jQuery – change tag name

Obviously, the tagName of an element is readonly – however, you can fake it with a little trickery. Just swapping with replaceWith and copying over the product of .html() won’t get data or events. Here’s an ugly little hack that should do the trick:

POC: http://jsfiddle.net/moagrius/3TRtc/1/ Note that the clone() isn’t necessary in all […]

MySQL – Select conditional boolean expression

And uncommon but useful feature of MySQL includes selecting the results of a conditional or boolean expression. E.g., say you have a Users table where you’re tracking if the user is actually logged in, and whether he wants to be shown as logged in, but don’t want to show both values in the response. You […]

PHP – seriously simple Router

/UPDATE I’ve come to prefer (the very similar) RegexRouter. I’m increasingly uncomfortable with the string replacement in the route method. My upshot of PHP routers (inspired by the various micro-frameworks, like Slim, Silex, F3, Laravel, Tonic, Flight, Klein, etc).

Usage…

Android – tiled MapView (similar to iOS CATiledLayer)

Of the six Android apps I’ve published this year, 5 have required a tiled map view component that wasn’t appropriate for the standard Google MapView or OSMDroid… I needed not only a lot more customization than is currently available with either of those, but they were at higher detail-levels than is possible for accurate GPS […]

JavaScript – remove multiple elements from an array

While you can always .filter() an array to remove unwanted elements, here’s a little sugar to remove all elements that evaluate truthily when compared to any argument passed:

Usage:

POC: http://jsfiddle.net/moagrius/yssfv/ Non-polluting:

JavaScript – splice array on multiple indices (multisplice)

Managing multiple splices in a loop can get confusing, as the position of each element changes after each splice operation. Here’s a little extension to help manage that:

The trick is in the call to sort() and the reduction of the index by the iteration count, which updates the originally passed index to match […]

JavaScript – separate (split) array

I often have a list from the server that I need to split into 2 separate arrays. For example, all options that are enabled and all that are not. Here’s a little extension to handle that. Takes a single callback as an argument, with map-style params (value, index, array) – if that iterated callback returns […]

ActionScript – using the Factory Pattern for Display Objects (ViewFactory)

Instantiating a Display Object is a fairly heavy lift. Usually this is negligible, but when dealing with particle or fluid effects, it can add up. Here’s one implementation of the Factory pattern used with Display Objects, to minimize the total number created – each Display Object would then have it’s visible properties and behaviors updated. […]

MySQL – compare dates

Values within the last 5 minutes:

Values older than 1 month:

PHP from command line

This under-appreciated feature has a couple upsides: 1) speed, 2) debug – it prints (or echos) as it processes, so you can easily break or debug to a particular line or, for example, in a loop iteration when running through a mysql resultset. Very simple use as well. On windows, just open cmd and input: […]