Disabling Google Analytics

Google offers a browser plugin to opt out of Analytics tracking. Grab it from http://tools.google.com/dlpage/gaoptout

30 September 2010 · 1 min · 15 words · Shafiq Alibhai

Getting the Current Unix Timestamp

Perl: time PHP: time() Ruby: Time.now.to_i Python: import time int(time.time()) Java: long epoch = System.currentTimeMillis() / 1000; C#: epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000; VBScript: DateDiff("s", "01/01/1970 00:00:00", Now()) Erlang: calendar:datetime_to_gregorian_seconds(calendar:now_to_universal_time(now())) - 719528*24*3600. MySQL: SELECT unix_timestamp(now()) PostgreSQL: SELECT extract(epoch FROM now()); Oracle: SELECT (SYSDATE - TO_DATE('01-01-1970', 'DD-MM-YYYY')) * 24 * 60 * 60 FROM DUAL SQL Server: SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE()) JavaScript: Math.round(new Date().getTime() / 1000) Bash: date +%s PowerShell: Get-Date -UFormat "%s"

30 September 2010 · 1 min · 75 words · Shafiq Alibhai

Database Integration -- Points to Keep in Mind

Have a single authoritative source for your schema. Everyone should know where the official schema lives. You should be able to walk up to a fresh machine, pull from source control, build, and run a simple tool to set up the database. Ideally the build process handles it automatically. Version your database. The goal is to propagate changes from development to test to production in a controlled way. You should also be able to recreate the database at any point in time. If someone reports a bug in build 20100612.1, you need to reproduce the exact database state from that build.

18 September 2010 · 1 min · 101 words · Shafiq Alibhai

Getting System Load in Perl

Use qx() to capture the output of uptime and parse the load averages: # 1-minute load average my $load1 = qx(uptime | awk -F "load average: " '{ print $2 }' | cut -d, -f1); # 5-minute load average my $load5 = qx(uptime | awk -F "load average: " '{ print $2 }' | cut -d, -f2); # 15-minute load average my $load15 = qx(uptime | awk -F "load average: " '{ print $2 }' | cut -d, -f3); Note: use qx() not exec() – exec replaces the current process and doesn’t return.

7 September 2010 · 1 min · 93 words · Shafiq Alibhai

Gearman Perl "syswrite on an undefined value" Error

If you get this error when running Gearman client code: Can't call method "syswrite" on an undefined value at /usr/local/share/perl/5.10.1/Gearman/Taskset.pm line 202. The fix is to specify the port explicitly. Change: $client->job_servers('127.0.0.1'); To: $client->job_servers('127.0.0.1:4730');

31 August 2010 · 1 min · 34 words · Shafiq Alibhai

Distributing Work with Gearman and Perl

I’ve been playing with Gearman over the past few weeks and I’m impressed by how little friction there is between the idea of distributing work across machines and actually making it happen. The Perl module, Gearman::Client and Gearman::Worker, is straightforward enough that you can have a client and a worker talking to each other through a job server in under an hour. The basic model is simple. You have a client that submits jobs, a worker that performs them, and a job server sitting in the middle dispatching work to whichever worker is free. The client and worker can be written in different languages, run on different machines, and you don’t need to worry about the networking yourself — Gearman handles all of that through TCP sockets to the job server. ...

31 August 2010 · 3 min · 506 words · Shafiq Alibhai

Preserving File Permissions When Copying in Linux

Use the -p flag with cp to preserve file permissions: cp -p /aaa/bbb /ccc/ddd

14 June 2010 · 1 min · 14 words · Shafiq Alibhai
Ajax Tabbed Google Search screenshot

Ajax Tabbed Google Search for Typo3

My first Typo3 extension. It’s a front-end plugin that displays a customised Google search engine on your site, using Ajax with tabs for different result types – no page reload needed. You can download it from the Typo3 Forge (link no longer available). The SVN repository was at svn.typo3.org/TYPO3v4/Extensions/ajax_google_search.

13 April 2010 · 1 min · 49 words · Shafiq Alibhai

Typo3 Reference Manuals as a Chrome Extension

My first Google Chrome extension. It’s a collection of Typo3 reference manuals compiled from typo3.org. Useful if you have a slow or unreliable internet connection (looking at you, India), or if you prefer to stay in the browser while searching the Typo3 swx reference manuals. I wanted to publish it on the Chrome Extension Directory, but the file is 19.86 MB and Google has a 10 MB limit. If anyone knows a workaround, let me know. ...

27 March 2010 · 1 min · 84 words · Shafiq Alibhai

SVN revision control – slides

I put together a presentation on Subversion for a class this semester. The slides cover the basics of revision control and why you should be using it for any project with more than one developer. The problem is simple: how do you coordinate code between multiple people without everything falling apart? You could work on the same machine and take turns. You could email files back and forth. You could dump everything on a shared drive. None of these approaches scale past two people, and even then they’re fragile. ...

22 March 2010 · 1 min · 183 words · Shafiq Alibhai