Wishful Coding

Didn't you ever wish your computer understood you?

Three good reasons to run a Webkit Nightly

  1. You get to use the latest an coolest features around.
  2. You can try out my 3D CSS browser game, which is finally online.
  3. You can see this wacky CSS endless zoom effect, and other beautiful show-offs.

No, seriously… You might not need it for daily web usage, but if you are a developer, it’s fun! Get it at webkit.org, even the nightly is more reliable than IE6. I’m using it right now to write this.

Tags: ,

How to install Python/web.py on a shared host

In the past I have written a few Python web applications, but when I asked my host about Python, they told me they where specialized in PHP and nothing but PHP(that is why this site runs Wordpress).

If your are lucky and have a very expensive dedicated server you can install whatever you want, but how about my poor projects? I’m not going to re-write them in PHP obviously.

I figured that as long as you have a CGI bin, you can do whatever you want. I started writing a CGI script that would install Python and Web.py for me; Check out the resulting web.py example.

This is the script that I came up with. It should be doable to customize this for Pylons, TurboGears, Django, or any other Python framework.

You should at least fill in your own home directory twice, we’re doing a Python installation inside you home directory.

#!/bin/sh

echo "Content-type: text/html

";

curl http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tgz | tar -zx
cd Python-2.6.4
./configure --prefix=/your/home/directory #change this to your home
make
make install
cd ..
curl http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz | tar -zx
cd flup-1.0.2
/your/home/directory/bin/python setup.py install
cd ..
curl http://webpy.org/static/web.py-0.33.tar.gz | tar -zx
cp -r web.py-0.33/web .

Note that you should add .py as a CGI handler in your .htaccess file:

AddHandler cgi-script .py

Since our fresh Python installation is not on the PATH variable, you should include a shebang header in your scripts to point to the right path:

#!/your/home/directory/bin/python

Again, check the result!

Tags: , , , , , , ,

How to navigate the browser ballot screen

How to navigate the browser ballot.

This is my response to the EU/Microsoft browser ballot screen. Honestly, most people don’t even know what their browser is, what do you think the difference in IE market share will be?

http://xkcd.com/627/ also applies here.

I recommend any of the five except IE. In case you’re wondering, I’m using Safari.

Tags: , ,

Wordpress.com Stats: Top Posts Widget

This hack is so cool and so simple, I expect anyone to run up to me and yell that this has been done before. I created a ‘Top Posts’ sidebar widget based on the widget that comes with any Worpdpress.com blog.

I know there are several widgets like this, but they all include their own statistics tracking. Mine is nothing more than an excerpt of the Dashboard widget that comes with the Wordpress.com Stats plugin.

For people not interested in technical details, here is a plugin file, that works as usual; Make sure you install the Wordpress.com Stats plugin first!

I said this hack was simple, here is way: The code is already there! I’m surprised Wordpress did not include the widget themselves. Lets have a look at stats.php:

Line 925-926:

foreach ( $top_posts = stats_get_csv( 'postviews', "days=$options[top]$csv_args[top]" ) as $post )
	$post_ids[] = $post['post_id'];

Line 942-949:

<?php foreach ( $top_posts as $post ) : if ( !get_post( $post['post_id'] ) ) continue; ?>
<p><?php printf(
	$printf,
	'<a href="' . get_permalink( $post['post_id'] ) . '">' . get_the_title( $post['post_id'] ) . '</a>',
//			'<a href="' . $post['post_permalink'] . '">' . $post['post_title'] . '</a>',
	number_format_i18n( $post['views'] )
); ?></p>
<?php endforeach; ?>

My resulting guesswork looks like this:

<h4>Top posts</h4>
<ul>
<?php foreach($top_posts = stats_get_csv('postviews', "days=7") as $post): if(!get_post($post['post_id'])) continue; ?>
	<li><a href="<?php echo $post['post_permalink']; ?>"><?php echo $post['post_title']; ?></a></li>
<?php endforeach; ?>

If anyone is interested, I can upload this to the Wordpress plugin repository.
Done: http://wordpress.org/extend/plugins/wordpresscom-stats-top-posts-sidebar-widget/

Tags: , ,

Food versus code

Food: 279kJ/66kcal; E263, E181, E459;
Code: [a-zA-Z0-9]*; &#104;&#101;&#121;

Now, which one is easier to decipher? Do you think we need simple food, simple code, or both?

For the record, the first food part is from coffee, the ingredients are Calcium acetate, Tannin and Beta-cyclodextrine. The first code part is a regex matching any number of alpha-numeric characters, the second part is ‘hey’ in html entities.

Tags: , , ,

Shorten Wordpress urls in Adium

I use Adium as my Twitter client, it includes a nice url shortener supporting multiple services, so what is my problem?

Nothing, I just had some fun making use of the wp.me service. Every Wordpress blog contains a header containing the short url, so it was only 3 lines of Applescript and one line of Bash to get the short url of any wp blog and post it to Adium.

If anyone with knowlegde of regex/grep comes around, he might get it to work with any shorturl/shortlink header.

The current line looks like this:

curl --head <url> -s | grep -o http://wp\.me/[a-zA-Z0-9\-]*

Update: sed seems to be able to do what I want.

curl --head http://pepijndevos.nl/ -s | \
sed -n 's/Link: <\(.*\)>; rel=shortlink/\1/p'

Use:

%_shorten{<url>}

Download the script: shorten.AdiumScripts

Tags: , ,

Cross-domain caching

Looking at the list of HTTP headers at Wikipedia, you’ll notice a few headers like If-Modified-Since, that serve to send content over only if it has changed since the last request.

While working with JavaScrip frameworks like jQuery, the thought occurred to me, that maybe half of all the websites I open are using the exact same JS framework, isn’t that a waste of bandwidth?

The best real-life solution would be to get your JS from Google, so you at least share a cached version with others that do the same: http://code.google.com/apis/ajaxlibs/

My imaginary solution however, would allow the same file, served from different hosts to be cached only once.

Look again at the list of headers… We’re looking for something to identify files as equal… What about Content-MD5? It exists, right there! But as far as I can tell it’s used for content-verification only.

So I want to propose a new HTTP header: If-MD5-Differs

What do you think about it? Cool? Useless? Security issues?

Tags: , ,

Automatically remove Trash from usb sticks

I think most Mac users have had this problem; You delete a bunch of files from your pen drive to make room for a large file, and it keeps complaining about lack of space.

The problem is that when you remove files on Mac, they’re just moved to a hidden folder named ‘.Trashes’, so they are actually still there. A commonly suggested solution is to empty the Trash while the USB stick is plugged in, but this might be problematic in some cases where you want to keep your Trash, just in case…

My new solution is to set this little script as a folder action, it will remove the trash only from the USB stick as soon as you mount it(unmount proved problematic).

on adding folder items to this_folder after receiving these_items
    do shell script "rm -rf " & POSIX path of these_items & ".Trashes/"
end adding folder items to

Save this script to /Library/Scripts/Folder Action Scripts/ and now set it as the folder action for /Volumes.

You might need to show hidden files in Finder for /Volumes to be visible. To do this, follow this guide.

Tags: , , ,

Write clean code!

Tags:

Nieuwe website

Hehe, eindelijk, ik heb een eigen website opgezet! Ik had al een tijdje een wordpress.com blog, maar nu heb ik een website waar ik wel alles me kan doen wat ik wil.

Tags: