Sunday, November 29, 2015

Bash animations

Animations in various languages.


1. The donut.


$ gcc -lm donut.c -o donut


[code]
           k;double sin()
         ,cos();main(){float A=
       0,B=0,i,j,z[1760];char b[
     1760];printf("\x1b[2J");for(;;
  ){memset(b,32,1760);memset(z,0,7040)
  ;for(j=0;6.28>j;j+=0.07)for(i=0;6.28
 >i;i+=0.02){float c=sin(i),d=cos(j),e=
 sin(A),f=sin(j),g=cos(A),h=d+2,D=1/(c*
 h*e+f*g+5),l=cos      (i),m=cos(B),n=s\
in(B),t=c*h*g-f*        e;int x=40+30*D*
(l*h*m-t*n),y=            12+15*D*(l*h*n
+t*m),o=x+80*y,          N=8*((f*e-c*d*g
 )*m-c*d*e-f*g-l        *d*n);if(22>y&&
 y>0&&x>0&&80>x&&D>z[o]){z[o]=D;;;b[o]=
 ".,-~:;=!*#$@"[N>0?N:0];}}/*#****!!-*/
  printf("\x1b[H");for(k=0;1761>k;k++)
   putchar(k%80?b[k]:10);A+=0.04;B+=
     0.02;}}/*****####*******!!=;:~
       ~::==!!!**********!!!==::-
         .,~~;;;========;;;:~-.
             ..,--------,*/

[/code]

Other interesting things:
https://github.com/szantaii/bash-weather
http://www.a1k0n.net/2006/09/15/obfuscated-c-donut.html
http://soomka.com/
https://github.com/radare/tiv
https://github.com/thewtex/tmux-mem-cpu-load
https://github.com/gryftir/tmux-networkspeed

2. Yahoo

$ gcc -lm yahoo.c -o yahoo

[code]

c,p,i,j,n,F=40,k,m;float a,x,y,S=0,V=0;main(){for(;F--;usleep(50000),F?puts(
"\x1b[25A"):0)for(S+=V+=(1-S)/10-V/4,j=0;j<72;j+=3,putchar(10))for(i=0;x=S*(
i-27),i++<73;putchar(c[" ''\".$u$"]))for(c=0,n=3;n--;)for(y=S*(j+n-36),k=0,c
^=(136*x*x+84*y*y<92033)<<n,p=6,m=0;m<8;k++["<[\\]O=IKNAL;KNRbF8EbGEROQ@BSX"
"XtG!#t3!^"]/1.16-68>x*cos(a)+y*sin(a)?k=p,p="<AFJPTX"[m++]-50:k==p?c^=1<<n,
m=8:0)a=(k["O:85!fI,wfO8!yZfO8!f*hXK3&fO;:O;#hP;\"i[by asloane"]-79)/14.64;}
[/code]

3. Explode



$ python explode.py

[code]

!/usr/bin/python

import sys, math, time, random

def distance(x, y):
    # ((y - y_center) * 2) -> correct ratio for a true circle
    return math.ceil(math.sqrt(((x - 40) ** 2) + (((y - 12) * 2) ** 2)))

def star(radiuses):
    for r in radiuses:
        #~ clear screen: http://stackoverflow.com/a/2084521/2257664
        print chr(27) + "[2J"

        # width
        for y in range(24):
            # height
            for x in range(80):
                d = distance(x, y)

                #~ border
                if (d == r):
                    sys.stdout.write('*')
                #~ inside the star
                elif (d < r):
                    if (r > 35):
                        sys.stdout.write(' ')
                    elif (r > 25) and ((d % 2) != 0):
                        sys.stdout.write('-')
                    elif (r > 15) and ((d % 2) == 0):
                        sys.stdout.write(' ')
                    else :
                        sys.stdout.write(random.choice('****#@'))
                #~ space outside the star
                else:
                    sys.stdout.write(' ')
            print
        time.sleep(0.1)

star(range(0, 12) + range(10, 0, -1) + range(0, 50))

[/code]

3. car

$ gcc car.c -std=c99  -o car

