Code Dump: Icongen

Here’s a quick and dirty php script (using GD) that creates icons for my android phone. I got fed up at SimpleText, which no longer creates transparent images, and appears to have been abandoned by its developer. Images are created from the URL

icongen.php?name=ICON

into a folder called images.

<!--?php &lt;br ?--> $img_width=128;
$img_height=128;
$handle = ImageCreatetruecolor ($img_width,$img_height) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 0,0,0);
$black = ImageColorAllocate ($handle, 0,0,0);
$white = ImageColorAllocate ($handle, 255,255,255);
$red = ImageColorAllocate ($handle, 255,0,0);
$blue = ImageColorAllocate ($handle, 50,50,150);
$txt_color = $black;
imagecolortransparent($handle,$bg_color);
$font_size = 26;
$font_path='./OpenSans-Regular.ttf';
$txt_max_width = intval(0.8 * $img_width);
if($_GET['name']) { $text=$_GET['name'];
} else { $text='snap';
} #do { #$font_size++;
$p = imagettfbbox($font_size,0,$font_path,$text);
$txt_width=$p[2]-$p[0];
#} while ($txt_width &lt;= $txt_max_width); $y = $img_height * 0.57; // baseline of text at 90% of $img_height $x = ($img_width - $txt_width) / 2; imagettftext($handle, $font_size, 0,$x, $y, $white, $font_path, $text); ImagePng ($handle,'images/'.$text.'.png'); imagedestroy($handle); ?&gt;<img src="images/&lt;?php" />.png&gt;

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.

Identifying mysterious wireless issues.

“The first drop was at 11, when lunch began.”

In my current position, I have been struggling to identify a particular wireless issue that was sporadically taking our wireless network down. At the moment, we have put APs our throughout the building, but only three people in one office are using them. As such, it’s a very small sample size, but still peculiar when all three simultaneously drop.

These issues tend to be what I call quantum mechanic problems (as in car problems that exist until observed by a mechanic). Nobody who witnesses them is technical enough to give you adequate data to diagnose the problem (“The internet is down”). Watching for an issue that crops up once every two weeks is impossible, and automated reporting tools were not providing useful data.

Today, after having worked until 3 AM the previous night and existing on 3 hours of sleep, I revisited a previous notion that the microwave might be to blame. This was discounted in the past as during the one drop I was able to witness, I ran to the kitchen to find nobody using the microwave. Today, however, I recalled that on the shop floor, we have microwaves scattered everywhere for lunch. The nearest microwave in the shop was 30 feet from the AP, and delicious burrito testing revealed that the AP was completely drowned out by this crappy plastic $30 microwave.

Replacing one microwave may prove to be enough, but I am also delving into “other avenues” to solve this if it continues as we roll wireless devices out to the entire shop.

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"\&amp;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/[&lt;\/].*//g'|sort | uniq)) echo $results mkdir /downloads/watch/misc/$USER for X in ${results[@]} do X="http://youtube.com/watch?v=$X" echo $X &gt;&gt; $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
“`

Rsyslog – Log only to first match.

Giving the tilde (~) as an action causes that message to be discarded. There’s also the ampersand syntax – if a line starts with & it is considered an additional action for the previous line’s selector. So something like this:
> mail.* /var/log/mail.log
> & ~
>
> kern.* /var/log/kern.log
> & ~
>
> *.* /var/log/catchall

[via This Forum Post](http://kb.monitorware.com/logging-first-match-t8601.html )