Archive for the ‘code’ Category

First commit of a theme for all Creative Commons chapters around the globe?

Wednesday, November 11th, 2009

Today, I finally added my first commit of the Creative Commons Netherlands(CC NL) wordpress theme (see also ‘New Creative Commons Netherlands site launched’) to the Creative Commons.org git repository. This means that other local CC chapters only need to install Wordpress and install this theme to have their own Creative Commons website. For example, Creative Commons France could now easily update their website and have a look and feel similar to Creative Commons Netherlands (and thus Creative Commons.org), without having to develop a theme on their own. By using this template, local Creative Commons organizations show more cohesion between the different CC chapters and allow them to be identifiable as part of the global Creative Commons movement.

I’m very interested in the response on this theme, although it’s still kinda rough around the edges. I still need to find some time to replace the Dutch names for English, write something down on how to use the theme  and there’s probably tons of stuff that might need some tweaking, but at least it’s in the repository.

If you’re interested in using it yet something is keeping you from doing this feel free to contact me and I’ll see what I can do to help you.

Last but certainly not least, I would like to thank:

- Paul Keller (Creative Commons Netherlands) for recognizing the potential use of this theme for other local CC chapters around the world.
- Mike Linksvayer and Nathan Yergler from Creative Commons.org for their enthusiasm, help and infrastructure.

Bram Cohen on Object Oriented Programming

Sunday, September 27th, 2009

“Taken less literally, it’s just gibberish, a completely nonsensical way of thinking about the problem, like teaching a drawing class where you cover pentagrams.”

Bram Cohen (inventor of the p2p Bittorrent protocol) has an interesting view on subclassing in object oriented programming.

Wordpress simple redirect

Tuesday, September 1st, 2009

Recently I needed an easy way for a client to create a link in a Wordpress powered website that would automagically redirect a visitor to a certain location upon visiting. Part of the requirement was that this link could be easily remembered and used in printed material such as leaflets and magazines. As an extra option it should be easy to change the location towards the redirection would point. I couldn’t find anything like this so I created a very simple little page template.

How it works:
Copy the template page Page Redirect code below to a file and save it as page-redirect.php in your own template’s directory. Create a Page in Wordpress and set the Page’s template to Page Redirect. Add a custom field to this page with the name redirect_url and the full url of the url you want to redirect to.
For instance: http://www.redirected-location.com. Now save the page and you should now test it by visiting the page you created.

For example (I assume you are using nice urls):

http://www.your-website.com/the-page-title-of-the-page-with-the-redirect-template

If all went well you should be instantaneously be redirected (using a standard php redirect with a 302 HTTP redirect) ) to the url you entered in the custom field. You can easily change the redirect location by changing the value of the custom field.

Code:


< ?php
/*
 * Template Name: Page Redirect
 *
 * Makes it easy to redirect a page to another url, using the parameter redirect_url
 */
$redirect_url = get_post_meta($post->ID, "redirect_url", true); 

// Defaults if no options we're given
if( ! empty($redirect_url) ) {  header("Location: $redirect_url"); } else { echo ""; }
/* Make sure that code below does not get executed when we redirect. */

exit;
?>

As I said it uses the standard PHP redirect, but you could easily change or extend it with more specific http headers if needs arise. Feel free to use the above snippet as you see fit, as far as I’m concerned it’s in the public domain. I hope this might be useful to you. If you have any questions, feel free to leave a comment.

Mapping firefox keyboard shortcut with vimperator to select a tab

Friday, May 1st, 2009

I’ve started to use the Firefox add-on Vimperator. It enables Firefox to behave more like Vim. I installed this add-on, not because I know Vim so well, but because I really like the ability to use my browser with a keyboard.

One of the things I really missed after installing Vimperator was the ability to select an open tab directly by a keyboard shortcut. I’ve used the following mapping (a well known method to vim users) to fix this and now I can select an open tab directly.

:map <C-1> :tabn1<CR>

