Skip to content

Instantly share code, notes, and snippets.

@andrewlkho
andrewlkho / gist:9943902
Last active August 29, 2015 13:58
Turn off magic_quotes_gpc by default in PHP

This was originally posted on 2007-03-03 to http://andrewho.co.uk/weblog/magic-quotes-gpc-and-array-map

Juxta over on the TextDrive forum pointed out a good use of PHP's array_map() function that I hadn't thought of which gets around the annoying fact that some hosts set magic_quotes_gpc to on. In short:

if (get_magic_quotes_gpc()) {
    $_GET = array_map('stripslashes', $_GET);

$_POST = array_map('stripslashes', $_POST);

@andrewlkho
andrewlkho / gist:9943921
Last active October 24, 2021 00:28
Lossless JPEG rotation

This was originally posted on 2007-03-17 to http://andrewho.co.uk/weblog/lossless-jpeg-rotation

I've been going through photos from Halfway Hall, and a lot of them have been taken vertically. The Canon camera I use (a compact) has a gravity sensor that can autorotate photos for you as it writes them; the way it does this is by using an EXIF tag which tells you how the image should be oriented. For example, if I take a picture with the camera rotated by 90 degrees:

% identify -format '%[EXIF:Orientation]' ./IMG_1120.JPG

@andrewlkho
andrewlkho / gist:9943964
Last active August 29, 2015 13:58
Installing cgit on a Joyent Shared Accelerator (Solaris)

This was originally posted on 2009-04-16 to http://andrewho.co.uk/weblog/installing-cgit-on-a-joyent-shared-accelerator-solaris

I recently found the time to setup a web frontend to git on my Shared Accelerator. Pretty much all of my data (including work) is under version control so this is useful for those occasions when I'm away from my own computer but want to fetch a file. I went with cgit rather than gitweb because the configuration looked cleaner and more powerful; it also (utterly unscientifically) felt a lot more responsive (it is meant to be, especially

@andrewlkho
andrewlkho / gist:10643479
Created April 14, 2014 12:29
Import SSL certificate for use in msmtp

With the recent [heartbleed][1] SSL vulnerability, FastMail have [updated their SSL certificates][2]. Here's how to download the certificate and convert it into PEM form.

Find out which certificate you need:

% msmtp -a fastmail --tls-certcheck=off --tls-trust-file= --serverinfo

Download the certificate:

% curl -O https://www.digicert.com/CACerts/DigiCertHighAssuranceCA-3.crt
@andrewlkho
andrewlkho / gist:10736577
Last active August 29, 2015 13:59
Debian/PowerBook G4: USB key for an encrypted LVM

This was originally posted on 2009-08-05 to http://andrewho.co.uk/weblog/debian-powerbook-g4-usb-key-for-an-encrypted-lvm

When setting Lenny up on my PowerBook, I wanted some way to encrypt important data on the hard drive. Crucially, this includes the contents of the main PostgreSQL database cluster. With this in mind, using an encrypted LVM seemed to be the obvious way to go and so I went ahead and did this during the initial installation (Debian makes it pretty easy to do). The one downside is that the 16 character alphanumeric password is a little cumbersome to type in every time, so I opted to have a key file stored on a USB key which could be plugged in at boot time to authenticate and unlock the LVM instead. Here's how I did

@andrewlkho
andrewlkho / gist:10736709
Last active August 29, 2015 13:59
Debian/PowerBook G4: Network configuration

This was originally posted on 2009-08-10 to http://andrewho.co.uk/weblog/debian-powerbook-g4-network-configuration

Debian's network configuration is pretty straightforward (make sure you have the package wireless-tools installed). The first thing to note is that on the PowerBook G4, you'll need to extract the Broadcom firmware. You can do this by installing the b43-fwcutter package (it's in the contrib repository) which automatically extracts the firmware in its post-installation "configuration".

I have three scenarios that I need to account for:

@andrewlkho
andrewlkho / gist:10736844
Last active August 29, 2015 13:59
Debian/PowerBook G4: Vodafone PAYG USB modem (K3565)

This was originally posted on 2009-08-11 to http://andrewho.co.uk/weblog/debian-powerbook-g4-vodafone-payg-usb-modem-k3565

I frequently find myself in need of mobile internet, and for this I use a Vodafone PAYG USB modem. It's the best plan in the UK, mostly due to the fact that the bandwidth doesn't run out. I pay £15 for 1 GB, but that 1 GB never expires and given that it'll take me about two years to get through that it's a pretty good deal (I mostly just SSH a terminal out).

The model I bought about a year ago is the Vodafone K3565, which I believe is a rebranded Huawei E160. This device can function in two different "modes": as a

@andrewlkho
andrewlkho / gist:10737771
Created April 15, 2014 14:37
Debian/PowerBook G4: Network install

This was originally posted on 2009-08-04 to http://andrewho.co.uk/weblog/debian-powerbook-g4-network-install

I'm currently in the process of seatting up Debian GNU/Linux (Lenny, the latest stable) on my PowerBook G4 (12-inch; bought circa August 2004 in the UK). I'm going to post a few bits and bobs here both to serve as a reference to myself but also to help anyone else who follows in this endeavour.

The SuperDrive on my PowerBook no longer works, so I had to do a completely network-based install (it also feels a bit cleaner this way). I couldn't place the files on the hard drive for booting as the installer can't boot from HFS+

@andrewlkho
andrewlkho / gist:10737832
Created April 15, 2014 14:38
OpenDNS and BT Openzone

This was originally posted on 2010-04-17 to http://andrewho.co.uk/weblog/opendns-and-bt-openzone

I frequently work in coffee shops, and if I happen to have forgotten to bring my Vodafone USB modem I use the free WiFi, which is run by BT Openzone. Now, I like to use OpenDNS, particularly when I'm not at home. It's significanly faster than both the BT Openzone servers and the Vodafone ones, so it really does make a difference whilst browsing.

The only problem is that in order to login to BT Openzone, you have to visit the domains www.btopenzone.com and my.btopenzone.com which, if you're connecting

@andrewlkho
andrewlkho / gist:10738177
Created April 15, 2014 14:43
Securing authentication in Debian with OPIE

This was originally posted on 2010-08-28 to http://andrewho.co.uk/weblog/securing-authentication-in-debain-with-opie

A lot of the software I use is run on a remote server, and as a consequence I often have a terminal connected to this server. Whilst most of time I log in through my own computer, it often comes up that I need to SSH in using an unknown computer (such as someone else's, or the university computing cluster). I needed to come up with a way that made it easy to get in whilst using my own (secure) computers, but provided an extra layer of security when using potentially insecure terminals. Enter OPIE.