[code]
 #include<stdio.h>
#include<stdlib.h>

#ifdef _WIN32
#define CLEAR "cls"
#define SLEEP "ping -n 1 localhost > nul"
#else //In any other OS
#define CLEAR "clear"
#define SLEEP "ping -c 1 localhost > nul"
#endif

void printline(char *, int);
void drawcar(int);

void printline(char *line, int no)
{
int i;
for( i = 0; i < no; i++)
  printf(" ");
printf("%s\n", line);
}

void drawcar(int no_of_spaces)
 {
 char *line1 = "       .--------.";
 char *line2 = " ____/_____|___ \\___";
 char *line3 = " O    _   - |   _   ,*";
 char *line4 = " '--(_)-------(_)--'";
 printline(line1, no_of_spaces);
 printline(line2, no_of_spaces);
 printline(line3, no_of_spaces);
 printline(line4, no_of_spaces);
}
int main()
  {
  int i;
  for (int i = 0; i < 50; i++)
    {
       system(SLEEP);
       system(CLEAR);
       drawcar(i);
    }
  }

[/code]

4. The cat.



$ chmod +x cat
$ ./cat

[code]

#!/bin/bash
#  --------------------------------------------------------------------------
#  (c) 2012 BruXy            Version: 1.0             http://bruxy.regnet.cz/
# downloaded with permission 
#  --------------------------------------------------------------------------
# switch off cursor, set blue background, clear screen
echo -e "\E[?25l\E[44m\E[2J"

# Play music
M=/tmp/cat_orig.mp3
[ ! -f $M ] && wget http://nyan.cat/music/original.mp3 -O $M >/dev/null 2>&1
while true; do mplayer $M > /dev/null 2>&1; done &

# easy way to reset terminal and exit subprocesses
trap "reset;killall nyan_cat.sh" 2

## Nyan cat ANSI picture data, my own creation :P, size 38 x 11
# Compressed version of picture
D="H4sIAHUNPlAAA22Q2w7CIAyG730rC1IGEs3itoS7cYlLvFGf37YcPMQvo5DxpT+pMYLb/8OVSxNv
Aiq1Db9sSmG1TgKqdhXqktKtsyBW6F08gB/EcgAUG2eAeRxbryqi1hq89yvQgfrFZ6If8E7sVoet
aVqWlNjqgYGlA5ckG5r4EGqvHmgtGeWzlqwLc6dJHD8Sr/IMQadMiTxR0IDrN/RUUjDnLJOghYn9
UgtyzvTcNvvdCw/8WhWjAQAA"

# decompress it to $C
C=`echo "$D" | base64 -d | zcat`

# hash field with 'pixel' atributes
declare -A B