In the snippet above I created the shortcut CONTROL-1 which selects tab number 1 following with ENTER. I would like to use a variable in the mapping but I have not been able to find out how to achieve this, so for now just add more mappings with following numbers, e.g. replace 1 for 2 etc. If you know how to add variables in vimperator let me know!

If you don’t see the numbers in your tabs or don’t see tabs at all you’ll need to enable the gui, you can use the following snippet:

:set go+=mTBn<CR>

This shows the following gui parts:

  • m Menubar
  • T Toolbar
  • B Bookmark bar
  • n Tab number

Now you should see the gui including the numbers in the opened tabs.

NB: Don’t forget to save the settings with the following:

:mkv<CR>

if you’re already have a saved configuration then you need to add a exclamation mark to the above.

:mkv!<CR>

Quick howto using Virtualbox with webdevelopment

Friday, March 27th, 2009

I use Virtualbox (version 1.5.6_OSE) on Ubuntu Hardy with Windows XP as one of the (guest) virtual machines. In order to access my webserver installed on the host (real physical system (Ubuntu Hardy) I need to use the ip-address 10.0.2.2 (I use NAT in Virtualbox’s network settings) from Windows XP (or any other guest operating system) and edit the hosts (c:\windows\system32\drivers\etc\hosts) file with the Virtual Host names I use on the host. This allows me to access the Virtual Host based websites to be accessed from the Windows XP operating system.

An example hosts file on Windows XP:

# make sure there's at least one space between the ip-address and the virtual host name
127.0.0.1 localhost
10.0.2.2 SOME_VIRTUAL_HOST_NAME

Replace SOME_VIRTUAL_HOST_NAME with a real Virtual Host name. In my case I use the extension .dev to indicate a local project in development, so it could be something like burobjorn.dev

Internet Explorer and “Operation Aborted”

Friday, March 20th, 2009

I was working on a website for a client when we discovered that sometimes the website was not accessible for Internet Explorer. Notice the word sometimes.

A word dreaded by every programmer including myself. In order to solve problems there needs to be a pattern. Something like: “press the red button and the screen goes blank”. Without the ability to reproduce a problem it is really hard to solve the problem or confirm that the actions you took to solve it were indeed the (right) solution and not some fluke.

In this case a user visited the website and got access to it, or the user visited the site and got an arcane error message:

“Internet Explorer cannot open the Internet site http://<Web site>.com. Operation aborted.”

I never saw this message before and after some testing we could confirm it only happened with Microsoft Internet Explorer. There were no problems with any other browser, but somehow Internet Explorer sometimes spat out this utterly useless error message and prevented the user to visit the client’s website.Together with some engineers from the hosting company I sat out to find and solve this issue. So we started to have a look at the web server’s  log files.

At first the engineer from the hosting company suspected it might have something to do with some HTTP 500 error codes, missing images (so you would expect HTTP 404 errors) and some rewrite rules. According to his first thesis this combination might have caused a redirection loop and Internet Explorer could not cope with it. After quickly fixing the missing images (a typo in a path) we could dismiss this thesis and we continued our quest. Luckily a colleague of one of the engineers remembered a similar issue creeping up with a different client of them and pointed us in the right direction. A quick search (note to self don’t try to be smart, first search for the error message on the Net, then analyze logfiles) later gave use quite a lot of links pointing towards Microsoft.

Apparently Microsoft’s engineers think that its a good idea to confront a user of their browser with an arcane error message and prevent the user from accessing the website when the visited website in question does something less smart (maybe even stupid). While any other browser would at least try to let the user access the website and cope with the issue. I wonder where the Interaction Design people were during this decision.

No, I’m not making this up. Microsoft states in the knowledgebase article on this issue: “This behavior is by design.” What are the arguments for doing it this way? Interestingly in the same article they claim:

How do I fix this problem?
The easiest way for you to fix the problem is to upgrade to Internet Explorer 8. This problem no longer occurs in Internet Explorer 8.

So the behavior is by design, yet they advice you to solve it by upgrading your browser. Interesting, to say the least.

Anyway, after reading the article and doing some more debugging (which is a lot more painful then it ever should be using Internet Explorer) I found the culprit to be a piece of JavaScript (swfobject.js in this case) trying to access an element before the parser was ready. A bug and certainly something we needed to fix, but Microsoft did you really have to abort loading the webpage and preven the user from accessing it? Why can all the other browsers cope with this and still allow the user to visit the website? Would it have hurt to show a less obtrusive error message in the status bar?

For those having similar issues please see these urls for more info:
http://support.microsoft.com/kb/927917/
http://blogs.msdn.com/ie/archive/2008/04/23/what-happened-to-operation-aborted.aspx

Commandline bookmarker

Wednesday, March 4th, 2009

When you use the commandline a lot like I do, you sometimes wonder about the amount of typing involved. Even if you use tabs like a maniac, you’ll probably end up typing certain paths a gazillions times a day. Not anymore…

I stumbled upon a great little time saver called bm (bookmark). It allows you to bookmark (as if you’re in a web browser) certain paths and create a cdbm command which allows you to quickly change directory to the bookmarked path.

1) To create a bookmark type:

