Tag: Fun


December 27, 2010 » Geek

So, something really simple was staring me in the face and I ignored it. CSS transforms. I’ve switched to that, but I still like the webkit stuff, it was fun to glue together.

This Sunday I tinkered for a few hours on a little project. I registered the Unicode version of my domain name, upside down (ǝɥɔɐɔʇǝʌlǝʌ) This was inspired by the post from The Sad Story Of The Unicode Snowman: ☁→❄→☃→☀→☺→☂→☹→✝.ws as posted on Hacker News.

It had to be a .com, but I bought it from DreamHost anyway.

Next I thought about Upside-Down-Ternet from a while back, but I wanted mine to be all upside down.

So, I glued together some stuff and I now have an upside down copy of this website at that domain. It’s a bit rough right now, I’m rendering it in Webkit with wkhtmltopdf and then rotating and slicing with ImageMagick, all glued together with PHP and some shell scripting.

I want it to be an actual HTML copy eventually, but if you visit my domain it should show you anything on www.velvetcache.org. You can even view this post: http://www.ǝɥɔɐɔʇǝʌlǝʌ.com/2010/12/27/www-ǝɥɔɐɔʇǝʌlǝʌ-com

I added a little link to all of my pages to let you flip them in place, it’s the very bottom right and it says “[dılÉŸ]”. It’s my newest little easter egg, like the Konami Code.

Tags: , , ,

Tail In PHP

December 3, 2010 » Geek

So I’m working on a little admin interface and I decided to tail some logs. It’s in PHP and Google came up with some stuff, but they were all a bit finickey and not well documented. So I wrote my own!

Here’s the basic concept:

  1. Open File
  2. Seek To End
  3. Loop:
    1. Seek Back By Chunk Size
    2. Read Chunk
    3. Count Newlines
    4. Stash In Buffer
    5. Break If Enough Newlines Total
  4. Trim Extra Line & Cruft
  5. Done!

Here’s the code:

function tail ( $file, $lines, $max_chunk_size = 4096 ) {

  // We actually want to look for +1 newline so we can get the whole first line
  $rows = $lines + 1;

  // Open up the file
  $fh = fopen( $file, 'r' );

  // Go to the end
  fseek( $fh, 0, SEEK_END );
  $position = ftell( $fh );

  $buffer = '';
  $found_newlines = 0;

  $break = false;
  while( ! $break ) {
    // If we are at the start then we are done.
    if( $position <= 0 ) { break; }

    // We can't seek past the 0 position obviously, so figure out a good chunk size
    $chunk_size = ( $max_chunk_size > $position ) ? $position : $max_chunk_size;

    // Okay, now seek there and read the chunk
    $position -= $chunk_size;
    fseek( $fh, $position );
    $chunk = fread( $fh, $chunk_size );

    // See if there are any newlines in this chunk, count them if there are
    if( false != strpos( $chunk, "\n" ) ) {
      if( substr( $chunk, -1 ) == "\n" ) { ++$found_newlines; }
      $found_newlines += count( explode( "\n", $chunk ) );

    // Have we exceeded our desired rows?
    if( $found_newlines > $rows ) { $break = true; }

    // Prepend
    $buffer = $chunk . $buffer;

  // Now extract only the lines we requested
  $buffer = explode( "\n", $buffer );
  return implode( "\n", array_slice( $buffer, count( $buffer ) - $lines ) );

You can give it a try on some junk data here: http://static.velvetcache.org/pages/2010/12/03/tail-in-php/

Detours Clone

November 4, 2010 » Geek

This week Jerod Santo released a nifty little app he had written for the Mac called Detours. It’s pretty cool, it’s a nice GUI where you can add routing information. So, you can make the DNS resolver think google.com is located at Stuff like that.

I use Linux though, and I wanted some of that goodness. Unfortunately, Jerod told me that Detours uses some OS X specific API calls. So, cool for Mac folks but lame for me.

That evening I set off to write a portable version of Detours by using the hosts file (/etc/hosts) on Linux. Naturally since I’m groking a text format it’s uglier, and it requires a daemon/client set up since the hosts file is write-locked for normal users.

But, I got one working that night and I’ve built it out since then. So I present to the Linux users of the world, Detours Clone. Lame name I know, if you have a suggestion for a better one let me know.

Anyway, I have a nice Python daemon and three Python clients (Qt4, GTK+ and a web server!). They speak JSON over TCP sockets (bound to of course) and work well so far. I even wrote a few tests and a distutils installer.

So go check it out!

The Qt4 Client
The Qt4 Client

Node Knockout – Team LazerCatz!

August 30, 2010 » Geek

This weekend I participated in Node Knockout with Jerod and Cody. It was awesome, we made a game in 48 hours (less than that of actual working time).


It was a lot of work, how much?

We had 129 total commits, 82 were mine, 35 belonged to Jerod, and 12 to Cody. That’s not 100% accurate because Cody had some git problems part way through, so I committed things for him. In those commits we had 245 file changes.

The final product had 974 total lines of code, as broken down by CLOC:

Language   files   blank   comment   code    scale   3rd gen. equiv
Javascript     4     130        43    750 x   1.48 =        1110.00
CSS            1      26         4    167 x   1.00 =         167.00
HTML           1       0         0     57 x   1.90 =         108.30
SUM:           6     156        47    974 x   1.42 =        1385.30

If you have a minute, give it a shot at http://www.lazercatzthegame.com/.

More Lomo Photos

July 14, 2010 » Geek, Life

We found and developed four rolls of film the other day. Here are some of my favorites from the batch. Fisheye shots are Darcy’s, the others should all be mine (some of these are few years old though, so no promises on that).