May 2012
2 posts
1 tag
May 10th
2 tags
Symfony2 ESI error: File name too long
We recently came across a strange, intermittent error at OpenSky: (36)File name too long: Cannot map GET /_internal… HTTP/1.1 to file We use Varnish to cache large sections of our pages that include follow/unfollow buttons. If the user is following a certain curator we show the unfollow button, otherwise we show the follow button. Our render tag looked like this: {% render...
May 9th
1 note
April 2012
3 posts
1 tag
The HTML5 placeholder attribute is not a... →
A good reminder from Roger Johansson. I admit I’ve been guilty of this in the past…
Apr 25th
1 tag
Type Matters
json_encode(array()) --> [] json_encode((object) array()) --> {}
Apr 11th
1 note
2 tags
Hello Spork! (aka "Forking PHP...")
A few months ago I was tasked with speeding up the upload of assets to the OpenSky CDN, which was taking a few minutes each deploy. I ended up dividing the upload into multiple processes using pcntl_fork() and bringing the total time of the upload down to a matter of seconds. Since then I’ve been working on wrapping some of the complexities of working with a parent and child processes into...
Apr 10th
1 note
March 2012
4 posts
1 tag
jQuery Events: Stop (Mis)Using Return False →
If you’re like me, this kind of rule doesn’t stick until there’s some meat behind it. Here is that meat. Thanks for the tip, NiKo!
Mar 17th
1 note
1 tag
I ♥ Event Delegation
jQuery event delegation is one of the coolest things since way cooler than sliced bread. This new hotness allows you to listen for an event farther up the DOM than where that event is triggered. If you understand event bubbling, you should be able to grok this fairly quickly. It starts getting interesting when you look at the implications of adding this tool to your toolkit. Let’s look...
Mar 16th
5 notes
2 tags
If you need to be able to tell others in the business when they can expect cached pages to refresh: $response->setPublic(); $response->setExpires(new \DateTime(sprintf('+%d seconds', 300 - time() % 300)));
Mar 15th
2 tags
$response->isNotModified($request)
This is one of my favorite methods in all of Symfony2 and it’s buried in the docs. Take a moment to glory in its simplicity: public function someHeavyAction(Widget $widget, Request $request) { $response = new Response(); $response->setLastModified($widget->getUpdatedAt()); if ($response->isNotModified($request)) { return $response; } // do some heavy...
Mar 12th
1 note
February 2012
1 post
2 tags
Faster PHPUnit
I made a simple optimization to the test suite at OpenSky over the weekend and we are reaping big benefits. The premise is pretty straight forward. We use the setUp() method to create a lot of mock objects through our test suite. If these are allowed to accumulate they end up wasting a lot of space and slowing down your suite. Luckily there is also a tearDown() method you can use to cleanup, and...
Feb 22nd
January 2012
2 posts
2 tags
Symfony2 Security Voters
I answered this question on StackOverflow today that is probably worth repeating here. The poster was asking how to implement subscription-based authorization logic in Symfony2. I imagine he models his problem something like this: class Subscription { const SECURED_AREA_FOO = 'FOO'; const SECURED_AREA_BAR = 'BAR'; // ... /** @ManyToOne(targetEntity="User",...
Jan 17th
10 notes
1 tag
Twig Node Visitors (Part 2)
This is the second in a series of articles on Twig node visitors. Please read part one first. Node visitors can be used for any number of things. The Twig_NodeVisitorInterface interface itself is just three methods: interface Twig_NodeVisitorInterface { /** * @return Twig_NodeInterface The modified node */ function enterNode(Twig_NodeInterface $node, Twig_Environment...
Jan 7th
2 notes
November 2011
1 post
1 tag
Getting Twiggy With It: Node Visitors
I am going to write about node visitors: one of the more obscure but powerful concepts in Twig. To help make sense of it I will be using a simple, real world example. At OpenSky we recently added a basic CMS to our site that allows us to make edits to text without going through the hassle of editing a template and redeploying the entire codebase. We added a module to our admin that manages these...
Nov 30th
3 notes
October 2011
1 post
1 tag
Cancer
I’ve been sitting on this for awhile and think I should share now. My wife of 7 years, partner of 10 and mother of my three young children was diagnosed with stage 4 breast cancer a few months ago. It’s been an extremely difficult fact to come to terms with. The diagnosis is serious, but we are very hopeful. She has just finished her third round of chemotherapy and the scans say all...
Oct 18th
9 notes
January 2011
1 post
1 tag
My first passport...
…has expired! I have stamps for these countries: The Bahamas France The Netherlands The British Virgin Islands Japan What will the next 10 years will bring?
Jan 28th
December 2010
1 post
Dec 3rd
October 2010
11 posts
1 tag
Unit Tests, Mocking, and PHPUnit 3.5's new Mock... →
My latest tidbit of testing goodness, this time on the OpenSky engineering blog.
Oct 29th
1 tag
Look Behind the "Feature Veil"
I’ve been thinking about a decision Apple made awhile ago to allow free iOS apps to offer in-app purchases. My recollection of their argument against doing this is that users would be frustrated by downloading a free app only to have to purchase something in-app to get it to work. Around the same time Apple decided to allow free apps to offer in-app purchases, the App Store also began...
Oct 27th
1 tag
Oct 26th
1 tag
Keep a trim autoloader
The symfony 1.4 autoloader works by scanning your PHP class files and remembering where each class and interface is defined, so it can magically load it when needed. This class-to-filename mapping is stored as an array in your application’s cache directory. You can (and should) look at this array by opening this cache file in your text editor from time to...
Oct 24th
1 note
3 tags
My MongoDB slides →
I had a great time talking about MongoDB and the Doctrine ODM at PDXPHP last night. Thanks to ShopIgniter for hosting (and deciding OpenSky is not a competitor — phew!). I’m looking forward to talking about these things more someday.
Oct 20th
1 tag
Oct 19th
The Geek Talk interviews… Me! →
Oct 19th
1 tag
Joining OpenSky →
I blogged about joining OpenSky last week, and about the compatibility of the OpenSky and open source philosophies, as I see them.
Oct 18th
2 tags
RFC: Mocking Fluent Interfaces in PHPUnit
I sent a pair of pull requests to Sebastian this morning for a very simple change that will make mocking fluent interfaces much easier. This is how you might mock a fluent interface using PHPUnit 3.5.1: $mock = $this->getMock('Person'); $mock ->expects($this->any()) ->method('setName') ->will($this->returnValue($mock)); I’ve proposed a new returnSelf() method,...
Oct 18th
2 tags
Oct 18th
2 tags
How to Test a Symfony2 Bundle
The Symfony2 Framework is fully unit tested using PHPUnit. When you create a Symfony2 bundle to share with the community, it’s important that your bundle also be fully unit tested. It’s also important that users be able to run your bundle’s test suite without having to wrap it in a dummy project. This blog post is about how to set that up. PHPUnit Configuration Configuration...
Oct 17th
1 note
July 2010
1 post
2 tags
How to create a Symfony2 templating helper
As you get started with Symfony2 you will probably find yourself getting stuck on some tasks that are second-nature to you when developing in symfony 1. One of these will probably be adding a custom helper to your view layer. Hopefully this quick article will clarify that particular process. Create a helper class In order to work with the Symfony2 view layer your helper class must implement the...
Jul 30th
February 2010
1 post
2 tags
Blog Post Cut Short
Me < Metro < Paris I would like to eat a crepe. What more can I say? That about sums it up! I’m headed to the symfony live training day, bracing myself for the first of three OSS geek-out days. I arrived in Paris yesterday morning after flying nine hours up and over the top of the world, getting nary a wink of sleep. This is my second trip to Paris and my first flying...
Feb 15th
August 2009
1 post
Shifting the Sun
When your father dies, say the Irish, you lose your umbrella against bad weather. May his sun be your light, say the Armenians. When your father dies, say the Welsh, you sink a foot deeper into the earth. May you inherit his light, say the Armenians. When your father dies, say the Canadians, you run out of excuses. May you inherit his sun, say the Armenians. When...
Aug 15th
1 note
July 2009
9 posts
1 tag
How to Spam Twitter in 3 Easy Steps (or, The Death...
Despite the fleeting “spammers perish” event a few days ago, my Twitter profile is still overrun by spammy followers. This is really bugging me. I’ve been forced to switch notifications off, and my stop_jackin_it.php script isn’t working because the /blocks/create API method is broken. This will be the downfall of Twitter if it isn’t contained. So you want to be a...
Jul 29th
2 tags
Doctrine and MySQL integers
I just pasted this somewhere handy for my own reference. It’s the logic Doctrine uses to translate the integer data types you specify in schema.yml into a MySQL data type. If you’ve ever wondered why the length you set on an integer isn’t directly translated to the table definition used in your database, here’s why. For example, the id columns in sfDoctrineGuardPlugin are...
Jul 22nd
1 tag
stop_jackin_it.php
I’ve been getting inundated by followers who appear to be normal people with a healthy number of followers, but have links to xurl.jp spiced throughout their timeline which resolve to… wait for it… porn. I’m sick of it. So I did something about it. I cronned this script on my computer and you should to. It will run a search for the string xurl.jp and block anyone posting...
Jul 20th
2 tags
Symfony: Denote Required Form Fields
You can checkout the full gist for this tutorial here. The symfony form framework separates a form’s presentation and validation into two distinct collections of classes: widgets and validators. For the most part, these two codebases live happily without any knowledge of eachother. When data from the validators needs to be shown in the presentation layer, such as in the case of error...
Jul 18th
2 notes
1 tag
MooTools: Bubbling Controllers
This one’s an oldie but goodie I just pulled out of my tome of a ~/Sites directory. Similar to Aaron Newton’s concept of Events Arbiters, this class fires events for one object on another object, but I’ve applied the bubbling pattern you may be familiar with from native DOM events. Instead of bubbling up a hierarchy of elements, we just bubble up a hierarchy of controllers. ...
Jul 14th
2 tags
MooTools: Ignoring the next click
I’m a big fan of MooTools, as I recently tweeted. I typically try to extend this framework as little as possible, since that can be rabbit hole for me, but this method is just too handy to pass by. The use case I’m working with is distinguishing between a drag/drop interaction and a click interaction on the same element. If you’re dragging an element, the click event will be...
Jul 13th
4 tags
Managing Master and Slave Database Connections...
This is one of those things that should be much easier than it is. Since I started using Doctrine a few months ago, I’ve been impressed with how complete it is, but I can definitely see room for improvement as the project matures. Setting up read and write connections is one of those areas. My challenge was to get the project I’m on ready to be hosted on Amazon EC2, with the help of...
Jul 10th
4 notes
2 tags
Doctrine Timestamps and User Timezones
I recently added a “timezone” dropdown to the user preferences screen on a symfony application currently in development. This simple extension to the sfDoctrineRecord class makes it easy to present times from the database in the current user’s timezone. abstract class myRecord extends sfDoctrineRecord { protected function _get($fieldName, $load = true) { if ($value =...
Jul 6th
1 note
“No one is further from the truth, than the one who has all the answers.”
– Chinese proverb
Jul 1st
June 2009
6 posts
2 tags
svn import: inconsistent newlines
I encountered this error ad nauseum while importing external libraries into my local/offline Subversion repositories: File ‘/foo/bar’ has inconsistent newlines At first I was opening each file in Textmate and then “save as”-ing with Unix newlines. This takes way too much time, so I wrote this little PHP diddy: <?php // Usage: // php smart_svn_import.php ....
Jun 25th
Swan Song
We are travelling north to Cognac today, then back to Paris Sunday night, then flying to Portland on Monday morning. I promise I’ll get some pictures up soon!
Jun 20th
1 tag
Travel Fatigue
The inevitable has happened: travel fatigue officially set in a few days ago. Six weeks away is a long bloody time. Just comprehending that has been an experience in and of itself. We drove from our last place, near Najac, to near Biarritz on Saturday, where we’re staying in an old mill of some sort. The house was built in the 1500’s and is right on a small river. The mill itself has...
Jun 17th
Travelling to the coast today. I’m not sure if I’ll have access to the web down there. If not, I’ll be back in a week!
Jun 13th
1 tag
From the middle of nowhere
I can’t believe my four weeks in Paris went by so fast. But they did, and now we’re holed up in a house 8.5 hours south of Paris, listening to a magnificent thunderstorm outside. First things first. My time at Sensio was very nice. My primary takeaway would have to be shaking hands with everyone at the start of every day. I haven’t experienced this in the states: I saw a lot of...
Jun 8th
2 tags
Two ZendCon proposals
I submitted two 400-character proposals to ZendCon yesterday. Someone else’s symfony Taking on development of a symfony application started by another developer can be a daunting task, especially for those not familiar with the framework. This will be a practical exploration of symfony from the perspective of a developer taking on an existing project. Topics will include getting...
Jun 1st
May 2009
23 posts
1 tag
Finally, a day in Paris
My wife and I finally got a chance to experience Paris in leisurely style yesterday. We started in Île Saint-Louis around lunch time and had a very nice meal with a great view of the back of Notre-Dame and a pleasant breeze off the Seine. After our meal and some coffee we strolled the island while enjoying some ice cream and sorbet, supposedly the best in Paris. We bought some gifts for folks...
May 30th
1 tag
Willy Wonka's Nespresso Factory
My most surreal experience this trip was my trip to the Nespresso store yesterday. When I came up from the Metro I was greeted by the old Opera house, which is gorgeous. I didn’t have the exact address with me, so I checked my iPhone for an available Wi-Fi network. I was able to connect to one called “Google-Guest” and find the store in the maps app. The store itself was like...
May 29th
May 27th
1 tag
Symfony in Concert gets a little attention
I’m happy to report symfony in concert got a little attention yesterday. I sat down with a designer here at Sensio and discussed the forthcoming microsite: something clean that can be built quickly. I think it’s a challenging design because the site is targeted toward two disparate audiences: developers and social organizations. Preparations for symfony live have taken the front seat...
May 26th
1 tag
Ten Days In
Today will be my tenth day in Paris. I’m on the bus now, headed to lovely Clichy and thinking about how unprepared I was for this sort of trip. It’s challenging to be “a stranger in a foreign land,” but of course I would have been naive to expect anything different. I don’t speak the language, for goodness sake! Living in a big city is also an adjustment. I’ve...
May 22nd