Arjan

This user hasn't shared any biographical information

Homepage: http://www.avoid.org


Posts by Arjan

Apache “rewrite rule” for REST API

Here’s how you can configure your Apache webserver for a REST API, without using rewrite rules (thus: you don’t need the rewrite engine). Simply add the following line to your <VirtualHost>:

AliasMatch ^/api/rest/v1/(.*)$ /var/www/[mywebsite]/htdocs/api/rest/v1/index.php

In index.php, you can read the parameters like so:

<?php
   $path = preg_replace('~^/rest/v1/~', '', $_SERVER['SCRIPT_NAME']);
   $parts = More >

Javascript: Add URL parameter

Here’s a handy function for adding a new parameter to a URL:

function addUrlParam(param, value)
{
   var url = location.href;
   if (location.search.indexOf(param) != -1) return url;
   var hash = location.hash, sep = url.indexOf('?') == -1 ? '?' : '&';
   return url.replace(hash,'') + sep + encodeURIComponent(param) + (value ? '=' + encodeURIComponent(value) More >
quoted-printable

Hotmail breaks some utf-8 email headers

Hotmail has a bad habit of breaking some email headers, when those headers are utf8-encoded. Campaign Monitor describes it in detail. After some testing, I found out that the problem only occurs with relatively long headers. For example, an email with (random) subject “婰婜孲 訬軗郲, 榃痯痻 熿熼燛 鷢黳鼶 誙 慛慖 More >

firefox

SynoExt add-on for Firefox 4, 5 and 6

The SynoExt add-on for Firefox is great for people who have a Synology DiskStation: downloading torrents on the NAS straight from the browser. Too bad the extension isn’t being maintained, and is now incompatible with new Firefox versions (everything newer than 3.6 won’t work). Turns out that there is a very More >

logo-ie9

Slow/crashing IE9, blank screens

At work, I am running Windows 7 (64-bit) on a Dell Optiplex 780 PC. When Internet Explorer 9 was released, I installed the 64-bit version on this PC. Right from the start IE9 was unbearably slow, pages didn’t load, or only showed after you moved the mouse (it reminded me More >

Javascript addClass/removeClass functions

While looking for compact Javascript addClass and removeClass functions, I stumbled upon http://snipplr.com/view/3561/addclass-removeclass-hasclass/.

This code allows for a few optimizations:

  • The ‘match’ method is deprecated, ‘test’ should be used instead.
  • The ‘addClass’ function references a non-existing ‘this’ object.
  • The ‘removeClass’ function declares a new variable ‘reg’, which is unnecessary.
  • The ‘removeClass’ function doesn’t handle multiple More >
php-logo

PHP: Determine the Quarter for a timestamp

PHP’s date and strftime functions are great for retreiving date-related info formatting them. The only thing missing is a way to determine the quarter (Q1-Q4) for a timestamp. Here’s a very short function that will return the quarter for a timestamp:

/**
 * Return the quarter for a timestamp.
 * @returns More >
php-logo

PHP: Replace \u characters in json string

In PHP, if you JSON-encode a string that contains accented characters, the result contains unicode sequences (for example: \u00e9 represents the é character).

<?php
$string = 'åbcdéfg';
print json_encode($string) . "\n";
?>

Running this gives the following output:

"\u005e5bcd\u00e9fg"

If you want to replace the unicode sequences back to their character representation, here’s what More >