Blog posts tagged "shell"

bceval: arbitrary precision math for PHP without extensions

March 25th, 2008

I needed arbitrary precision math in PHP, and wasn’t willing to rebuild PHP to add the bcmath extensions. All hail backticks.

function bceval($expr) {
  return trim(`echo "$expr" | bc`);
}

Used like so

$end = bceval("$start + $batchsize - 1");

Wet cat territory.

Shell Scripting and Agg Stats

September 21st, 2005

Been a while since I dug into my aggregator stats (intrigued by FeedBurner mentioning their tracking 2000 aggregators), and while I’ve got my Perl script, but I was alarmed to realize that I had forgotten the shell for doing the equivalent.

So killing time waiting for J I re-created it. Assumes you’re using Apache’s “full” log format (and that your feed is “index.rdf”)

sudo grep '/index.rdf' access.log | cut --delimiter=\" -f6,1 --output-delimiter="=" | 
sed 's/ - - \[[^=]*//' | sort | uniq | cut --delimiter="=" -f2 | sort | uniq -c | sort -n

Returns a count of unique IPs per User-Agent. Tack on a little awk to get aggregate counts.

| awk '{sum += $1; print sum}'

Of course folks like Bloglines, Rojo, Yahoo FeedSeeker, Feedster, and FeedLounge (among others I’m sure) are rolling up the user counts. Of course FeedLounge and FeedSeeker are counted multiple times as they add time sensitive info to their User-Agent (that has got to be against some best practices!), and Bloglines comes from a couple of different IPs.

Interestingly, Google Desktop is showing up as generating not only the highest number of hits, but the highest number of 200s.

Tagged: Uncategorized , , , , ,

The Kettle Dilemma and Growl

December 4th, 2004

I can be a little distracted at times, but the sight of a heavy, solid black kettle glowing an eery incandescent orange tends to rivet my attention.

I don’t know about you but I have a habit on these cold wet nights to put a kettle on, and then start a project while waiting for the water to boil. And I get distracted, and come back a view hours later. So inspired by a comment on Remind as command-line iCal replacement, I wrote a simple bash script to growl at me 5 minutes after I run it.

Growl

Download Growl, and GrowlNotify. Install the Growl.dmg, and extract the growlnotify binary and copy it /usr/local/bin (or somewhere else in your path). Now go to System preferences and turn on the Growl framework.

No at

My first attempt was going to use at, but after fiddling for a bit (and reaching out for expert assistance from Josh) I found the following line at the top of at man pages:

at, batch, atq, atrm are all disabled by default on Mac OS X.

pure bash

Rather then fiddle with overriding Apple’s descision in this matter, I did a little googling and figured out how to simulate what I wanted in bash.

Without further ado, my kettleison script.

#!/bin/sh

DELAY=300
TITLE='Time to take the kettle off'
MSG='Seriously, new kettles are expensive'

{
sleep $DELAY
echo $MSG | growlnotify $TITLE 2>/dev/null
} &

Copy this into your path, and you should be all set.

Obvious Improvements

Obviously it would be nice if the script took arguments on the command line. Even better would be if the notifications stuck around a little longer then the default 5 seconds. But those are both for another night (wasted too much time on at)

Additionally this script is entirely incompatible with a good book, as with most other non-OS X running devices.