Megan

Megan Trinity

Megan Trinity. She was born last July 10, 2010.

2009: looking back

i wish i have something to write about 2009. it could’ve been a great year for some. it wasn’t for me. i have lost a lot this year. money, hair, weight… some i cannot quantify.

all i have are a few unfinished projects and some unimplemented ideas. i feel like i lost my passion for programming save for learning new technologies. building software? not so much.

i lost my love for photography. knowing that software can trump whatever my camera churns out doesn’t help. photography as i know it ceased to be. at least in my circle.

i lost some blogs. what used to be a good idea – or so it seems in the middle of the night – is now such a crap i can’t even begin to think about. actually, lost half of made-for-adsense blogs i can no longer maintain.

also, i lost something i never had.

i will be marching to the new year with a new set of goals. hopefully, i will have more success in the coming year so i won’t feel like such a lulz.

clock says 3:45AM. guess it’s time to sleep.

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.

JavaScript:
  1. Array.each = function(a, fn){
  2.     for(var i=0; i <a.length; i++){
  3.         fn(a[i]);
  4.     }
  5. };
  6.  
  7. Array.prototype.each = function(fn){
  8.     Array.each(this,fn);
  9. };
  10.  
  11. Array.collect = function(a, fn){
  12.     var new_array = new Array();
  13.     a.each(function(e){
  14.         new_array.push(fn(e));
  15.     });
  16.     return new_array;
  17. };
  18.  
  19. Array.prototype.collect = function(fn){
  20.     return Array.collect(this, fn);
  21. };
  22.  
  23. Array.inject = function(a, init, fn){
  24.     a.each(function(e){
  25.         init = fn(init, e)
  26.     });
  27.     return init;
  28. };
  29.  
  30. Array.prototype.inject = function(init, fn){
  31.     return Array.inject(this, init, fn);
  32. };
  33.  
  34. Array.detect = function(a, fn){
  35.     for(var i=0; i <a.length; i++){
  36.         if(fn(a[i])){
  37.             return a[i];
  38.         }
  39.     }
  40. };
  41.  
  42. Array.prototype.detect = function(fn){
  43.     return Array.detect(this, fn);
  44. };
  45.  
  46. Array.select = function(a, fn){
  47.     var new_array = new Array();
  48.     a.each(function(e){
  49.         if(fn(e)){
  50.             new_array.push(e);
  51.         }
  52.     });
  53.     return new_array;
  54. };
  55.  
  56. Array.prototype.select = function(fn){
  57.     return Array.select(this, fn);
  58. };
  59.  
  60. Array.reject = function(a, fn){
  61.     return a.select(function(e){
  62.         return (!fn(e));   
  63.     });
  64. };
  65.  
  66. Array.prototype.reject = function(fn){
  67.     return Array.reject(this,fn);
  68. };
  69.  
  70. Array.reduce = Array.inject;
  71. Array.prototype.reduce = Array.prototype.inject;
  72. Array.map = Array.collect;
  73. Array.prototype.map = Array.prototype.collect;

Use it like:

JavaScript:
  1. >>> var a = [1,2,3,4];
  2. >>> a.reduce(0, function(x,y){ return (x+y); });
  3. >>> 10

Basically, almost all functions are built on top of Array.each so I'm not sure how fast it'll go.

Happy hacking.

updated sideblog for WP 2.8

In the process of committing updated code for WP 2.8 to wordpress subversion repository. Due to changes in rendering multiple widgets, version 6.0 of Sideblog breaks backward compatibility. Additional work can be done to make it so but in the meantime to address the needs of those who have already upgraded their wordpress to 2.8, this version will suffice.

To upgrade, I suggest deactivating the plugin and go through the usual installation process. I have not thoroughly tested (as usual) the code, so any bugs please leave a comment.

Get Sideblog version 6.0 here

url shortener using base 62

Trying to scratch an itch one weekend, I tried to write my own URL shortener service. After all, bit.ly got $2M funding for offering such service so I went ahead and see how hard it is to create one. If you've been doing web development for sometime, this activity is trivial. The only hurdle I have was how to generate those random looking string appended at the end of the domain url. For the lazy there's always Base36 that look like the one tinyurl is using. I wanted mine to resemble is.gd so I wrote my own. Here's one I quickly wrote in ruby.

RUBY:
  1. class B62
  2.   CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split('')
  3.   BASE = 62
  4.   def self.encode(value)
  5.     s = []
  6.     while value >= BASE
  7.       value, rem = value.divmod(BASE)
  8.       s << CHARS[rem]
  9.     end
  10.     s << CHARS[value]
  11.     s.reverse.to_s
  12.   end
  13.    
  14.   def self.decode(str)
  15.     str = str.split('').reverse
  16.     total = 0
  17.     str.each_with_index do |v,k|
  18.       total += (CHARS.index(v) * (BASE ** k))
  19.     end
  20.     total
  21.   end
  22. end

Hope that helps.

Photos from the Red Dot Museum

doorway

sale stuff

I lost my DSLR last christmas vacation in the Philippines so I have to make do with my film cameras. These photo was taken on a lazy sunday afternoon at Red Dot Design Museum. They're having their once a month art market where they sell art-sy stuff. After developing these and the other rolls of film from mid last year, I feel like I won't miss much of my DSLR. I've been shooting on the widest angle most of the time.

Bride at the Door

bride at the door

A silhouette of a lovely bride taken during wedding of my college best buddy in Manila. I was supposed to shoot digital until the letter of invitation arrived. I'm going to play a minor part in the wedding ceremony which would prevent me from lugging a big-ish camera around.

Not owning a digital point-and-shoot, I happily took the Olympus Trip with me. Shot 2 rolls of Lucky Film 100 New which proved to be a disaster. The Luckies was for the sunny beaches I'm going to visit after the event. None of the shops I visited carried my favorite Tri-X or any standard BW film. The Luckies have no match against low light inside the church.

Lesson learned: do not expect to find film at your destination.

lomo effect

sailboats

I haven't tried lomography and probably won't any time soon. This photo was not taken with a lomo camera. I took it using my D40. This was an uninteresting photo straight out of the camera. I was playing with the effects in iPhoto when I notice it looked a lot like the lomo photos I saw in flickr and zooomr.

Gear: Nikon D40, Nikkor 18-200mm f3.5-5.8 VR, iPhoto

some abstract architectural shots

henderson waves support

The gang went to Singapore Henderson Waves to take night shots of the bridge. Problem with the place is that it's always full of people you can't shoot without having another photographer in your frame. With my frustration of getting a decent wide shot, I went closer instead. The bridge's support frame made a good abstract subject.

Gear: Nikon D40, 18-200mm f3.5-5.6 VR

Faces at Esplanade

faces at esplanade

The view of the faces artwork from the inside of Singapore Esplanade. I was taking a rest inside the Esplanade from the searing Singapore heat during the National Day Parade 2008 celebration. I like this better than the one I took outside.

Gear: Olympus Trip 35, Tri-X 400, HC-110

Next Page »