Blog posts tagged "unix"

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.

Reading a file backwards in PHP

February 28th, 2008

This morning I needed to read from a file line by line from the bottom. In PHP. Perl, of course, has a module to do this. A quick view source decided that I didn’t want to get into file seeks before breakfast. Very happy with my solution:

$file = popen("tac $filename",'r');

while ($line = fgets($file)) {
  echo $line;
}

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 , , , , ,