This is a great function for sorting small multi-dimensional arrays based on a value in the nested array.
Tip: a lot of folks seem to think that starting a CSS class with a number is impossible. They are wrong. You can start your classes with numbers if you really want to, but you have to use a special syntax in the actual CSS. For instance:
<div class="404">No love!</div>
In the CSS you would target this div like so:
.\34 04 {
/* styling here */
}
The weirdness at the beginning of the class name is CSS syntax for an escaped UTF-8 character code. The backslash tells CSS that we’re entering into a hexadecimal character code, and the space terminates the code (and is thus discarded). Sure, it’s illegible, but at least its possible for those scenarios when you absolutely have to start your classname with a number. The CSS codes for numbers range from \30 (zero) to \39 (nine).
Tip: if you have a custom array sorting function in Javascript that’s performing right in Firefox but not in Safari, you may need to change what you’re returning. For instance, returning 0 (use same order between first and second element) by default will typically work in Firefox, but for Safari to get the ordering right you’ll need to return a negative number (first item should be sorted ahead) by default.
I have no idea why this is true, but if you’re having issues with Webkit’s Array.sort() functionality that may be the problem. I discovered this trying to sort an array of <img> elements alphabetically by their alt attribute like so (example is using Mootools):
var links = $$('.sometarget img');
links.sort(function(first, second) {
var firstAlt = first.getElement('img').get('alt');
var secondAlt = second.getElement('img').get('alt');
var temp = new Array(firstAlt, secondAlt);
temp.sort();
if (temp[0] == firstAlt) {
return -1;
} else {
return 1;
}
});
Returning 0 worked great in Firefox, but to get it working in Safari, too, I had to switch to returning -1 by default.
Easy to follow setup for a great local testing environment using MAMP and VirtualHostX. Definitely necessary for anyone coding websites on the Mac.
I found this some time ago, but it deserves sharing again. A reference to mod_rewrite RewriteCond variables that says exactly what the variables contain (along with how to find out for yourself if you’ve got a server that’s behaving funny). This is a must-read for anyone who has wondered why the heck their mod_rewrite rules were failing.
Astonishingly useful looking plugin for turning WordPress into a CMS. Allows adding arbitrary custom fields to posts or pages, for easy creation of custom content types.
Fantastic little tip for solving a classic time-waster: the voice mail automated message. Sounds like it works with just about every major cell carrier as long as you listen to what happens in between keypresses.
Fantastic utility for anyone developing an ExpressionEngine site; solves the age-old problem of “what did I name that custom field again?”
Tip: When compiling an external framework like JSCocoa for inclusion in a bundle, make sure to change the Installation Directory in the framework’s target to @loader_path/../Frameworks. This causes Objective-C to look for the framework in your bundle path instead of the application path or the standard framework locations.
(If you are working on a full application instead of a bundle, you can use @executable_path/../Frameworks instead.)
Some great solutions to niggling Photoshop and Illustrator problems; the tip about masking effects was one that I’ve struggled with a lot without realizing there was such a simple solution.
A beautiful slideshow module for Mootools; multiple transitions and easy loading of images.
Tip: when adding a number to the end of a string in Python, you can surround the number with backticks in order to automatically convert it to a string (rather than using str()). For example:
num = 10
my_string += `num`
Incidentally, I learned this from Oliver Crow’s article on Efficient String Concatenation in Python, which is a fantastic resource for anyone curious about the best way to combine strings in Python.
Allows you to compress Javascript and CSS for an ExpressionEngine site on the fly. Very handy for switching from development to live site and back again easily, although it unfortunately uses Minify rather than YUI Compressor.