See a new wallpaper after every suspend

My ubuntu 14.04 is getting crusty and I don’t think that Mate helped it out greatly, but I marginally like Mate better than XFCE. However, whenever my computer wakes from suspend, my wallpaper background image is all black and kinda messed up. So I read this example of making a suspend-resume hook. And here is my own:

jreynolds@cholla /etc/pm/sleep.d 
 > cat 20-desktop 
case "$1" in

   pgrep mate-session \
      && Esetroot $wallpaper &

And it seems to work pretty well.

Creating Stop Motion Video

For fun today, Jesse constructed a stop motion scene with legos and a hand-drawn backdrop. Meanwhile, I wrote an animation process. I wrote it as two scripts: one to resize input from my camera, the other to actually animate the pictures.

My ImageMagick resize script is reasonably simple, and if you search for other animation techniques, you will see many scripts like this. To use all four cores on my processor, I fire off 5 resize jobs and then do a job wait for them to complete so that I do not bog my system down.

set -x
set -e
# ----------------------------------------------------------------#
#  resize the input directory and put it in the output directory  #
#  and also re-names the files to simple numbered format          #
# ----------------------------------------------------------------#
find 0-input/ -type f -iname "*.jpg" -printf "%f\n" \
| sort \
| while read f ; do
   echo "convert 0-input/$f -geometry 728x480! -normalize $g "
   convert "0-input/$f" -geometry 728x480! -normalize "$g" &
   i=$[ $i + 1 ]
   j=$[ $j + 1 ]
   if [ $i -eq 4 ]; then
      # wait a bit
      for job in `jobs -p`; do
         echo -n "...$job"
         wait $job 
   echo "!"
echo "done"

My animation script is not all that different from other animation scripts you can search for on google, either. However, mine does not loop, does no fades, and plays very slowly. The first ‘-r’ switch specifies how long the input frames should last, so in this case, about 750ms (1.25 frames/sec). The output frame rate is the second ‘-r’ switch.

# -f : output format
# -r : frame rate
# -i : input file pattern
now=`date +%Y-%m-%d_%H%M`
ffmpeg  -r 1.25 -i "1-resized/r-1%03d.png" -r 24 "2-animated/animation-$"

I have a post of it on my G+.

Parenting and Teaching Programming

At what level of programming are we actually imparting the philosophy of human thought? Or, another way, a basic program that prints out a few numbers is truly trivially basic: it merely teaches some programming syntax. However, contrast your smartphone apps to your old DOS/Windows apps. A significan understanding of human haptics and intuition have been codified into the most basic of smart phone apps where your DOS applications might still be more closely related to punch-cards.

Episode 27 of Bad Voltage takes a fascinating turn in the middle of the episode where these parents stop discussing technology in terms of quantifiable capacities and start talking about the philisophical benefits to young programmers. Jono Bacon quotes a collegue:

Programming is smulating how we thing. Teaching programming is teaching a meta-level of how we [make decisions].

And then Bryan Lunduke chimes in with Scratch, a simple programming environment suitable for younger children.

Please teach your kids, especially your girls, how to code. I firmly believe that this is not just a job skill, but an introduction to logic and analysis that is more tangible than any calculus tought, ever. And don’t brag to me about how you used an interval to compute the average runoff from a forested watershed, you’re showing off. You thouch your phone 120 times a day and you’re entirely dependent on it. If you can boil water and put peanut butter on bread, you can program, so stop raising your hands about how difficult it is. Our children will lead lives where software will decide their salaries, their health insurance, their academic opportunities and how they are promoted and ultimately how they promote themselves through life.

Please listen to that episode and tell me why you are not introducing your kids to computer programming.

Crazy Perl Day

I’m surprised that this is the first time in Perl that I’ve bothered to use the posix character class [:alnum:]. Check this nuttiness out:

($::port_name, $::first_port, $::last_port) = 
  $::port_range =~ 

Yeah…it’s better with coffee.

CSS pulldown menus, the trick

The real trick to css pulldown menus is the :hover pseudo selector. You knew that. However, the insight comes in learning that the :hover pseudo can be used anywhere in the middle of your CSS selector. This allows you to build up the a selector representing a mouse action that selects a child element of what the mouse it on.

Here is some html:

(span id="menu")
(h3)a category(/h3)
  (li)item 1(/li)

Now here is how you hover over the over H3 to get the sub menu to raise:

#menu {
   width: 2in;
   height: 2em;
   position: relative;
#menu ul {
   display: none;
   position: absolute;
#menu h3:hover ul {
   display: block;
#menu ul:hover {
   display: block;

That h3:hover ul trick is gold!

Keep that Laptop from Racing thru Battery

