Category: code

  • SSL Certificate Expiry Warning Script

    With the increasing trend of SSL on the web, where Google values SSL sites higher and you can have your site be added to the HSTS preload list (the browser will first try HTTPS before trying HTTP), it is a good idea to start using SSL yourself. The downside: you need to get a certificate…

  • Add a Rate Limit to Your Website

    Suppose you have a ressource on the web (for example an API) that either generates a lot of load, or that is prone to be abused by excessive use, you want to rate-limit it. That is, only a certain number of requests is allowed per time-period. A possible way to do this is to use…

  • munin smart plugin: ignore error in the past

    As a hard drive in my server failed, my hosting provider exchanged the drive with another one which obviously had some sort of error in its past, but now seems to be fully ok again. I would have wished to receive a drive without any problems but as my server is RAID 1, I can…

  • preg_match, UTF-8 and whitespace

    Just a quick note, be careful when using the whitespace character \s in preg_match when operating with UTF-8 strings. Suppose you have a string containing a dagger symbol. When you try to strip all whitespace from the string like this, you will end up with an invalid UTF-8 character: $ php -r ‘echo preg_replace(“#\s#”, “”,…

  • Restoring single objects in mongodb

    Today I had the need to restore single objects from a mongodb installation. mongodb offers two tools for this mongodump and mongorestore, both of which seem to be designed to only dump and restore whole collections. So I’ll demonstrate the workflow just to restore a bunch of objects. Maybe it’s a clumsy way, but we’ll…

  • trac Report for Feature Voting

    I use trac for quite a few projects of mine. Recently I tried to find a plugin for deciding which features to implement next. Usually trac hacks has something in store for that, but not this time. I wanted to be able to create a ticket and then collect user feedback as comments for the…

  • iOS 2011 Alarm Clock Bug

    Just to add to the speculation about the causes of the 2011 alarm clock bug of iOS where the one-time alarms would not activate on January 1 and January 2, 2011. My guess is that the code that sets off the alarm takes day, month and year into account when checking whether the alarm should…

  • Debugging PHP on Mac OS X

    [factolex] I have been using Mac OS X as my primary operating system for a few years now, and only today I have found a very neat way to debug PHP code, like it is common for application code (i.e. stepping through code for debugging purposes). The solution is a combination of Xdebug and MacGDBp.…

  • Website Optimization, a book by Andrew B. King

  • Upgrade WordPress Script

    Whenever a new version of WordPress comes out (as just WordPress 2.6 did), it is somewhat of a pain to upgrade it. But not for me anymore, because I have created a small (and simple) script some versions ago which I would like to share with you. $ cat upgrade_wordpress.sh wget http://www.wordpress.org/latest.tar.gz mv www wordpress…

  • bash completion for the pear command

    I am only scratching my own itch here, but maybe someone can use it or expand from it. I just always found annoying that pear run-tests tab gives all files instead of just *.phpt. This is what this snippet actually does. Paste this into the file /opt/local/etc/bash_completion on OSX (for me it is just before…

  • High Performance Web Sites, a book by Steve Souders

    I’d like to introduce you to this great book by Steve Souders. There already have been several reports on the Internet about it, for example on the Yahoo Developers Blog. There is also a video of Steve Souders talking about the book. The book is structured into 14 rules, which, when applied properly, can vastly…

  • Subversion: The Magic of Merging

    Use svn merge -rhead:{date} to go back in time with a file

  • JavaScript Tricks And Good Programming Style

    Note that this is an updated version. Original version can be found here. Thanks to the commenters I have updated this post with some better tricks. In a loose series I’d like to point out a few of them. As I am currently mostly programming in JavaScript, I will write most of my samples in…

  • JavaScript Tricks And Good Programming Style – Original Version

    Note that there is an updated version I have been programming for about 10 years now, and I am always longing for improving my code. Throughout time I added a few habbits that I consider to be good practices and increase the quality of my code. In a loose series I’d like to point out…

  • Firefox 1.5, XmlHttpRequest, req.responseXML and document.domain

    Recently I have been working on a web application, extending it with an iframe on another subdomain. When you set up communication with an iframe on another subdomain, it works by setting document.domain in both pages. Pretty nice and straight forward. But it can mess up the rest of your page. As soon as you…

  • Misuse of the Array Object in JavaScript

    There is a very good post about Associative Arrays considered harmful by Andrew Dupont. The title is a bit misleading but correct. When coming accross a piece of JavaScript like this foo[“test”] = 1; there is nothing wrong about it. It’s the basic usage scheme of assoziative arrays. Or should i rather say objects? While…

  • Welcome naked!

    Today is CSS Naked Day. Take this chance to visit my site in person (= with your browser). Looking quite okay naked, too ;) css naked day, css

  • A better understanding of JavaScript

    I’ve been working with JavaScript for years. It was my replacement for a server side language when I couldn’t afford to buy web space in the mid-90’s. Still, as the language becomes popular again, I recognized that I did understand the basics but there was much more to the language. digg it, add to delicious…

  • 10 Realistic Steps to a Faster Web Site

    I complained before about bad guides to improve the performance of your website. digg it, add to delicious I’d like to give you a more realistic guide on how to achieve the goal. I have written my master thesis in computer sciences on this topic and will refer to it throughout the guide. 1. Determine…

  • Speed up your page, but how?

    Today I ran accross the blog entry by Marcelo Calbucci, called "Web Developers: Speed up your pages!". It’s a typical example of good idea, bad execution. Most of the points he mentions are really bad practice. He suggests reducing traffic (and therefore loading time) by removing whitespace from the source code, to write all code…

  • Using a Feedback Form for Spam

    Have you ever received weird spam via the feedback form of your site? Something with your own address as sender or with some Mime stuff in the body? Your form is likely to be misused for spamming. How does it work? For PHP, for example, there is the mail function that can be used to…

  • Eclipse Everywhere. Buah.

    It’s been a little quiet lately. This is because I am working on a cute little project that I will be able to present soon. More when the time is ready. There has been rumor lately that Zend (developer of PHP) will release a PHP Framework. This is nothing new, there has been a IDE…

  • Caching of Downloaded Code: Testing Results

    Today I did some experimenting with the caching of downloaded code (or On-Demand Javascript, whatever you want to call it). I’ve set up a small testing suite that currently tests 3 different ways of downloading code: script-tag insertion via DOM, XmlHttpRequest as a GET and XHR as a POST. These are my results for now:…

  • Better code downloading with AJAX

    I’ve been playing with Code downloading (or Javascript on Demand) a little more. Michael Mahemoff pointed me at his great Ajaxpatterns in which he suggests a different solution: if (self.uploadMessages) { // Already exists return; } var head = document.getElementsByTagName(“head”)[0]; var script = document.createElement(‘script’); script.type = ‘text/javascript’; script.src = “upload.js”; head.appendChild(script); Via DOM manipulation a…