Categories
Etc

Dojo’s little gems

I really enjoyed Mitch’s article on YUI Lang’s little gems and thought it might be handy to see how to do the same things with Dojo. Here’s the translation:

Trim

var trimMe = "  trim me please  ";

//YUI 
var trimmed = YAHOO.lang.trim(trimMe);

//Dojo
// - exactly the same
trimmed = dojo.trim(trimMe);

Substitute

var processText = function(key, value) {  
  return value.toUpperCase();  
};  

//YUI
YAHOO.lang.substitute('Hello {world}', { world: 'earth'}, processText); 

// Dojo
// - Named placeholders are prefaced with a $
// - No support for extraValues from Mitch's example
dojo.require("dojo.string"); // not in base distribution
dojo.string.substitute('Hello ${world}', { world: "earth" }, processText);

Later

// YUI 
// - Docs indicate this return type void, which is a timer object?
YAHOO.lang.later(200, foo, "method", [{ data: "bar" }]);

// Dojo
// - No abstraction for timers in Dojo
// - Can use hitch to set calling scope for function
setTimeout(dojo.hitch(foo, "method", { data: "bar" }), 200);
//  or
setInterval(dojo.hitch(foo, "method", { data: "bar" }), 200);

Merge

var defaults = { color: "red", answer: 42 };
var config;

//YUI
config = YAHOO.lang.merge(defaults, { color: "blue" });

//Dojo
// - mixin takes a variable number of arguments
// - Values are written to the first object, hence passing {}
// - Later values have precendence
config = dojo.mixin({}, defaults, { color: "yellow" });
Categories
Etc

SqueezeCenter + Hardy

I upgraded my Ubuntu boxes to 8.04 last night and ran into but one issue: my SlimServer (now SqueezeCenter) would not start. Apparently I’m not the only one with this problem, and solution for now is to jam some more lines into your /etc/apparmor.d/usr.sbin.mysqld

/var/lib/squeezecenter/cache/ r,
/var/lib/squeezecenter/cache/my.cnf r,
/var/lib/squeezecenter/cache/mysql.startup rw,
/var/lib/squeezecenter/cache/mysql-error-log.txt rw,
/var/lib/squeezecenter/cache/squeezecenter-mysql.pid w,
/var/lib/squeezecenter/cache/squeezecenter-mysql.sock w,
/var/lib/squeezecenter/cache/MySQL/ r,
/var/lib/squeezecenter/cache/MySQL/** rwk,

According to the bug report, the installer is fixed in trunk, so with the next release (7.0.1?) this won’t be an issue.

Congrats to the Ubuntu guys for such a seamless upgrade! It was really smooth.

Categories
Etc

That random castle on the island in the Hudson (Bannerman’s)

Bannerman’s Island

There’s this ruined castle on an island just north of Cold Spring that I always wanted to get out and photograph, but never got the chance. However, I found an excellent write-up of what it is (Bannerman’s Island Arsenal), along with some wonderful photos by Shaun O’Boyle (buy here). Definitely worth a read and a look, and possibly a visit if you’re in the area.

Categories
Etc

Making cmd.exe pretty

Ah, finally. After years suffering with Lucida Console or that nasty raster font, there’s a way to switch to a decent monospaced font, Consolas, in the Windows cmd.exe windows.

Categories
Etc

Third

Portishead is finally coming out with a new album, Third. Last.fm has the full album available for a test listen, and you can pre-order it over on Amazon. So far, I really like it, but I think I’m going to wait to see if it becomes available through the MP3 store before diving in.

(via Nelson)