bm -a /path/you/want/to/bookmark name_of_your_bookmark

2) To use a bookmark type:

cdbm name_of_your_bookmark

I highly recommend this nifty little timesaver. You only have to compile it (it’s really easy, just follow the two instructions in the README.txt) and I can confirm it works without a hitch on Ubuntu 8.04, but my guess is that it would probably could work on other POSIX systems as well (like OS X).

Thanks to Bart from Onderstekop.nl for creating it!

UPDATE
Download the bm_1.0-1_i386 package I created for Ubuntu. Tested on Ubuntu (9.04) Jaunty on 32-bit architecture and it works for me. Your mileage may vary!

Distributed version control

Monday, September 1st, 2008

I’ve had my share of bad luck the last week. Servers dying, Internet connections going down and all sort of annoying technical issues you rather not want to work on while having deadlines. During this I noticed that using Subversion as a tool for version control and in my case general asset management for projects kinda sucks. If you don’t have a connection or the server goes down, you cannot use the repository in a structured manner. So I’m going to leave the centralised server repository for version control behind and start using distributed version control. I’ll still use a central server for backup and easy access for clients and collaborators, but I will not be dependent on it anymore.

Since its kinda hard to know which of the myriad of distributed revision control systems (DVCS) complies with my demands I’ll start using some of the ones that looked most promising.  The features I’m looking for are:

  • can handle binary files efficiently (I need images and other binary files in a repository as well)
  • is cross-platform (I do not want to be tied to one platform, nor do I want to force other to use my preferred platform)
  • ease of use (yep that’s a feature in my book)
  • tools (it needs to be extensible preferable in a language I already know)
  • documentation (also a feature in my opinion)
  • off-line usage is just as good as on-line usage
  • has community and support options available

I’ll be checking out Mercurial (I hope to contribute to this project for my Neuro OSD and learn a bit of Lua), Bazaar (also checking it out with a small project) and maybe I should have a look at Git.

Off course, the DVCS of my chosing needs to be FLOSS.

Any hints and tips are appreciated!

Hackers festival in NL 2009?

Thursday, August 7th, 2008

In 1989 a great tradition started with GHP (Galactic Hacker Party), which continued four years later in 1993 with HEU (Hacking at the End of the Universe), HIP (Hacking In Progress) in 1997, HAL (Hacking At large) in 2001 and finally WTH (What The Hack) in 2005.

Next year a new crew wants to organize the next event in this fine tradition. The name has been set on HAR2009 (Hacking At Random 2009). I’ve been part of this tradition in one form or the other since HIP97 and thus this event would by my ten year anniversary. Can’t wait for it.

ps: To clear some mistakes up on the definition of hacker, check out this description

updated profile_picture plugin

Tuesday, August 5th, 2008

I just updated my version with the profile_picture plugin with a patch supplied by Johannes Harms. I haven’t had the time to test it thoroughly, so use it on your own risk. More info on this page

If you’re interested, you can check the patch here below:
(more…)