Linux and Laptops: a long, old story. However, one that with a bit homework, helps get the most out of your battery. Using powertop, you can see your energy usage profile and your device power settings. The downside to powertop is that you cannot "export as shell script." (Seriously, y u no export?) To get these power savings on boot, I wrote my own script.

  1 #!/bin/bash
  2 /usr/sbin/rfkill block 0 #bt
  3 /usr/sbin/rfkill block 1 #wifi
  4 /usr/sbin/rfkill block 2 #bt
  5 for i in /sys/class/scsi_host/host*/link_power_management_policy
  6 do
  7     echo "min_power" > $i
  8 done
  9 echo 0 > /proc/sys/kernel/nmi_watchdog
 10 echo 1 > /sys/module/snd_hda_intel/parameters/power_save
 11 echo 60000 > /proc/sys/vm/dirty_writeback_centisecs
 13 find /sys/devices/ \
 14 | grep 'power/control' \
 15 | while read i
 16 do
 17     echo -n "$i@"
 18     cat $i 2>/dev/nulll
 19 done \
 20 | grep -v auto \
 21 | awk -F@ '{print $1}' > /tmp/sleepy.tmp
 23 for i in `cat /tmp/sleepy.tmp`
 24 do
 25     echo "auto" > $i
 26 done
 28 for i in `find /sys -name autosuspend -exec echo {} \;`
 29 do
 30     echo "1" > $i
 31 done
 33 find /sys/devices/pci0000:00 -type f -iname autosuspend_delay_ms \
 34    -exec echo "1000" > {} \;
 36 for i in /sys/bus/usb/devices/usb*/power/autosuspend_delay_ms
 37 do
 38     echo "1000" > $i
 39 done
 41 for i in /sys/bus/usb/devices/usb*/power/autosuspend
 42 do
 43     echo "1" > $i
 44 done
 46 for i in /sys/bus/usb/devices/*/power/autosuspend
 47 do
 48     echo "1" > $i
 49 done
 51 webcamDev=$( lsusb | grep -i webcam | awk '{print $2 "-" $4 }' | tr -d ':0' )
 52 if [ ! -z "$webcamDev" ]
 53 then
 54     echo 1 > /sys/bus/usb/devices/$webcamDev/power/autosuspend
 55     echo auto > /sys/bus/usb/devices/$webcamDev/power/level
 56     echo 1000 > /sys/bus/usb/devices/$webcamDev/power/autosuspend_delay_ms
 57 fi
 59 # eof

The best way to run this script is to open two windows, one running powertop, the other for this script. After adjusting this script, type r in the powertop window to refresh the device stats. I was able to take my T60 from 30.1W down to somewhere between 19.8 – 16.1W. Unfortunately, I haven’t seen that 16.1W reading since.

I hope this serves as a good starting point for your own laptop power savings! And not just laptops, but this script can also be used for home NAS or media center or other small servers where you need thermal management, too.

This is not the nastiest perl I’ve ever done…but dang.

This is a stanza where, given a comma separated list of keywords to match on, find the values after the colon. The values could be empty and at the end of a line. I would be delighted to find an even simpler way to do this.

   my $matcher       = " (".join('|', keys %option_map)."):";
   my @matches       = grep( /$matcher/, @lines);
   for my $match (@matches) {
      my @parts      = ($match =~ m/( *[^ ]+):( \S+ [^ #]*)(?! #|\S+:)/g);
      for (my $i=0; $i < @parts; $i+=2) {
         $option     = $parts[$i];
         $option     =~ s/^\s*(.*)\s*$/$1/;
         if ( defined $option_map{ $option } ) {
            my $value = $parts[ $i + 1 ];
            $value   =~ s/^\s*(.*)\s*$/$1/;
            $option_map{ $option } = $value;

And that’s pretty darned terse for that solution.

uh…remind me how to begin a perl script?

Don’t let me forget to do this at the start of my perl scripts at work:

package main;
use strict;
use warnings;
use Carp;
$SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
use Scalar::Util; #::looks_like_number;
# Un-buffer output
$| = 1;
# this is pedantic necessity for the following use statements
use lib '/home/lanforge/scripts';
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;
use Net::Telnet ();
use Getopt::Long;
use Socket;
use POSIX;

PH7 Engine – is it really the fix?

This sounds very useful, especially if you consider that PHP is used in embedded environments like MonoWall and pfSense.

My big question for larger installation is this: xcache already does a great job at bytecode caching. The largest slowdown in the majority of PHP applications is the relational engine sitting underneath it. After much profiling of previous applications, I have always found the biggest benefits to application performance in taking a casual schema to a rigorous level. And if that is not fast enough, then you throw in some memcached to the mix.

PH7 Engine.