Jason Galea

Coder. Maker. Problem Solver.

Read this first

Building a PDF writer

A PDF file is basically a set of object serialised in a specific format similar to PostScript. Our initial goal is to be able to place text in a PDF by writing the required objects in the correct format but today we’ll just start with the overall layout of the PDF file source.

The first thing we write to the file is the PDF header which consists of the PDF version and 4 binary characters to ensure readers know the file contains binary.

%PDF-1.4
%ÿÿÿÿ

After that we add the objects which will lay out the document. Each object begins with an id followed by a dictionary and an optional stream. We won’t be working with streams this round.

1 0 obj
<<
  /Type /Catalog
  /Pages 2 0 R
>>
endobj

Following the objects we put down the xref. The xref is an index of the objects in the file to help readers locate them quickly (and add a bit more info in PDF files that have been modified).

xref
...

Continue reading →


MongoDB Upgrade 2.4 to 2.6 in Debian

When upgrading to the latest and greatest MongoDB (2.6) the first thing you have to do is run a check on your databases. Specifically the upgrade docs say:

To begin the upgrade procedure, connect a 2.6 mongo shell to your MongoDB 2.4 mongos or mongod and run the db.upgradeCheckAllDBs() to check your data set for compatibility.

Tightly constrained by the box, I wondered how I could install a 2.6 mongo shell on my Debian system without upgrading the whole shebang.. turns out there’s no need.. just download the tar version of MongoDB and run the shell straight from there..

$ curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
$ tar -zxvf mongodb-linux-x86_64-2.6.1.tgz
$ ./mongodb-linux-x86_64-2.6.1/bin/mongo

to run the check, you also need to be using the admin database, so..

> use admin
switched to db admin
> db.upgradeCheckAllDBs()

Checking database mydb1
...

Continue reading →


Believe in yourself

You are right. Whatever you believe to be true, is correct. It is true for you.
Your knowledge of the facts is based in your reality, your experiences, and those are the only truths you can be sure of. Yes, they are a minute sampling of the truth of the world, but they are real. Anything anyone tells you about something you have not seen first hand is a clue, but only a clue, a hint, of what may be true.

Yeh, ok, I’ve had a drink or three tonight.. but they have only relieved me of the burden of believing everything I hear, or read, or see on TV. This is probably temporary. Tomorrow I will wake again and believe I need to do more, be better, smarter, learn more, do things differently. For now, I am not sure that that is so.

Don’t get me wrong, I am positive, and happy. I have a wonderful family, and a great job, but I strive for more. always more. Don’t let your dreams, your...

Continue reading →


How to create PDF documents

Adobe’s Portable Document Format (PDF) files have almost become the standard for preparing well-formatted documents. There are PDF readers/displayers for most web browsers, so there is no real excuse for not providing this kind of formatted document to your users if your web application demands its use. Standardized forms and statistical reports can all be drawn from a web system’s data, so it makes sense to format that data in a common layout. Adam Flaherty

Example uses for dynamically generated PDFs include orders, receipts, invoices, packing slips, event tickets, reports, certificates, booking details and anything else that would benefit from a well supported printable document format that can easily be sent to others and stored for archival purposes.

I created (and continue to develop) Docca as a web service to ease the pain of implementing dynamic PDF files from your web site or...

Continue reading →


Something About Perl

Perl is used extensively all over the world in production, doing the job, all the time. Modern Perl takes the solid base that is Perl5 an implements all the goodness of modern programming practices. Perl has been in intensive use for more than 10 years and there are many examples of it’s use that are very out of date. When searching for Perl references on the ‘net, please make sure you restrict your search to the last 12 months.. there has been extensive progress in recent times.

TMTOWTDI - There’s More Than One Way To Do It

This has it’s detractors and is certainly open to abuse. Other languages have the opposite view and believe in The One True Way. Reasons for this mostly boil down to making things easier to get started, but the real world just isn’t that simple. My problem with this is that my favourite answer as a developer to “Can we…?” is “Yes. We can do anything”. And with Perl...

Continue reading →


Using Catalyst with a Fat Model

Today I’m going to talk about using a fat model in Catalyst. When I started using Catalyst and eventually got my head around all the parts and where they all fit in, the slot for my “business logic” seemed to be in the Controllers and I think that’s a common assumption.

The first thing that got my spidey sense tingling about this approach was when I realised I had multiple Actions with the same code. I’m very, very DRY so that bugged me a lot. Because I was in a Controller my first attempts at fixing this resulted in lots of forwarding between Actions both private and not.. this gets very messy, very quickly.

Ok, so why not regular methods in the Controllers which are called from your Actions? This is a better solution wherever possible but I must admit it makes me feel icky.. a Controller is a place for Actions and for clarity, modularity, etc, I prefer to keep everything else out..

...

Continue reading →