Pragmatism in the real world

Adding Diff syntax highlighting to Sublime Text

My chosen colour scheme for Sublime Text doesn't include support for diff/patch files, so I added my own. To the bottom of my .tmTheme file, I added this just above the closing </array>: <dict> <key>name</key> <string>diff.header</string> <key>scope</key> <string>meta.diff, meta.diff.header</string> <key>settings</key> <dict> <key>foreground</key> <string>#009933</string> </dict> </dict> <dict> <key>name</key> <string>diff.deleted</string> <key>scope</key> <string>markup.deleted</string> <key>settings</key> <dict> <key>foreground</key> <string>#DD5555</string> </dict> </dict> <dict> <key>name</key> <string>diff.inserted</string> <key>scope</key> <string>markup.inserted</string> <key>settings</key> <dict> <key>foreground</key> <string>#3333FF</string> </dict> </dict> <dict> <key>name</key> <string>diff.changed</string> <key>scope</key> <string>markup.changed</string> <key>settings</key> <dict> <key>foreground</key>… continue reading.

Simple logging of ZF2 exceptions

I recently had a problem with a ZF2 based website where users were reporting seeing the error page displayed, but I couldn't reproduce in testing. To find this problem I decided to log every exception to a file so I could then go back and work out what was happening. In a standard ZF2 application, the easiest way to do this is to add a listener to the 'dispatch.error' event and log using ZendLog. To… continue reading.

Notes on embedding fonts in rst2pdf

I wanted to use Helvetica Light in a PDF that I'm creating using rst2pdf and this proved a little tricker than I expected. Note that to use fonts with rst2pdf, you need to install fontconfig using brew: brew install fontconfig Now, on to the problem! In this case, I discovered that setting stdFont: Helvetica-Light or stdFont: HelveticaLight in the style file resulted in Verdana being used in the PDF file! Fortunately, the -v switch to… continue reading.

Setting the umask when using Capistrano

This is one of those posts to remind me how I solved a problem last time! I've recently been using Capistrano for deployment and other remote tasks and it's proving quite useful. One problem I ran into was that the umask was being set to 022 when using Capistrano and 002 when I was ssh'd into the server itself. After a bit of research, I discovered that the secret is to put the umask statement… continue reading.

Minding my own business

After nearly ten fantastic years at Big Room Internet, I have decided to take the jump and run my own business! Having concentrated on project management for the last year or so, I am happy to return to hands-on development. I also intend to provide training and consultancy services. I'm really excited by this new phase of my career. I have created a shiny new company for interesting projects: Nineteen Feet Limited. If you want… continue reading.

Objects in the model layer: Part 2

I previously talked about the terms I use for objects in the model layer and now it's time to put some code on those bones. Note that,as always, all code here is example code and not production-ready. An entity My entities are plain old PHP objects: namespace Book; class Entity { protected $id; protected $author; protected $title; protected $isbn; public function __construct($data = array()) { $this->populate($data); } // Data transfer methods public function populate($data) {… continue reading.

Ideas of March: It's my content and my opinion

If there's one thing Twitter is not good at, it's holding a discussion on something controversial. Sean Coates noted this problem when he said: "I’m not worried about having my opinion disagreed with; I *am* concerned that I will be crucified for something I don’t mean." I suspect this is because you don't have the space to develop an idea on Twitter. It also doesn't help that Twitter is a conversation which means that people… continue reading.

Objects in the model layer

I currently use a very simple set of core objects within my model layer: entities, mappers and service objects. Entities are objects that represent something in my business logic. For example, in my traditional Album's tutorial, the entity would be the object that holds one album. It has properties such as title, artist and date created and methods that are specific to this entity. Mappers know how to save and load an entity from the… continue reading.

Changing the format of a ZendForm DateTime element

If you want to change the format of the value of a DateTime element, the easiest way to do this in your Form class is to do this: $this->add(array( 'name' => 'next_appointment', 'type' => 'ZendFormElementDateTime', 'options' => array( 'label' => 'Next callback time', ), 'attributes' => array( 'min' => '1 Jan 2013, 00:00', ), )); $this->get('next_appointment')->setFormat('j M Y, H:i'); The two things to note: You can't set the format within the array – it has… continue reading.

Improved Sublime Text 2 PHP getter and setter generation

As I've been using Sublime Text 2 for all coding for the last year, I've noticed a significant problem with my simple 'getset' snippet that I created last year: it doesn't handle underscores in property names correctly. I've finally got around to fix it! As with a lot of editors, Sublime Text supports snippets which are essentially text expansions of a short phrase into more text. This snippet creates a getXxx() and setXxx() method from… continue reading.