Wishful Coding

Didn't you ever wish your computer understood you?

Restore the old iTunes icon

Since the last keynote, where Apple announced iTunes 10, I've heard a lot of complaints about the vertical close buttons and the new icons.

For the close buttons you should keep an eye on http://hints.macworld.com/, but at least I solved the problem of the ugly icon.

Before updating, save the old icon by right-clicking on iTunes, and then on "Show package contents", then browse to Content/Resources and copy iTunes.icns somewhere safe.

Now upgrade iTunes, and do the same thing in reverse, so you'll overwrite the new iTunes.icns. Below is a video and the original icon, in case you are to late to copy it yourself. You might need to start and stop iTunes a few times, or even reboot to se the "new" icon.

(download)

[update] Posterous doesn't like my icon. Download it from Dropbox instead: http://dl.dropbox.com/u/10094764/iTunes.icns

Also, about the control buttons: defaults write com.apple.iTunes full-window -1

http://hints.macworld.com/article.php?story=20100901223846748

A smile for web standards

We all love web standards. While I was implementing a little easter egg(which are also very lovable) on http://coverontwerp.nl/ with a good deal of CSS3 love, I thought it would be nice to turn as many clicks as possible into a smile for web standards, a mini ACID test if you will.

Bellow you'll find a CSS snippet that, when included on your site, will flash a smile for every link clicked in a supporting browser.  It is totally unobtrusive, and only blinks the moment anyone clicks a link, thus spreading some positive feelings to all supporters of web standards.

Example implementations can be found here and on http://coverontwerp.nl/. Show some standards love, by including the snippet below on your site!

Other selectors, styling and ASCII arts are encouraged!

Posted 1 day ago

Search Google in running browser

After reading this hint, I wanted to get it working with my previous script to open links in the currently running browser.

I did not use OnMyCommand, but instead just made an Automator service. Here is how:

  • Open Automator and create a service
  • Set the type to text
  • Add the ‘Run shell script’ action
  • Set the shell to Python and the input to ‘as arguments’
  • Paste the script below

The script(this text serves only to satisfy Posterous’s parsing engine, which is seriously pissing me off):

import sys
import urllib
import webbrowser
webbrowser.open("http://www.google.nl/search?q=" + urllib.quote(sys.argv[1]))

Automator

You need to have my previous script installed to do the actual opening of the url. With some more trickery, it is even possible to add this service as a keyboard shortcut. I suggest you Google around a bit, and comment if you find something revolutionary.

Posted 10 days ago

JS server benchmark: Node.js & Rhino; Part 2

After having tested the pure JS speed of Node and Rhino in my previous post, I wanted to see some actual numbers for serving stuff.

Long story short, I grabbed the "Hello world!" examples from both Node.js and Rhino running on Jetty and ran 'ab' on them.

I was not able to do high-concurrency tests on my Mac, because Jetty gave up around 100, and Node somewhere around 200. I think I'm having the issue described here.

So here is the graph. I don't have much experience with benchmarking, but again, it is obvious that Node.js is in fact quite a lot faster than the Rhino/Jetty combo.


Posted 11 days ago

Remove the bookmark button in Safari

A while back I found this comic, comparing Safari with a bike, and Firefox with a car with a lot of stuff attached to it.

But in reality, since Safari 5 supports extensions, it starts to look more and more like this illustration from a Dutch children book.

Now that I have lots of goodies and a nice Delicious bookmark button, I wanted to get rid of the bookmark button embedded in the navigation bar. This video shows how to do it.

(download)

If someone knows how to embed the Delicious button in the navigation bar, I would be very pleased.

Posted 13 days ago

JS server benchmark: Node.js & Rhino

Background

I’m playing with the idea of writing a little web framework in JavaScript using jQuery on both the server and the browser. To run jQuery on the server, you need — except for JavaScript — some magic, such as env.js and jsdom.

Env.js is a complete browser environment that allows you to run almost all browser JS code(like jQuery) on Rhino, a JavaScript engine written in Java. It is very complete, but tied to Rhino.

Jsdom is a younger project implementing only the DOM in CommonJS, though it is written for Node.js, an event-based network server based en Googles V8 JavaScript engine.

While I know some Java, and env.js does all I need, I got the impression that Node.js offers more in terms of speed and is more suitable for a web framework.

Since jsdom does not do AJAX and events, I’m facing the choice between using Rhino, or porting env.js to Node. I started to investigate the possibilities, and here is what I found.

Running the benchmark

Searching for benchmarks comparing server side JavaScript, I found none. I did find the JS benchmark Google uses to test V8, which might of course be skewed towards V8. I tried them anyway.

Node.js

Installing Node was a breeze, but getting the V8 benchmark to run on a V8 based framework was not so easy.

For some unknown reason the V8 benchmark uses load() to load everything together, while Node uses require(), with a slightly different meaning, which made simply substituting them impossible.

Stride on #node.js came up with the solution, consisting of concatenating the files together with some shell magic:

cat base.js crypto.js deltablue.js earley-boyer.js raytrace.js regexp.js richards.js splay.js run.js > v8bench.js

Note that the order of the files was important, otherwise a simple “cat *.js” would have sufficed.

Now all that remained was commenting out the original imports and defining a print function:

print = require('sys').log

