A game of OpenTTD is in progress...

Posted by

FPDF: Calculating the height of a MultiCell

January 11th, 2013

FPDF is a great tool to easily create PDF documents. The automatic line-breaking feature is great, but leaves something to be desired. For instance, if a MultiCell is too tall to fit in the remainder of a page, the element gets split up.

Unfortunately, there is no built-in method to calculate what the height of a MultiCell would be.

One solution to this issue posted on StackOverflow utilizes GetStringWidth() to try and approximate what the height would be. I tried it out, but it doesn’t quite hit the nail on the head. It would produce inaccurate results due to spacing and newline issues. I wanted an exact height, not an estimated guess.

I ended up cloning the MultiCell() function within the FPDF class, gutting it, and re-purposing it to return an accurate height. Every time the function made a call to Cell(), I replaced the call with a line of code to add the height of the Cell to the total height of the MultiCell. I also removed a few things such as any code relating to the border.

Using a conditional statement, I then checked the height of the MultiCell against the remaining space on the page:

$spaceleft =  $pdf->h - $pdf->GetY() - $pdf->bMargin

if ($pdf->GetMultiCellHeight(args) > $spaceleft)


You can get a copy of my function here: https://gist.github.com/4089627. Don’t trust random code on the internet? I wouldn’t either. View the diff against the original MultiCell() function here: http://diffchecker.com/99S1TJ8b.

Posted by

TV show predicts future event! Kinda.

December 30th, 2012


This sort of thing probably happens more frequently than I realise, but…

In this episode of That Mitchell and Webb Look,  they make a joke about sentencing Jimmy Savile to three life sentences (we assume he did something bad). I guess it was funny in 2008 because he was widely regarded as a bit of a saint, hero and generally nice guy.

Now, of course, we know he was a serial child rapist - which basically ruins the joke.

I still find it funny though.

Posted by

Samsung Remote, Comcast Cable Box

November 13th, 2012

clicker-medal.jpgToday I tried programming my Samsung remote control to my Comcast cable box. I was trying to achieve two things: toggle the power and change the channel on the device.

I looked at the user manual for my TV (LNT4061F). Neither Comcast nor Motorola were present under the cable box category. I figured the internet would surely have the answer. The first post I came across firmly asserted that this was not possible:

sorry to tell you but it does not work that way.  since the invention of the cable box in the 80’s you cannot use your tv remote anymore.  The best you can do is get a logitech or harmony remote to control the comcast box.    YOu cannot put in any code to your tv remote to work a comcast box it does not work like that.


It boggles my mind that rog286713 was able to achieve the rank of “Bronze Problem Solver” on these forums. From this case, he appears to be the opposite of a problem solver; I’ve never seen someone so wrong in my entire life.

After a little more research, I was able to find the correct answer:

 In the manual for your TV/Remote, if you don’t see Motorola listed as a cable box, look for General Instruments or GI. That is the name of the company Motorola bought a few years ago to get into the cable business.


We need to get andyross promoted to Platinum Problem Solver, because this solved my problem. Code “041″ listed under GI for the Cable Box category worked for my set top box just perfectly.

Posted by

Buying WinRAR

October 31st, 2012

WinRar I’m almost at the end of my 40-day trial now, and I really like WinRAR - so I’ve decided to buy a licence. The question is - where to buy it from?

RARLAB doesn’t make it easy. They have countless “dealers” in many countries across several continents. For each country, the dealers are broken down into “Distributors” and “Resellers”. I can’t actually count them all because RARLAB will only show me dealers local to my own continent (IP geolocation magic).

I managed to get a list of dealers in the USA from Google’s cache. The going rate seems to be about $29 USD for a single user (≈ £20 GBP). This seems quite reasonable, but there was no mention of taxes (and I’m sure my bank can’t wait to charge me a hidden foreign transaction fee).

So let’s take a look at the prices from the UK dealers.

Dealer Single User Licence Price
(incl taxes)
Roche GB (Distributor) £27.78
qbs software (Reseller) £28.58
grey matter (Reseller) £28.58
SHI International (Reseller) N/A (MOQ 2000)

It looks like the best deal in the UK is from Roche. It’s not as competitive as the US price, but here comes the bit where this blog post finally becomes blogworthy…

I noticed that Roche uses an ancient piece of eCommerce software called Actinic (specifically, version 10.0.2 according to their catalog blob file). I’ve had several years of commercial experience developing middleware and extensions for Actinic and generally just hacking it to bits. I know this software more intimately than a Mexican knows tacos.

I can tell you that the Actinic version used by Roche is vulnerable to several LFI and information disclosure exploits. It also has a remote diagnostics backdoor which reveals an awful lot of server/software configuration information (and best of all, the username & password are hard-coded and identical across every version). A lot of these problems arise as a result of Actinic’s desire to needlessly upload plain text configuration files within the webserver’s document root. Today, I’ll be probing one of my favourite Actinic configuration files - the discounts file.

Have a little peek yourselves. The discounts file just contains a simple Perl data structure and a checksum on the first line. The checksum is calculated as the sum of the ordinal values of each remaining character within the file - but that’s not the interesting bit. As the name implies, the discounts file defines all of the possible discounts which can be redeemed. These discounts can take many forms, e.g. “Buy X of Y, get Z free” or “X percent off when you spend more than Y”. The most rewarding ones, though, are usually the ones which require coupon codes to activate.

As you may be able to glean from the linked file, there is a 25% discount called “WinRAR Educational Discount” which requires a coupon code to redeem. The coupon is shown here as a series of 32 hexadecimal digits - 70f0befcd7daa8085f10ee9f4911318f.
If you guessed that this is a MD5-hash of the coupon code string - you’re right!

A quick Google search is always a good start when you’re given an unsalted MD5 hash.


Bingo! The coupon code is WINRARED.

Anyway, I’m going to wrap this post up now - but rest assured, I got a fair deal when I bought WinRAR.


Next week: How to buy WinZIP.

Posted by

Ventrilo Throwbacks of the Cult #2(c)

September 9th, 2012
Alex I’m not gonna get 57 tonight now, *sss* God dammit.
Alex Hey what do you know - he’s camping my corpse again!
Alex God dammit.
Alex is upset GOD DAMM͕̩̣ͭͬ̌̾ͩ̐̈́Ā̳͔̙̠̇̔̍̒̾I̴͍̗̥͖̞̞̳̅̄̋ͫĤ̜͔̣̘̝̭̙Ṣ͚̩̣̙̠̣̀̃̓̌͞Ỉ̷̢̡̦̖̍F̶̵̻̠͎̞͙̠̬̩̤͕͉̲͎̣͊ͫ̂̇̈́̀͐̓͋̚̚H͋̑ͣ̊̐̽҉̩͖̭͚͇̯̗̠̜̼̩͞Kͮ̄̃͗̀̏̒͊̒ͭ̿ͤ̏̑ͭ͆͊̎̊͢҉͕̙̘̺̫̘̥͙̘̝̩̣͚ͅT̷̸̨̤̘͉͉͎͓̮̗̭͙̹̀̍ͥ̇͒̍̔̑͋̊ͬ̾͌̍͜͠!!