php usort

Tuesday 02/10/2009  –  Category: Uncategorized  –  2 Comments

I learned about a nifty PHP function that allows you to sort an array with a user-defined comparison function. This is useful if you have an array of database results and need to sort by one element in the result array (normally it would be better to sort with the SQL query but I had a mixed dataset to sort).

This is a bit similar to ranges in Ruby where the objects you're comparing have to be comparable with the <=> operator.

Sample usort with custom function:

 
function cmp($a, $b) {
	if($a["view_order"] == $b["view_order"]) return 0;
	else if($a["view_order"] > $b["view_order"]) return 1;
	else if($a["view_order"] < $b["view_order"]) return -1;
}
 
usort($tab_items, "cmp");
 

Google Latitude

Monday 02/9/2009  –  Category: Uncategorized  –  No Comments

I've been wondering when Google was going to jump on the location-based service bandwagon after seeing apps like Brightkite and Loopt started getting popular when the iPhone came out.

As of now, the following devices are supported:
- Android-powered devices with Maps v3.0 and above. G1 users in the US will be receiving Maps v3.0 in a system update soon.
- Most color BlackBerry devices
- Most Windows Mobile 5.0 and above devices. Note: Some Windows Mobile devices don't support cell-ID location detection.
- Most Symbian S60 devices

No iPhone yet?? I guess I'll have to stay with the web interface (which is a bit clunky within the iGoogle framework IMO). At the very least I'd expect some automatic location detection via IP geocoding...

IE – Expected identifier, string or number

Monday 02/9/2009  –  Category: Uncategorized  –  1 Comment

If you're getting this error, chances are you have an extra comma after a curly brace:

 
a = {
   b: function() { },
   c: function() { },
}
 

Get rid of the trailing comma and your JS error woes will disappear!
(source)

Safari doesn’t read inline css

Monday 02/9/2009  –  Category: Uncategorized  –  No Comments

I'm not sure why I haven't come across this until this past week, but I found out that Safari doesn't render css within style tags outside the head tags.

The workaround is to inject the style into the head with javascript--similar to what Rails' content_for does:

var cssDefinitions = '..my style chunk goes here';
var style = document.createElement('style');'
$(style).html(cssDefinitions);
$('head').append(style);

(jquery code from stackoverflow)

After this things were looking dandy in Safari but now IE was giving a weird "unexpected call to method or property access" error. It turns out that IE doesn't let you add style elements like this. The workaround for IE looks like this:

var styleElement = document.createElement("style");
styleElement.type = “text/css”;
if (styleElement.styleSheet) {
  styleElement.styleSheet.cssText = “a { color: red }”;
} else {
  styleElement.appendChild(document.createTextNode(”a { color: red; }));
}
document.getElementsByTagName(”head”)[0].appendChild(styleElement);
 

source: YUI blog

Server Upgrade

Monday 02/9/2009  –  Category: Uncategorized  –  No Comments

I finally bit the bullet last night and upgraded my Slicehost slice to a 512slice. It's running much zippier now (with much more room to breathe RAM-wise)!

The upgrade process was pretty painless through the admin panel--it took less around ten minutes to do the pre-resize setup and then another few minutes to complete the process. Go Slicehost!

 Page 7 of 15  « First  ... « 5  6  7  8  9 » ...  Last »