OSHA Label Generator

http://michaellubert.com/blog/wp-content/uploads/2013/11/label.png

[OSHA Label Generator](http://michaellubert.com/projects/labeler “OSHA Label Generator”)
This is something I whipped up yesterday afternoon/this morning after an employee requested I help him create a template for OSHA labels, as apparently OSHA standards have changed or something. As he described what he wanted, I knew that it would be painful to create in Word, and it’d be awful to use and attempt to get everything in place, aligned, and to add the necessary icons. My way isn’t the simpler way, but it a better way.

Code Dump: channeldown.sh

Building on youtube.sh, this downloads an entire youtube channel. Usefull for marathon viewing sessions.

#!/bin/bash if [ "x$1" = "x" ] then echo channeldown "(username)" exit fi if [ ! "x$2" = "x" ] then MAX=$2 else MAX=100 fi USER=$1 i=1 while [ $i -lt "$MAX" ] do wget http://gdata.youtube.com/feeds/api/users/$USER/uploads\?start-index="$i"\&max-results=50 -O $USER.$i.raw let "i+=50" done #results=($(cat $USER*raw | sed 's/.*\(http:\/\/www.youtube.com\/watch?v=.\{11\}\).*/\1/g;/^http/!s/.*//g;/watch/!s/.*//g' | sort | uniq)) results=($(cat $USER*raw | sed 's/http/\nhttp/g' | grep 'api/videos' | sed 's/.*videos\///g;s/[<\/].*//g'|sort | uniq)) echo $results mkdir /downloads/watch/misc/$USER for X in ${results[@]} do X="http://youtube.com/watch?v=$X" echo $X >> $USER.log youtube-dl -o "/downloads/watch/misc/$USER/%(upload_date)s.%(stitle)s.%(ext)s" "$X" done rm $USER*raw

Code Dump: youtube.sh

Downloads youtube videos using youtube-dl. I built it to download multiple videos in a row. Put each url in a pair of single quotes.

“`bash
#!/bin/bash SETDIR=”/downloads/watch/misc” DIRFLAG=0 for ARG in $* do ARG=”$(echo “$ARG” | sed ‘s/feature=[a-z_+]*&//’)” # http://www.youtube.com/watch?feature=player_embedded&v=qeK0KmtYNaA # http://www.youtube.com/watch?v=kV832rfjcas&feature=related echo “$ARG” if [ x$ARG = x ] then exit elif [ x$ARG = “x-d” ] then DIRFLAG=1 elif [ $DIRFLAG = 1 ] then DIRFLAG=0 SETDIR=$ARG else echo “$SETDIR $ARG” youtube-dl -w -o “$SETDIR/%(title)s.%(ext)s” –max-quality=22 “$ARG” fi done
“`

Code Dump: Brighty

For some reason, on my Acer Aspire laptop, Ubuntu doesn’t seem to respond to the brightness settings, but this script works. It’s probably not terribly safe, but it add a good 20-30 minutes of battery life when I set it to the lowest setting I can see.

“`bash
#!/bin/bash function helpa { echo brighty [ 1 – 976 ] } if [ x$1 = x ] then helpa elif [ $1 -gt 976 ] then helpa else echo $1 | sudo tee /sys/class/backlight/intel_backlight/brightness fi
“`

Code Dump: rand.sh

Generates random strings. I got tired of having to go to [random.org](http://random.org “Random.org”), and this takes like 2 seconds.

VERSION=4
NUM=0
LEN=0
MODE=0
LN=0
ALLOW=""
for Y in $@
do
        if [ $Y = "-n" ]
        then
                MODE=1
                ALLOW=$ALLOW"0-9"
        elif [ $Y = "-s" ]
        then
                MODE=5
                ALLOW=$ALLOW'!@#$%^&*()-_=+'
        elif [ $Y = "-l" ]
        then
                MODE=2
                ALLOW=$ALLOW"a-z"
        elif [ $Y = "-u" ]
        then
                MODE=3
                ALLOW=$ALLOW"A-Z"
        elif [ $Y = "-c" ]
        then
                ALLOW="0-9A-F"
                LEN=6
        elif [ $Y = "-X" ]
        then
                ALLOW='0-9A-Fa-f!@#$%^&**()-_=+'
        elif [[ "$Y" =~ ^[0-9]+$ ]] && [[ LEN -eq 0 ]]
        then
                LEN=$Y
        elif [[ "$Y" =~ ^[0-9]+$ ]] && [[ LEN -gt 0 ]]
        then
                NUM=$Y
        elif [ $Y = "-b" ]
        then
                MODE=0
        elif [ $Y = "-N" ]
        then
                LN=1
  elif [ $Y = "-D" ]
  then
    echo $(curl -s "http://www.dinopass.com/password/simple")
    exit
        else
                echo "rand [arg] [length] [number]"
                echo "Arguements"
                echo -e "-b\tbasic\n-X\tcomplex\n-n\tnumber\n-l\tlowercase\n-u\tuppercase\n-s\tsymbols\n-c\tcolor\n-D\tdinopass"
                exit
        fi
done
if [ $LEN -eq 0 ]
then
        LEN=10
fi
if [ $NUM -eq 0 ]
then
        NUM=1
fi
if [ x$ALLOW = "x" ]
then
        ALLOW="A-Za-z0-9"
fi
X=0
while [ $X -lt $NUM ]
do
        if [ $LN -eq 1 ]
        then
                printf "%0${#NUM}g: " "$(($X+1))"
        fi
        </dev/urandom tr -dc $ALLOW | head -c$LEN;echo
        let "X++"
done

Code Dump: Core.sh and Startconky.sh

Used to randomly select from several wallpapers and apply a specific conky theme to it.

core.sh

“`bash
#!/bin/sh TOTAL=$(ls /home/michael/.conky/ | grep png | wc -l) if [ “x$1” != “x” ] then if [ $1 -gt -1 ] && [ $1 -lt $(ls /home/michael/.conky/| grep png | wc -l) ] then URAND=0 RANDER=$1 else echo INVALID NUMBER URAND=1 fi else URAND=1 fi if [ $URAND = 1 ] then RANDER=$(echo “$(/home/michael/apps/rand -n) % $TOTAL” | bc) fi echo $RANDER gsettings set org.gnome.desktop.background picture-uri file:///home/michael/.conky/core$RANDER.png cp /home/michael/.conkyrc$RANDER /home/michael/.conkyrc
“`

startconky.sh

“`bash
cat startconky #!/bin/bash while [ true ] do /home/michael/apps/core.sh sleep 30; conky & sleep 30m sudo killall conky done
“`

Grid Cypher

I was recently attempting to solve the cyphers presented by ToTheArk’s newest video ([Surveillance](https://www.youtube.com/watch?v=cFQKzg-yXgo)) when I came up with an idea (I wasn’t the only one).

“`
A,B,C,D,E,F,G,H,I
J,K,L,M,N,O,P,Q,R,
S,T,U,V,W,X,Y,Z,A,
B,C,D,E,F,G,H,I,J,
K,L,M,N,O,P,Q,R,S,
T,U,V,W,X,Y,Z,A,B,
C,D,E,F,G,H,I,J,K,
L,M,N,O,P,Q,R,S,T,
U,V,W,X,Y,Z,A,B,C
“`

That is the 9×9 cypher that formed the basis of my theory. At the time, the message contained only pairs of numbers [0-9]. I went to work brute forcing solutions. When that failed, I tried altering the starting letter of the grid. That failed too. Finally, I tried arbitrarily increasing the size of the grid, at one point getting to 100×100 (but still only using the upper-left most 9×9 as coordinates). These all failed. Ultimately, this didn’t even turn out to be the solution, but when I figured that out I had already written most of the script that I’ve posted below.

“`bash
#!/bin/bash
XM=$1
X=$2
Y=$3
F=$4
CO=$5
if [ “x$F” = x ]
then
F=65
elif [ “x$F” = “x!” ]
then
F=65
BRUTE=1
else
F=$(
echo “ibase=16;
$(echo $F | hexdump | tr [a-z] [A-Z] | awk ‘{print $2}’)” | bc
)
fi
function grid
{
A=0
B=0
GRID=””
Q=$1
while [ $A -lt $Y ]
do
ROW=””
D=$(echo $(($A))|sed ‘s/^\([0-9]\)$/0\1/’)
ROW=”$D”
Z=0
while [ $Z -lt $X ]
do
if [ $Q -gt 90 ]
then
Q=65
fi
ROW=$ROW”…”$(echo -e “\x$(echo “obase=16;ibase=10;$Q”|bc)”)
let “Z++”
let “Q++”
done
LROW=$(echo $ROW | sed ‘s/^..//;s/\.//g;s/\(.\)/\1,/g;s/,$//’)
GRID=”$GRID $LROW”
let “A++”
done
for Z in ${GRID[@]}
do
echo ${Z[@]}
done
}
function decode
{
GRID=($(grid $2))
if [ x$1 = xv ]
then
for ZZ in ${GRID[@]}
do
echo ${ZZ[@]}
done
fi
PHRASE1=””
PHRASE2=””
COORD=($CO)
echo ${#COORD[@]}
for XX in ${COORD[@]}
do
X1=$(($(echo $XX | sed ‘s/,.*//’) – 1))
Y1=$(($(echo $XX | sed ‘s/.*,//’) – 1))
X2=$(($(echo $XX | sed ‘s/,.*//’) – 1))
Y2=$(($(echo $XX | sed ‘s/.*,//’) – 1))
R1=($(echo ${GRID[$Y1]}|sed ‘s/,/ /g’))
R2=($(echo ${GRID[$X2]}|sed ‘s/,/ /g’))
PHRASE1=$PHRASE1″”${R1[$X1]}
PHRASE2=$PHRASE2″”${R2[$Y2]}
done
echo $PHRASE1
echo $PHRASE2
}
#
# Encode
#
function encode
{
GRID=($(grid $2))
if [ x$1 = xv ]
then
for ZZ in ${GRID[@]} do echo ${ZZ[@]} done fi COORD=($(echo $CO|tr [a-z] [A-Z]|tr -dc A-Z |sed ‘s/\(.\)/\1 /g’)) for XX in ${COORD[@]} do YP=$(($RANDOM%${#GRID[@]})) COUNT=$(echo ${GRID[$YP]} | grep $XX |wc -l) while [ $COUNT -lt 1 ] do YP=$(($RANDOM%${#GRID[@]})) COUNT=$(echo ${GRID[$YP]} | grep $XX |wc -l) done LINE=($(echo ${GRID[$YP]}|sed ‘s/,//g;s/\(.\)/\1 /g’)) XP=0 for YY in ${LINE[@]} do if [ $YY = $XX ] then echo -n “$(($XP+1)),$(($YP+1)) ” break else let “XP++” fi done done echo } # # Do Encode # function doencode { if [ “x$CO” != “x” ] then if [ x$BRUTE = x ] then encode v $F else while [ $F -lt 90 ] do encode a $F $3 let “F++” done fi else echo “tta e X Y BASE msg” fi } # # Do Decode # function dodecode { if [ “x$CO” != “x” ] then if [ x$BRUTE = x ] then decode v $F else while [ $F -lt 90 ] do decode a $F let “F++” done fi fi } # # Grid # function dogrid { GRID=($(grid $2)) if [ x$1 = xv ] then for ZZ in ${GRID[@]} do echo ${ZZ[@]} done fi } # # Help # function help { echo tta command x y root message } # # Command Menu Parse # if [ “x$XM” = xe ] then doencode elif [ “x$XM” = xd ] then dodecode elif [ “x$XM” = xg ] then dogrid v $F else help exit fi
“`