Grammar-Based Event Logging

August 24th, 2010

This is a big one, so hold tight!

One of the most common tasks in any application, on the web or otherwise, is logging. The list of uses for a good log of events occurring within your application ‘space’ is practically infinite, but at the simplest we can say that a log lets the developer store and then communicate to the user things that have happened and that it lets the developer better understand what is actually happening in his application, particularly when something unexpected or undesirable is occurring!
Read more »

BFCollections

August 20th, 2010

I’ve been doing a bunch of PHP programming the last few weeks for a client and it’s been such a pain to use PHP’s archaic array_* methods. And don’t get me started on having to return arrays like array('result' => 'not_ok', 'message' => 'User not found') to indicate success or failure. I had some time to kill at the airport yesterday, so today I am happy to bring you BFCollections. The collections included are:

  • BFArray: A better array. It can be used just like a native array but it also has methods for common array operations such as map, filter, and reduceLeft.
  • Option: Indicates an optional return result, via the form of an instance of the Some class or the global $None. Inspired by Scala’s Option (naturally) and Haskell’s Maybe. There are basic methods to operate on the values.
  • Box: Again indicates an optional return result, though the lack of a value can also be indicated and even chained. Inspired by the Lift framework’s Box.

If there’s interest I’ll see about improving them and even adding additional collections.

Everyone’s Using Scala

August 13th, 2010

Twitter, LinkedIn, TomTom, Novell, Yammer, Meetup, Remember the Milk – the list goes on! Cool!

Imajs

July 23rd, 2010

I made this a month or two ago but I forgot to mention it here: Jacob Biljnai of Tumblr was complaining on Twitter that there wasn’t a Javascript-based image resizing API so I made him one using App English, Imajs. Enjoy.

Installing Twisted on OS X

July 21st, 2010

I’m using Twisted for a project and the default sudo easy_install twisted was giving me errors. It turns out that my default Python install, via Fink, was built for the i386 architecture while Twisted was trying to link to its libraries using the x86_64 architecture, for which it does not have libraries built. sudo ARCHFLAGS='-arch i386' easy_install twisted did the trick.

Seats Available in My Office

July 13th, 2010

There are now two seats available in the office in the old Volkskrantgebouw on Wibautstraat. You’d be sharing a 45 m2 room with me, Eelco, and Sjoerd. We’re nice, friendly coders and don’t cause a lot of fuss. It’d be nice if you were there same, though being a coder isn’t a requirement by any means. Rent is approximately €90 per month. Please email me at peter@bubblefoundry.com if you’re interested.

Lift Presentation at DuSE VI

July 1st, 2010

I gave an introductory presentation on Lift last night at DuSE VI. You can download the pretty PDF or view in on Slideshare. And guess what, it’s already out of date: 2.0 is now out!

Fun with Scala Implicits

June 21st, 2010

Last night I discovered that Scala’s RichString has a format method quite similar to  Python’s. However, in Python I’m used to using the % operator and I wondered if I could use the same syntax in Scala. With a little library pimping and help from my friends on Stack Overflow, I can:

class BFString(s: String) {
  def %(in: Any*) = s.format(in: _*)
}
 
implicit def add_%(s: String) = new BFString(s)
scala> "The %s costs $%d." % ("dog", 255)
res2: String = The dog costs $255.

Pretty cool!

Nginx Sitting in Front of Apache

June 17th, 2010

On my Slicehost virtual server (signup with my referral link) I originally set up Apache as my web server, with a bunch of virtual hosts to manage serve different domains. This has worked well but I am now working on projects (namely Lift apps running in Jetty) where Nginx is a much better solution. So, I decided to stick Nginx in front of Apache.

Translating my vhosts was quite easy: I simply changed their Apache settings to only listen on localhost:8888 and created settings in Nginx that look like this:

server {
  listen 80;
  server_name thedomain.com www.thedomain.com;
    location / {
      access_log off;
      proxy_pass http://127.0.0.1:8888;
      proxy_redirect off;

      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

However, I also want to occasionally throw up the odd PHP script for testing. There’s no mod_php (or libphp, or whatever it’s called these days) for Nginx and the most common solution is using FastCGI. That looks good but I figure that since I already have Apache playing nicely with PHP, I might as well use it. So how to do it? I set up the following in Nginx:

server {
       listen 8989;
       server_name BubbleFoundry.local;
       location / {
                 proxy_pass  http://127.0.0.1:8889;
                 proxy_redirect off;
                 proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header Host $host;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       }
}

And in Apache I simply had my default virtual host listen on 8889.

This works well, though I noticed that when Apache returns a 404 error the response returns back to Nginx. If I go to http://myserver:8989/somefolder, it gets kicked back to Nginx which then returns a 404 error. http://myserver:8989/somefolder/ (notice the trailing slash), on the other hand, works. Probably just need to tweak something in my Apache settings, but it’s good enough for now.

HTML5 TV

June 15th, 2010

At the Dutch GTUG HTML5 Hackathon I decided to make an HTML5 TV.

My HTML5 TV uses a whole grab bag of hot web features:  CSS 3SVG, the canvas element, the video element, and HTTP live streaming video. In theory the TV works in all of the most recent versions of the Safari browser variants. However, in Mobile Safari Apple puts a custom overlay over the video element, hiding the static, and prevents videos from playing automatically. I leave it up to you whether this is desirable. Given this, I recommend you use Safari 5 on OS X to view the page.

I can confirm that the latest version of Chrome on OS X does not play HTTP live streaming videos. If you can’t see HTTP live streaming video in your browser and are comfortable with its Javascript console, you can change the channels used like so:

TV.channels = [
  {
    'name': 'BBB',
    'url': 'http://cdn.kaltura.org/apis/html5lib/kplayer-examples/media/bbb_trailer_iphone.m4v'
  }
]

As you can see, channels is an array of anonymous objects with name and url properties and you can have as many as you want. I recommend doing this before you turn on the TV.