Now this is the result:

$ node v8bench.js
19 Aug 16:13:25 - Crypto: 2434
19 Aug 16:13:26 - DeltaBlue: 3150
19 Aug 16:13:28 - EarleyBoyer: 12752
19 Aug 16:13:29 - RayTrace: 6230
19 Aug 16:13:30 - RegExp: 2287
19 Aug 16:13:31 - Richards: 1547
19 Aug 16:13:33 - Splay: 8879
19 Aug 16:13:33 - ----
19 Aug 16:13:33 - Score (version 5): 4090

Note the last number(average score) and the length of the command(2 parts).

Rhino

Installing Rhino was equally easy(just “port install rhino nodejs”)

Then the trouble started… First I had to figure out how to run Rhino, because it doesn’t come with its own command, like Node does. Turns out it’s “java -jar /path/to/js.jar”

After that, I ran ‘run.js’ from the v8 benchmark, and it just worked! Without modification! … Until it gave java.lang.OutOfMemoryError. Some Googling reveals that unless you have a memory leak in your app, you can increase the memory limit, which I did.

Here are the results for Rhino:

$ java -Xmx265m -jar js.jar run.js
Richards: 20.4
DeltaBlue: 138
Crypto: 120
RayTrace: 253
EarleyBoyer: 248
RegExp: 59.1
Splay: 279
----
Score (version 5): 120

Again note the score and the length of the command(5 parts). The -Xmx265m is for raising the memory limit.

My verdict

Sure, Node’s score is about 34 times the score of Rhino, but I talked to the author of Claypool, and he used Rhino for several production sites, without performance problems. It’s a measurement without a scale, so I can’t judge if it will matter to me.

With the speed sorted out, there is just the general style and comfort of both systems. Node.js is a very young C++ project, while Rhino has been around since the Netscape ages and is written in Java.

While I’m attracted to the speed and freshness of Node, I know more Java than I know C++, and there are tons of Java libs available to Rhino. And then there is env.js, which needs to be ported to Node, if I decide to use that.

Besides the porting and library issue, there is also hosting. Because Node is so new, you’d have to rent your own VPS, while Rhino can run in any Java servlet container, and even Google App Engine with the help of Rhino-for-webapps

So, my verdict? Undecided: As always, it depends on what you want, and I’m not yet sure what I want.

[update]

FireFox gets only 394 in the same test, so Rhino is probably not that bad.

I would be very grateful if anyone could give me some information on the CommonJS load/require and print problem or ways to speed up Rhino.

Posted 14 days ago

Twisted pop3 example server

Remember last time when I showed you the Twisted SMTP server? This time it's a POP3 server. I think it is more common to write SMTP servers as a part of a project(to send notifications and stuff), but I needed a POP3 server, so I think there might be others who need a POP3 server as well.

The process is rather similar to SMTP, only you need to implement the IMailbox interface. This is usually done with some sort of file or db based solution, but I used a simple list in this case. You might want to have a look at the mailbox module for a serious implementation.

Below you'll find a bare bones POP3 server, which can be run with `twistd -ny pop3.tac` and below that a sample telnet session, by running `telnet localhost 1230` in another terminal.

Posted 15 days ago

Check multiple twisted.cred checkers for a valid login

This is a snippet of a credential checker I wrote to authenticate a user
first via my DB, and if that fails via Twitter. It helped me to speed up
login, after the initial Twitter access tokens are stored.

In theory, this snippet could be used to authenticate against any number
of checkers, providing different interfaces. Only if all of them fail,
it returns an error.

Posted 1 month ago

XAuth(CamelCase), xAuth(iCase), XOAUTH(ALLCAPS); 3 distinct technologies, confusing?

While thinking up names, Unix/open source people tend to come up with names containing ‘X’. I can almost hear them scream “‘X’, the new and free(as in beer, pizza and speech) ‘i’(as in iPhone, iPod, etc.)!”

My (possibly fictive) story goes like this: Some time ago, 3 separate development teams came together to find a name for their product.

The first team was making a secure, social, easy way of authenticating browsers. Since they where developing an open authentication protocol, and read loads of developer guidelines, they came up with XAuth, using proper CamelCasing, as one was supposed to.

The second team had a nice OAuth implementation running, but some people required using good ol' passwords, so they came up with the idea of requesting tokens using regular credentials, instead of complicated token exchanges. Since they wanted to be hip, and had a nice marketing department, they came up with xAuth, in line with the iDevice casing.

The third team thought it would be nice to apply the security of OAuth to email. Since this was way to cool to be called OAuth-for-email, they decided to add the cool ‘X’ in front of it. And as we all know(don’t we?), mail servers talk to each other in ALL CAPS, so it was a logical thing to call their system XOAUTH(although they’re not all that consistent about it).

Posted 1 month ago

Messing with the REPL with Twisted

I love to try out things on the REPL(read eval print loop) before I write scripts with them. The trouble with Twisted is that everything returns deferreds, and after your start the reactor, you can’t do anything anymore.

All this is solved by this one single command. It gives you a REPL powered by the Twisted event loop. To make things even better: It prints the value of a deferred once it is finished!

python -m twisted.conch.stdio

Added hint: Put this in a file, do “chmod +x” on it and put it on your $PATH.

Posted 1 month ago