Archive for the 'Javascript' Category


Webkit feature test

The last few days I’ve been writing a 3D game.

  • Not just a game, an online multiplayer game.
  • Not just a 3D game, but one run in my browser.
  • Not just in my browser, but only with CSS and HTML(and some JS and server side stuff of course).
  • Not just AJAX, but Comet.
  • Not just PHP+MySQL, but only ±30 lines of Bash.

Don’t believe me? Watch this:

It started out a few days back when I read about Comet. I found out about the new EventSource support in Webkit, but I was in doubt how to implement this on the server. My first thought was throwing some PHP+MySQL at it, but I decided otherwise.

Normal Ajax is pull data transfer. You push data to the server, but every time you need data you request it and PHP in turn requests it with the database.

Doing Comet with PHP+MySQL would make the server push data to the client, but the server still does pull transfer with the database.

Then I came up with named pipes, and because named pipes are the easiest in Bash I used that. Now every listening transfer creates a FIFO and all new data is just written to them. This system creates on big U-turn where everything submitted is instantly sent back to all the clients.

This is all the bash code I’m using:


echo "Content-type: text/plain"
echo ""

cd data
echo -e "event:message\ndata:$QUERY_STRING\n" | tee -a $(ls -1)

cd data

if [ $(ls -1 | wc -l) -lt 5 ]
    echo "Content-type: text/event-stream"
    echo ""

    mkfifo data$$
    trap rm\ data$$ SIGTERM SIGKILL EXIT

    while [ -p data$$ ]
        cat data$$
    echo "Content-type: text/plain"
    echo "Status: 503"
    echo ""
    echo "Sorry, server to busy!"

For the client side all I had to do is set up an AJAX form submitting player information and move players when an event occurred. The 3D part is done entirely with Webkit 3D transforms. The only downside about using EventSource and -webkit-transform is that you can only play my game with a nightly of Webkit(if you’re unsure if you have one you don’t).

I would love to share my game, but my host refuses to run it. It’s using gzip compression so all events are queued up until the request times out. You can however throw from the widget in your cgi-bin and try it yourself.


“Hacking your own Twitter widget” for beginners

In the last few days I received 2 questions about how to get a Twitter widget on your site to display some data other than a user timeline. Since I love writing stuff I know that people like instead of what I think they will like, I’m going to write a short howto on getting your custom widget.

Getting your user timeline in a widget is easy; Go to Twitter and grab the code from this page:

If you look at the code you’ll see a link like this Go ahead and click it! It’s a JSON file with my latest tweets.

The cool part is that Twitter has a whole API of urls you can use to get your data. The default widget is using statuses/user_timeline. Note the XML structure at the bottom. We can replace this url with any public url that returns the same structure, that means statuses containing a user, not users containing a status.

Here is a list of a few API calls you could use:

An example using my favorites would look like:

<div id="twitter_div">
<h2>Twitter Updates</h2>
<ul id="twitter_update_list">
<a href="" id="twitter-link" style="display:block;text-align:right;">follow me on Twitter</a>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>

You can now paste this html code anywhere you want it to appear!


Twitter mindmap

I’ve never used Twitter before, I considered it useless. But today I registered at, only to surf straight to their API page to realize my new idea.

Those of you familiar with the concept of mindmaps know that they can visualize information which normally would need pages in one single image. Wouldn’t it be great if you could see your network and messages as a network/mindmap? It IS a network after all. 😉

What I made is a mere proof of concept. It fetches some friends and messages from Twitter and shows them at a random place connected with black lines to their author, @friends and #tags. Clicking on a friend shows their network. All objects ar draggable, thanks to jQuery(the image below is slightly ordered 😀 ).

I’ve got no place to put this except for here, so I can only give you an image and a zip file(Box widget over there >>> ), no live example.



jQuery Rapid CSS/XHTML Prototyping (QRP)

I stopped for a while working on my Python CMS, but in my head I was already playing for a while with in place editing(like Adobe Contribute) and a round context menu.

I finally decided to spend some time on trying it out. As with most things I make, I imagined it to be very simple, but in reality you always encounter things that you simply did not thought about. Because this is just a tryout, I did not bother to check it in any browser except Safari.

The idea is this: throw in some jQuery and plugins, set contentEditable to True, write some JS glue, and TADA! Finished! The reality: Not very different, but it takes some time.

I started out with the image and the css for the context menu, then I turned on the contentEditable. After some playing around with that I started to write some JS to let the menu appear on the right spot and enter the clicked tag(mind the difference between currentTarget and target!). Now I looked for a bunch of jQuery plugins, the ones I currently use are: rigchtClick, markitup and in the future maybe thickbox. The problem with thickbox is that it applies a padding and margin of 0 to all elements. I previously used TinyMCE, but it does not use jQuery and it refused to interact with the content part(TinyMCE turns your textarea into an iframe, and I was to lazy to modify my script to read an write to the iframe).

So here you have it.

Here is a little howto:

  1. Fire up Safari 4 (other browsers are not guaranteed to work)
  2. Open index.html within the zip file (extract it maybe? 😉 )
  3. Right click in the content area, choose a tag, or type the name of it in the text field.
  4. Click our newly created tag, now you’re in editing mode!
  5. You can now: edit the text in place, drag it around, edit the id and class, assign css to it, edit it with markitup, or add more tags!

screenshotPicture 8

My blog has moved!

My blog has permanently moved to a self hosted Wordpress at

This blog will stay around for accidental search engine visitors.


This is me

Blog Stats

  • 22,921 hits