Exporting PDFs in Illustrator

There are a few common issues with saving PDFs in Adobe Illustrator. I experienced these with CS5 (5.1 specifically) but while looking for a fix I saw reports of the same errors from users with CS2, CS3, CS4, and CS6 as well. Commond errors include: “This file cannot be found.” when trying to save a PDF in Illustrator Saved PDFs coming out blank white or empty with file sizes 500k+ This file cannot be found ...

July 18, 2013 · 2 min · Paul

Assigning variable defaults in PHP

It’d be nice if PHP had a quick Or-Equals expression like Ruby: user ||= User.new but we make do with few slightly less sugary idioms. The standard way if (isset($user)) { $user = new User(); } A bit shorter $user = isset($user) ? $user : new User(); Shorter still This is my preferred way of making sure variables are set. Short and clear. isset($user) || $user = new User(); Expressions with defaults It’s usually best not to treat variable assignments as booleans but in cases like this I think it’s clear enough what’s happening. ...

July 16, 2013 · 1 min · Paul

IE8 select element change event not firing with the keyboard

Change events on select elements don’t fire in IE8 when the user confirms the selection with the enter key until the user clicks elsewhere. If your users are waiting on something in particular to happen after updating the select this is a bit of a problem. Here’s my solution: // jQuery syntax for ease of reading var the_select = $("#my_select"); // this works great for most browsers the_select.change(function() { console.log('changed'); }); // if IE8 if ($.browser.msie && parseInt($.browser.version, 10) <= 8) { // get the keypress event the_select.keypress(function(e) { // if the user pushed enter if(e.keyCode === $.ui.keyCode.ENTER) { // manually trigger the change handler $(this).change() // blur afterwards isn't ideal but // it doesn't work correctly otherwise .blur(); } }); }

July 11, 2013 · 1 min · Paul

Getting a particular superview in Objective-C

If you have, for example, a child view of a UITableViewCell and you need to get the UITableViewCell in question you can quickly do something like: UITableViewCell *cell = (UITableViewCell *)the_view.superview.superview; It works but this code is fragile because it requires that the view heirarchy not change (also things like this usually point to a code organization issue but hey, i’m not here to judge). If we want to be able to add a scrollview in between without editing this method we’ll have to take a different approach. ...

July 11, 2013 · 1 min · Paul

Debugging Javascript with Console

A quick review. Console.log() //how to print a log statement console.log('That thing you expected to happen is now happening!'); //how to break production sites in internet explorer console.log('anything'); //how to log safer function l(str){if(window.console&&console.log){console.log(str);}} l('I can forget this in my code base without breaking anything!'); Console.trace() //how to figure out what's calling what console.trace(); //console.trace example: function a() { console.trace(); } function b() { a(); } function c() { b(); } function d() { b(); } if (Math.random() < 0.5) { c(); } else { d(); } If you copy and paste that console.trace example into the Chrome Console you’ll get a full stack trace like this one: ...

July 9, 2013 · 1 min · Paul