Gadgets, Computers and Nerdy Stuff
Arjan
This user hasn't shared any biographical information
Homepage: http://www.avoid.org
Posts by Arjan
Apache “rewrite rule” for REST API
Apr 8th
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
Mar 17th
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 > Hotmail breaks some utf-8 email headers
Aug 17th
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 >
SynoExt add-on for Firefox 4, 5 and 6
Jun 25th
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 >
Slow/crashing IE9, blank screens
May 26th
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
Mar 18th
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: Determine the Quarter for a timestamp
Feb 3rd
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: Replace \u characters in json string
Jan 10th
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 >
Enable SSH&SCP on DiskStation
Mar 28th
Enabling SSH on a DiskStation is easy. Download and install the Synology “Enable SSH” patch. Install it via the DiskStation manager (via System -> Firmware Update).
Voila: you should now be able to SSH to your DiskStation. But SCP does not work yet. When you try to SCP to the DiskStation, you More >
Properly Mounting DiskStation shares in OSX
Mar 20th
Mounting shares (called “Shared Folders” on the DiskStation) in OSX is very easy. In Finder, click Go -> Connect to Server. Depending on whether your share is available as AFP (Apple Filing Protocol) or SMB (Samba), you enter afp://192.168.1.2 or smb://192.168.1.2 respectively.
Click Connect, then select the shares you want to share. Easy.
However, More >