New Mac Setup
Transitioning to a new Mac has always been a very smooth experience – the first run setup offers to migrate everything for you and generally it gets everything right so your new Mac comes up looking just like your old one.
Recently I’ve acquired a new MacBook Pro with Retina display and decided that after all these years of migrating everything over I’d set up from scratch. Mostly just to make me consciously choose to reinstall things instead of a heap of cruft coming across automatically which I don’t actually use anymore.
The Semantic CSS Debate
Couple of very interesting articles today on architecture of CSS. Firstly Thierry Koblentz questions the benefits of separation of concerns – advocating a coding style where most style rules map a single classname to a single CSS property.
In complete contrast Ben Darlow argues the importance of semantic meaning, pushing back against techniques like OOCSS and BEM which move away from semantic class names in the name of modularity – generally resulting in long strings of class names on elements.
Uglify/Uglify2, Rickshaw, Requirejs and Minification
If you have:
- A javascript project using require.js
- Which is optimised using r.js
- Includes Rickshaw or any other library that uses the prototype class system
Then you are very likely here because you’re trying to enable JavaScript optimization (minification) and finding that suddenly stuff breaks.
The problem is that the prototype class system allows overriding methods to call the original method by adding a $super as the first parameter to the function. From the prototype docs:
Automation and Selecting Web Hosts
One of the biggest challenges with selecting a web host is that it’s very difficult to determine the quality of a provider without actually setting everything up and seeing how it goes for a while. Generally that means that you either wind up avoiding the very low cost providers out of fear they won’t be reliable and possibly paying too much, or spending a lot of time and effort setting up with a provider only to then discover they’re unreliable or the performance isn’t as good as you expected.
JavaScript Drag and Drop Events
Note to self: when you next need to handle drag and drop events in javascript, just use jquery.event.drag from ThreeDubMedia. Simple jquery based API and automatically handles the most annoying part of javascript drag handlers – dealing with cases where the user starts dragging inside an element, drags right out of the element and then releases the mouse.
Injecting Stubs/Mocks into Tests with Require.js
I’ve recently embarked on a fairly complex new application, a large part of which is a webapp written in JavaScript. The application uses require.js to handle modules and loading of dependencies and we want to be able to unit test our JavaScript.
In order to test specific pieces of the application, we want to be able to inject stubs or mocks into the module being tested. For example, if we had a module:
Importing an ant buildfile multiple times
According to the ant documentation:
It is possible to include the same file more than once by using different prefixes, it is not possible to import the same file more than once.
Unfortunately, it turns out this isn’t _quite _true. In most cases, ant will indeed ignore a request to import a file for the second time, so:
<import>
<file name="utils.xml"/>
<file name="utils.xml"/>
</import>
will only import utils.xml once. This is true even if there’s a chain of files being imported (so A imports B and C, then B imports C as well, C will only be imported once).
Ant Dependencies Running Twice
Most people believe that ant will only ever execute a target once per execution of ant. So if we have targets A, B, C and D, where A depends on B and C and C and D both depend on D.
<target name="A" dependencies="B, C"/>
<target name="B" dependencies="D"/>
<target name="C" dependencies="D"/>
<target name="D"/>
When we run ‘ant A’, we expect each task to execute once, D first, then B and C, ending with A. Since there is no dependency between B and C, they may execute in any order, so we might also get D, C, B, A. All pretty straight forward.
Doctypes, Compatibility Modes, Charsets and Fonts
This information is all covered in much more detail elsewhere on the web but for my own future reference, here’s a primer on doctypes, compatibility modes, charsets and fonts which was required to explain why certain Chinese characters weren’t showing up in IE8. Of course the best answer is that you need to have the East Asian Font pack installed and then it just works (usually) but this tends to be useful background and saves “server side” folks from a number of gotchas.
Media Release or Bug Report?
Ah Apple maps, ever the source of a good sensationalist headline. This time the Victorian police have warned people not to use Apple Maps to get to Mildura. This is definitely a bug with Apple maps, no question it should be and has been fixed. What’s interesting though is that the Victorian police thought it would be easier to attempt to notify every iOS 6 user about the problem via the media and get them to use an alternate mapping application than it would be to call Apple and get them to fix the source data.
Brawling on a Plane
From Straights Times:
A flier aboard Sunday’s Swiss airline flight – a 57-year-old Chinese man […] felt disturbed during his meal when the passenger in front of him reclined his chair.[…]
“The older of the two felt disturbed during his dinner. When the younger did not respond to his protests, he hit him on the head with the flat of his hand. It was a real slap,” said the guide, Ms Valerie Sprenger.
Demystifying Doubles: Consistent Inaccuracy
Of all the data types, double is probably one of the most misunderstood. A huge amount of folk lore has been built up around it to help protect developers from falling into its many pitfalls. Lately I’ve done a lot of work replacing usage of BigDecimal with double and learnt a lot about where those pitfalls are and how the folk lore can be misleading.
The great challenge with double is that it has a degree of inaccuracy because of the way the number is actually stored. For example, the number 2983792734924.2293 actually winds up being stored as 2983792734924.2295, a tiny difference but with far reaching consequences. All of the folk lore around doubles is designed to deal with this potential for inaccuracy.