B=([A]=43\;30m▀ [a]=43\;30m▄ [B]=47\;30m▀ [b]=47\;30m▄ [C]=43m\  [D]='47m '
[E]=1\;40\;37m▀\\E[0m [F]=44m\  [G]=40m\  [H]=1\;31m█\\E[0m [I]=0\;35m█
[J]=44\;30m▄ [j]=44\;30m▀ [K]=45\;30m▄ [k]=45\;30m▀ [L]=43\;35m▀
[l]=43\;35m▄ [M]=45\;31m▄ [O]=31m█ [o]=44\;31m▄ [P]=33m█ 
[R]=42\;33m▀ [S]=42\;32m█ [s]=46\;32m▀ [T]=46\;36m█ [t]=46\;30m▄
[U]=45\;35m█ [u]=46\;35m▀ [V]=43\;30m▄ [v]=42\;30m▀ [W]=45\;30m▀
[X]=43\;32m▄ [x]=32m█ [c]=44\;36m▀ [d]=42\;35m▄ [e]=41\;33m▄ [Z]=44m\\n)

# get size of terminal window
read X Y <<< `tput cols; tput lines`

# some terminals have problem with background color change
# this fills screen with spaces and fill my signature to bottom left
printf "%*s" $[X*Y] BruXy

##################
### Draw Nyan Cat
##################

# set position to the center
xp=$[(X-37)/2]
yp=$[(Y-11)/2]

# go through image data and draw them to specified position

j=1 #row    ... y
k=1 #column ... x
for i in {0..417} #38*11-1 image size
do
    p=${C:$i:1} # get pixel
    # put pixel to given position \E[y;xH
    echo -en "\E[$[j+yp];$[k+xp]H\E[${B[$p]}"
    # if pixel Z is found go to next row (pixel count worked strange)
    k=$[k++,k%38]; [ $p = 'Z' ] && : $[j++]
done

###################
### Star animation
###################

# Field with stars animation
S=("       " "      " "       " "       "
"       " "  ▄▀▄  " "      " "       "
"      " "      " "▀▀  ▀▀" "      "
"      " "     " "     " "    "
"      " "       " "     " "      ")

# function for star drawing
# $1 .. column, $2 .. row position
s () {
    echo -en "\E[1;37m" # set bright white
    for j in {0..4} # for each line
    do
        # draw one star frame of animation
        for i in {0..3}
        do
            echo -en "\E[$[i+$1];$[$2+m]H\E[1;37m${S[$[i+4*j]]}\E[0;44m"
        done

        sleep 0.2

        # erase star
        for i in {0..3}
        do
            echo -en "\E[$[i+$1];$[$2+m]H\E[44m${S[0]}"
        done
        : $[m-=5] # move the next frame 5 columns to the left
    done
}

# count star positions according to nyan cat position 
# -3,+3 best constant, I've played with those numbers
# to get best position of stars and do not destroy the cat :)
my=$[(Y-11)/2 - 3]
My=$[my+11 + 3]

while true
do
    for i in $(eval echo {1..$my..4}) # each position 4 rows difference
    do
        # draw top star, animation has 20 columns length, so generated
        # for lowest start position columns is 0+20
        (s $i $[20 + $RANDOM % (X - 20)]) &
        # draw bottom star 
        (s $[i+My] $[20 + $RANDOM % (X - 20)]) &
    done
    sleep 0.5
done &

######################
### Draw rainbow flag
######################

# oOPXxUuT .. top wave, OePxdUTc bottom wave
A="oOPXxUuTOePxdUTc";

# Flag waving:
# $c .. flip flop when counter $i modulo 5 is zero,
#       then it adress top or bottom wave
while true
do
    : $[c^=1]
    for x in `eval echo {1..$[xp]}`
    do
        if [ $[i++ % 5] -eq 4 ]; then : $[c^=1]; fi;
        for y in {0..7}
        do
            echo -en "\E["$[yp+y+2]";${x}H\E[${B[${A:$[y+(c*8)]:1}]}\E[0m"
        done
    done
    sleep 0.5
done
[/code]

5. Matrix



$ chmod +x matrix
$ ./matrix

[code]
 #!/bin/bash
echo -e "\033[2J\033[?25l"R=`tput lines` C=`tput cols`;: $[R--] ; while true 
do ( e=echo\ -e s=sleep j=$[RANDOM%C] d=$[RANDOM%R];for in `eval $e {1..$R}`;
do c=`printf '\\\\0%o' $[RANDOM%57+33]` ### http://bruxy.regnet.cz/web/linux ###
$e "\033[$[i-1];${j}H\033[32m$c\033[$i;${j}H\033[37m"$c; $s 0.1;if [ $i -ge $d ]
then $e "\033[$[i-d];${j}";fi;done;for in `eval $e {$[i-d]..$R}`; #[mat!rix]
do echo -e "\033[$i;${j}";$s 0.1;done)& sleep 0.05;done #(c) 2011 -- [ BruXy ]
[/code]

Slide rule




You can make your own temporary slide rule that should somewhat accurate using very simple parts. (not drawn to scale).

Styrofoam board.
Glue.
Clear plastic.
Tape.


To get some templates:

$ wget http://sliderulemuseum.com/REF/scales/SR_scales.zip

That need to be cut apart for the sections.

 The bottom section is for the backside of the center section,

Add labels.




Or to put it together.

Slider.



 Slide rule tutorial: http://sliderulemuseum.com/SR_Course.htm

Tuesday, November 24, 2015

Clear tv?



Noticed the Cleartv has changed antennas. The original antenna was not received very well and had some scathing reviews. Plus the specifications were easily attainable.   We made our our own version.  http://www.instructables.com/id/ClearTV-antenna-lookalike/


Now I have noticed they have come up wigh a new antenna and the pictures are blurred with no specific technical details in the advertisements. Wondering why that is?




If I get a chance to duplicate it I will let you know.


Could it be?


Saturday, November 21, 2015

Dumb terminal to thin client.

Years ago there real was not a terminal that you could cozy up to to do your computing. In the beginning  there was a punch card machine. You would type in your data, your program in to 80 column punch cards. On this cards you would also have to number them. If the cards went into a pile, there would be an unpleasant experience reorganizing them. Used one of these for writing programs in Fortran.


Eventually systems came with enough storage, that you did not need to carry the punch cards and you could print out what you keyed in and the results of what you were working on with the printing terminal. Finance company I worked for had one of thes that connected to an acoustical modem contract the credit bureau..


The finally we get a crt soft of like a tv with a keyboard.  Worked much like the printing terminal. You could even edit what you were working on in real time. Saved a lot of paper. You can not see it very well but the text was in green. Used one of these at a real outlet for sending email and doing various reports. These were still used less than 20 years ago.


Eventually the terminals also know as thin clients became more portable and you could use standard monitors with them. Thin clients came two way, they either had an embedded minimal operating system, remote desktop client, or  a minimal operating system was installed from the network onto the systems. They basically connect to a server that does all the heavy lifting. The unit had no drives or off-line storage. This terminal is working with an Linux terminal server.


And now the ultimate in thin clients with the touchpads that are generally driven by web servers.


A fractured fairy tale history.

Ordering from the menu.

Web pages with menus are sure easy to navigate. In fact, I like all the base menus in one place so that you do not have to go though a maze to get what you want.


The menus are just one part of the page, so let's zoom in and see that we are looking at. The menu takes up minimal space, but expanding a pull-downs make it easy to manage.


Wrote this years ago so I am sure there are much better ways to do it now, but it still works for me on a private server. The menu is pretty much a large table comprised of sections having each option menu.

[code]


<td>
<form name="jump1">
<select name="menu1" onchange="top.location=document.jump1.menu1.options[document.jump1.menu1 ...
<!-- option value="../flatpress">Flatpress</option>
<option value="../wiki">Mediawiki</option> -->
<option value="../wordpress">Wordpress</option>
<option value="../vh/www.ohmygalleries.com/html">Scrapbook</option>
<!-- <option value="../habari">Habari</option> -->
</select>
</form>
</td>
[/code]

Notice there are some lines commented out of former options that were a part of the menu. But that is ok because they will not be shown. So what does the total page look like?


Notice that each section is named separately.  So here you go a quick and dirty menu section.

Note: in the main menu I nave set up a reference to make links easier.

[code]

<head>
<title> Offshore Educators (Main Page) 1 </title>
<base href="http://oeorgan1/oe/">
</head>
[/code]

Have fun.

Friday, November 13, 2015

It's web time.


Ever wonder what would be like to have a local web app for the time without having to connect to some far off unknown place with who knows what hidden features.



Now you can have local clock time on your server

 
<code> 
<table border=2>
<tr>
<td>
<script>
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write("<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"</b></font></small>")
</script>
</td>
</tr>
<tr>
<td>
<span id=tick2>
</span>

<script>
<!--
function show2(){
if (!document.all&&!document.getElementById)
return
thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn="PM"
if (hours<12)
dn="AM"
if (hours>12)
hours=hours-12
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
var ctime=hours+":"+minutes+":"+seconds+" "+dn
thelement.innerHTML="<b style='font-size:14;color:blue;'>"+ctime+"</b>"
setTimeout("show2()",1000)
}
window.onload=show2
//-->
</script>
</td>
</tr>
</table>
[/code]

Open for business?




This is two scripts one to find and record machines on the system at the time and the second script is to find open ports on those systems below 1024.

alive.sh
[code]
#!/bin/bash
rm /tmp/goodips
is_alive_ping()
{
  ping -c 1 $1 > /dev/null
  [ $? -eq 0 ] && echo $i >> /tmp/goodips
}

for i in 192.168.1.{1..255}
do
is_alive_ping $i & disown
done
[/code]

/tmp/goodips

192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4

Now the second script.

scannet.sh
[code]
datafile="/tmp/goodips"
a=1
m="not done"
while read line
do fdata[$a]=$line
echo
echo $line
       let a=a+1
       for p in {1..1023};
       do
       (echo >/dev/tcp/$line/$p) >/dev/null 2>&1 && echo "$p open"
       done
done < $datafile
[/code]

results:
192.168.1.1
23 open
53 open
80 open

192.168.1.2
22 open
23 open
25 open
80 open
111 open
443 open
465 open
587 open

192.168.1.3
21 open
80 open
139 open
515 open

192.168.1.4
22 open
111 open

Vulnerabilities abound. Now would be a good time to install and run both chkrootkit and or rkhunter.

$ sudo apt-get install rkhunter chkrootkit

$ sudo  rkhunter --update
$ sudo  rkhunter -c

$ sudo chkrootkit

Tuesday, November 10, 2015

Another Tuxpaint hint.

Using two or more programs together can make a system more powerful. In this case we want to use Tuxpaint and the Gimp.  We will start off using Tuxpaint to make a picture and then take a screen shot just of the drawing.



The let's import a picture we have downloaded and use Tuxpaint to edit it and then of course to take a screen shot of that.


Then we need a screen shot that was made a while back.


The we need to open up the Gimp and set up a new page several times larger than the pictures and then import the three pictures.



Then you can export that picture and import it into tuxpaint for final editing.


So then you can use it in a web page like you blog or where ever


Saturday, November 7, 2015

Secure yourself.



Linux commandment: Thall shall not login remotely as root.

If your a good linux admin, you did this when you first set up the machine.

$ cd /etc/ssh
$ sudo vim sshd_config

Change the line that says permit Root login to no
/Roo
in vim should find the line quickly

# Authentication:
LoginGraceTime 120
# PermitRootLogin yes
PermitRootLogin no
StrictModes yes

Save and exit the file.

Restart the service:

$ sudo service ssh restart

Friday, November 6, 2015

The PCinoPi

The PCinoPi available from many junk closets is not faster than a speeding bullet and  not faster than a speeding train but it can easily introduce you to computers and electronics. Will run Pitus Linux, Atomic Linux, Freedos (with Qbasic), among other operating systems right from the floppy drive. (Pictured is an i486 laptop)


You can easily do digital control with it's legacy parallel port. Lighting led's is a cinch. Controlling  rocket launchers is another benefit.  Need to do analog input? With a few discrete parts you can even get analog values too. Say grabbing the temperature. If the vga port is new enough, you can even use I2C

Picture of i2c interface. 

Extra cable and interfacing not included but can be built with off the shelf parts.



Picture of Vga breakout cable. 



Picture of DB9 serial break out cable.

Parallel (http://www.instructables.com/id/No-solder-parallel-port-break-out/)

Picture of Ready to use.


also see (http://www.instructables.com/id/Mini-parallel-port-break-out-cable/)

Thursday, November 5, 2015

Tuxpaint cad?

Tuxpaint can be good for drawing pictures, cartoons, and the like, but if we let it stretch it's muscles there is more that can be done. Maybe use it as a sort of drafting program. A drawing usually has at least four views. They are the front, side, top, and isometric (roughly translated at an angle).  If you needed a simple step stool, you certainly can make a drawing to reflect that. In this case you only have a partial isometric, but the point gets across.


https://computothought.files.wordpress.com/2014/09/56985-stairs.png



Maybe you could do a floor plan:


A 3d object in 2d.



Then all the rest....




Circuit design.




Have fun.