jqtouch
trying out jQTouch again. i remembered when i first got my iphone 3G, i tried to write a better webapp version of my favorite bus schedule app for iphone. i was torn between iUI and jQTouch. being a jQuery fanboy, choosing jQTouch was a no brainer. the animation wasn’t as smooth as a native app but it’s easier to work with. the project? like most of my toys, it’s in limbo.
running out of breath
finally dragged myself to the gym tonight. it’ll be silly for me to expect i could last an hour in a treadmill. i didn’t but i’m still glad to clock in around 40 minutes of combined walking and running plus a little stationary cycling. my back is hurting a bit so i’m hoping it’ll go away in the morning. i guess i’ll start living healthy from now on. no more smokes for me.
micro-blogging
in this age of micro-blogging, you’ll think having your own self-hosted blog is a waste of time and money. after all, you get wider audience using twitter. on the other hand, it’s easier to get your ideas across using a blog. not everything can be squeezed into 140 chars.
committing self to the gym
quite happy that there’s a gym near my place. gotta start doing something to make the bloated feeling i get every time i wake up in the morning. i need all the hand-holding i can get to get through this drastic step. am not aiming for a chiseled abs and all that. i just want to be thinner.
export import content from wordpress.com
helped a friend export contents from a wordpress.com to a self-hosted WP blog today. i’m blown away with the ease of the whole process which if done correctly won’t take more than 10 minutes. kudos to the WP team.
thought about upgrading to snow leopard
I’m supposed to rush to the nearest apple store and buy myself an upgrade, snow leopard, to my macosx. checked some popular apple related sites for software compatibilities. surely enough, some of my installed apps will not run on snow leopard. postponing the upgrade until some smart people figures out a way to run them.
giving YUI some love
working with YUI wasn’t as bad as i thought. managed to survived without the jQuery or prototype magic. somebody should write a book on it – or somebody already did. the sheer size of the docs and the API can overwhelm those trying to evaluate the framework.
ruby-like syntax for javascript array functions
At work, we recently decided to use YUI (Yahoo UI) to generate our user interface. YUI is great. It got almost all the widgets we need. Tabs, tree, carousel... As a result, we have consistent look all throughout. We dump the javascript framework that came with Ruby on Rails and use YUI instead.
Now, here's the problem. If you've use prototype or jQuery, you must be used to using the utility functions these frameworks provide. I go big on jQuery's each function for iterating through arrays and array-like object. Unfortunately, YUI - in version 2.x, at least - does not provide these array functions.
In a course of an hour, I wrote a handy set of functions to get me through. It could've been easier if I just include jQuery since the noConflict function makes it work with any js framework but then I got a mandate to focus on YUI.
-
Array.each = function(a, fn){
-
for(var i=0; i <a.length; i++){
-
fn(a[i]);
-
}
-
};
-
-
Array.prototype.each = function(fn){
-
Array.each(this,fn);
-
};
-
-
Array.collect = function(a, fn){
-
var new_array = new Array();
-
a.each(function(e){
-
new_array.push(fn(e));
-
});
-
return new_array;
-
};
-
-
Array.prototype.collect = function(fn){
-
return Array.collect(this, fn);
-
};
-
-
Array.inject = function(a, init, fn){
-
a.each(function(e){
-
init = fn(init, e);
-
});
-
return init;
-
};
-
-
Array.prototype.inject = function(init, fn){
-
return Array.inject(this, init, fn);
-
};
-
-
Array.detect = function(a, fn){
-
for(var i=0; i <a.length; i++){
-
if(fn(a[i])){
-
return a[i];
-
}
-
}
-
};
-
-
Array.prototype.detect = function(fn){
-
return Array.detect(this, fn);
-
};
-
-
Array.select = function(a, fn){
-
var new_array = new Array();
-
a.each(function(e){
-
if(fn(e)){
-
new_array.push(e);
-
}
-
});
-
return new_array;
-
};
-
-
Array.prototype.select = function(fn){
-
return Array.select(this, fn);
-
};
-
-
Array.reject = function(a, fn){
-
return a.select(function(e){
-
return (!fn(e));
-
});
-
};
-
-
Array.prototype.reject = function(fn){
-
return Array.reject(this,fn);
-
};
-
-
Array.reduce = Array.inject;
-
Array.prototype.reduce = Array.prototype.inject;
-
Array.map = Array.collect;
-
Array.prototype.map = Array.prototype.collect;
Use it like:
-
>>> var a = [1,2,3,4];
-
>>> a.reduce(0, function(x,y){ return (x+y); });
-
>>> 10
Basically, almost all functions are built on top of Array.each so I'm not sure how fast it'll go.
Happy hacking.
starting to like google chrome
google chrome browser has been on my ubuntu-powered netbook since they released the native package. i'm not sure when it supported firefox-like tab navigation but being able to switch using alt-[1-9] did me in. i'll make it a default when it finally support flash.
beautiful code
picked up and started reading the book Beautiful Code. i always try my best to write elegant code. reading the printout of my C code 8 years ago still makes me smile.