Do You Work With Me?


If you work with me currently please email me from a corporate email address for a password to the company-related (private) posts.

selective base64 decode


The MTA expects text, Windows system accounts are sending base64 encoded email. Lets get the text back to text for parsing

perl -MMIME::Base64 -e ‘$deco = 0; $/ = “\n\n”; while (<>) { $deco–; if (/Content-Type:/){ $deco = 2 if (/text/);
$deco = 0 unless(/text/); } print decode_base64($_) if ($deco == 1); print unless ($deco == 1); }’

Prettier Calendar Invites




if [[ $# != 4 ]]


(echo Address Subject Date Time)

exit 2












##To: $WHO


##Subject: $SUB

##Mime-Version: 1.0

##Content-Type: multipart/mixed; boundary=”$DIV”



##Content-Type: text/calendar



























#@Content-Type: application/octet-stream; name=”invite.ics”

#@Content-Transfer-Encoding: Base64;

#@Content-Disposition: attachment; filename=”invite.ics”


# cram invite into ICS file


grep “^##” $0 | sed -e ‘s/^##//g’ | \

sed -e ‘s/$DATE/'”$DATE”‘/g’ | \

sed -e ‘s/$TIME/'”$TIME”‘/g’ | \

sed -e ‘s/$SUB/'”$SUB”‘/g’ | \

sed -e ‘s/$WHO/'”$WHO”‘/g’ | \

sed -e ‘s/$DIV/'”$DIV”‘/g’ | \

sed -e ‘s/$RAND/'”$RAND”‘/g’ | tee – | grep -v “^#” | perl -MMIME::Base64 -0777 -ne ‘print encode_base64($_)’ > $ICS


# Get basic invitation


(grep “^##” $0 | sed -e ‘s/^##//g’ | \

sed -e ‘s/$DATE/'”$DATE”‘/g’ | \

sed -e ‘s/$TIME/'”$TIME”‘/g’ | \

sed -e ‘s/$SUB/'”$SUB”‘/g’ | \

sed -e ‘s/$WHO/'”$WHO”‘/g’ | \

sed -e ‘s/$DIV/'”$DIV”‘/g’ | \

sed -e ‘s/$RAND/'”$RAND”‘/g’ | grep -v “^#”;


grep “^#@” $0 | sed -e ‘s/^#@//g’ | \

sed -e ‘s/$DATE/'”$DATE”‘/g’ | \

sed -e ‘s/$TIME/'”$TIME”‘/g’ | \

sed -e ‘s/$SUB/'”$SUB”‘/g’  | \

sed -e ‘s/$WHO/'”$WHO”‘/g’  | \

sed -e ‘s/$DIV/'”$DIV”‘/g’ | \

sed -e ‘s/$RAND/'”$RAND”‘/g’ | grep -v “^#”


cat $ICS) | /usr/sbin/sendmail $WHO


rm $ICS;

Range of Time Log Slices

# cat $LOG | THIS_SCRIPT Nov 7 15:06:21 , Nov 7 15:23:00 set timeA [split $argv "," ];set start [ clock scan [lindex $timeA 0]]; set stop [clock scan [lindex $timeA 1]]; while { [gets stdin data] >= 0 } { set dateA [lrange [split $data {}] 0 14]; set eSec [clock scan [join $dateA ""]]; if { $eSec > $start && $eSec < $stop } { puts "$data" } }

Point-In-Time Log Slices


What happened in a text stream (cat $LOG) from two minutes before to two minutes after a specified time.

set start [clock scan $argv]; set start [expr $start - 120]; set stop [expr $start + 240];
while { [gets stdin data] >= 0 } {
        set dateA ''; set eSec '';

        if {[regexp {(^[A-Z][a-z][a-z]\s+[0-9]*\s?[0-9][0-9][0-9][0-9])} $data]} 
                { set dateA [lrange [split $data {}] 0 14]; }
        if {[regexp {(^[A-Z][a-z][a-z]\s+[0-9]*\s?[0-9][0-9]:[0-9][0-9]:[0-9][0-9])} $data]} 
                { set dateA [lrange [split $data {}] 0 14]; }
        if {[regexp {(^[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9])} $data]} 
                { set dateA [lrange [split $data {}] 0 19]; }

        if {[regexp {([0-9])} $dateA]} 
                { set eSec  [clock scan [join $dateA ""]] } else { puts $data; }
        if {[regexp {([0-9])} $eSec]} 
                { if { $eSec > $start && $eSec < $stop } { puts $data } }

Userland CPU Throttling for Android


I’m sure that this is common knowledge but I tripped over this all by myself, so here comes a post.

My Galaxy SII has a directory called /sys/power with what look like explicit controls for the CPU throttle.

Minimum CPU speed is set by the contents of /sys/power/cpufreq_min_limit.
Maximum CPU speed is set by the contents of /sys/power/cpufreq_max_limit.

A table of legal values for the minimums and maximums lives in /sys/power/cpufreq_table.

This is nowhere as fine-grained or powerful as a hacked kernel scheduler, but I’m having good results so far. A quick python script allows me to idle with the screen off at 200 MHz, with the CPU ramping up to 500 MHz when a poll shows the screen on. CPU is ramped-up to 1000 MHz once an hour during a forced mail check and RSS scrape.

I combined the above with airplane mode off/on scheduled as an hourly cycle while out camping last week in Western Pennsylvania. I was able to last 4 days without a charge (radio-off and CPU running full tilt usually runs my battery down in 10 – 12 hours).

Edit: borrowed a friend’s Droid Razr, it appears that settings are different per manufacturer (of course…). Try /sys/devices/system/cpu/cpu[0|1]/cpufreq/cpuinfo_max_freq

Forcing Android to Check For New Email


For the sake of maintaining power I’ve fallen into the habit of putting whatever handset I’m carrying at the moment into Airplane mode and activating the radio for a few minutes every so often. Now that I finally own an Android handset, I can schedule a job to do this for me with TaskBombS4LA and a little bit of python. A job runs once an hour to enable 3G services and open my email client for two minutes receiving if there’s enough juice.

The biggest problem I found was getting the stock email client to poll for new email on demand instead of by timer (why bother with this power toggle if I need to run for 15 minutes every hour just to get email?). After a bit of poking around, I discovered that the stock email client ( automatically checks for new mail at application startup! Sticking a call to run pkill -9 -f, waiting two seconds and then forcing the email client to return to a conversation view (am start forces a new mail check nicely.

tl;dr: You can force the default android email client to check for new email by forcing the application to restart with ‘pkill -9’ and ‘am start’.

Your Schedule Just Exploded


You have autosys jobs scheduled in a Solaris in a variety of European timezones. Today they went off at the wrong times. Happy European DST. Check your Solaris patches.

Hunting Down Cross-Authorizing SSH Keys


Its well-known that some users insert their public keys into another user’s authorized_keys file to escalate their privileges. Let’s find out who’s playing silly games.


for id in `/usr/bin/ypcat passwd.byname | awk ‘!/'”$USER”‘/ {FS=”:”} { print $1 }’`
(ssh -qTn $id@$HOSTNAME id | grep $id >/dev/null) && \
echo “$USER cross-authorizes as $id on $HOSTNAME”

Automatically Restart Your Python SimpleHTTPServer


Command Line Fu turned me on to python’s built-in servers a while ago, unfortunately, root tends to kill my long-running processes. Schedule the below in cron to tickle the default python webserver port and start a new instance of the python webserver in the specified <ROOT_DIR> if no response.

(echo '' > /dev/tcp/localhost/8000) 2>/dev/null || (cd /<ROOT_DIR> && /bin/python -m SimpleHTTPServer &)

If this doesn’t work, your BASH was compiled without network support. wget should be able to help you.

Autosys man pages


Because I could never find these myself: