Posts tagged "tip"
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.
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.
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.)
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.
Tip: if Mail.app is autocompleting an out-of-date address for someone you can remove the address from its memory by selecting Window→Previous Recipients, searching the list for the problematic email, and clicking the Remove From List button.
Incredibly handy; incredibly hidden.
Tip: when using Hazel to automatically manage or sort your files, make sure to place your most specific rules first in the list.
For example, I’m monitoring my Downloads folder with Hazel using three rules: “label orange if older than one week”, “label red if older than 10 days”, and “move to Trash if older than two weeks”. The “move to Trash” rule needs to come first, followed by “label red”, and finally “label orange”. Otherwise, every file older than a week triggers “label orange” and Hazel never reaches “label red” or “move to Trash”.