jeffsu.com

July 27, 2010

Inception: Spin and Spoiler

Filed under: Personal — Jeff @ 12:14 am

I think I figured out what happens in Inception. In my opinion, this has to be the most brilliant ending I’ve seen (SPOILER ALERT!):

The whole movie was just a dream up until Cobb wakes up on the plane. He looks at everyone as if he just had the weirdest dream of his life. He goes through customs and feels a little nervous (because of his dream) and then meets his father. He spins the top because it reminds him of his dream (or maybe his late wife) and then proceeds to meet his children (ignoring the “totem”) because he knows it was all just a dream and doesn’t care what the outcome was.

Thats my take!

November 21, 2009

JS2 Released!

Filed under: Tech — Jeff @ 2:19 am

Finally, after writing in js2 for almost 2 years, I finally got a chance to open source it. After the 3rd iteration, I think its finally ready for public beta consumption.

Google Code Page

Installation:

sudo gem install js2

You might need to add the gems bin directory to your path.

Here’s a “Hello World” example:

In my.js2

module My.Mixin {
  property friend;
  function helloFriend () {
    alert("Hello " + this.getFriend());
  }
}
 
class My.Base {
  include My.Mixin;  
  function hello () {
    alert("Hello World");
  }
}
 
class My.Concrete extends My.Base {
   function goodByeWorld () {
     alert("Good Bye World!");
   }
}
 
var me = new My.Concrete();
me.goodByWorld();
me.helloWorld();
me.setFriend("Jeff");
me.helloFriend();

Now run (notice the dot for current directory):

js2 .

There are now 3 files in this directory:

my.js
my.js2
classes.js

Include all js files in your header.

November 2, 2009

Shanghai Restaurant Factual Table

Filed under: Personal, Shanghai — Jeff @ 4:13 am

The first Shanghai Factual Table.

October 31, 2009

The Fat Olive

Filed under: Personal, Shanghai — Tags: — Jeff @ 1:55 pm

I’m not sure what the deal is with these places that feel like pretentious is a good thing. I get it… There are some places that just need to be… but some places could probably do better without being so swanky. The
Fat Olive
is a good candidate.

As soon as we walked through the entrance and onto the rooftop sitting area that overlooked PuDong, I immediately felt like it was a seen from Miami Vice. The area is basically an open space flooded with white cushioned chairs and small tables. I could deal with this if it weren’t for the really weird music the DJ was playing that sounded like rambling English over some soft techno beats.

The food was just okay (maybe a little less than okay) and was pretty expensive. 100+rmb for a small cheese platter seemed a little excessive. The bottles of wine actually turned out to be cheaper than the food.

I would recommend going there for a bottle of wine (or a glass of coke… thats just how I roll) on clear Shanghai night (good luck!) to enjoy the excellent scenic view of the city.

October 30, 2009

Incheon Airport

Filed under: Personal — Tags: , — Jeff @ 9:00 am

The Koreans sure can build an airport!

[sthumbs=1|2|3|4,160,2,y,left]

jQuery Click Off Events

Filed under: Tech — Tags: — Jeff @ 8:45 am

I’ve been trying to figure out a good way to get click off events to work in jQuery. So far, I haven’t been able to find a canned solution so I came up with my own crusty one.

At first the solution was to use e.stopPropagation() on the bound element and have the body register a “click” event that would fire off a “clickoff” event on the bound element. The “e.stopPropagation()” would basically prevent the body from firing the if the bound event was clicked on.

This worked okay, but it didn’t quite work in conjunction with other clickoff registrants. The reason was because “e.stopProgatation()” was preventing clickoff to be fired on all the other registrants.

After reading Brandon Aaron’s tutorial on jQuery’s special events, I came up with this:

jQuery.event.special.clickoff = {
  setup: function (data, namespaces) {
    var $this = jQuery(this);
 
    // class static state information for clickoff
    state = jQuery.event.special.clickoff.state;
 
    // get unique id per registration
    var id   = state.idCounter + '';
 
    // store it in data for later use in teardown
    $this.data('clickoffId', id);
 
    // lookups of all registered elements
    state.lookups[id] = this;
 
    // register the clicking on body 
    if (state.idCounter == 0) {
      var body = jQuery('body');
      body.bind('click.clickoffHandler', function (e) {
        // find out which elements were clicked off of
        for (var k in state.lookups) {
          // if the element was not clicked on trigger call clickoff on it
          if (! state.ignores[k]) {
            jQuery.event.trigger('clickoff', null, state.lookups[k], false, null);
          }
        }
 
        // clear out ignores
        state.ignores = {};
      });
    }
 
    // get a uniqueEvent handle the clicking 
    // this is probably not that necessary
    var uniqueEvent = "click.clickoff" + id;
 
    // bind a click event that puts the element in an ignore state 
    // if its clicked on... will be ignored by the body handler
    $this.bind(uniqueEvent, function (e) { state.ignores[id] = true; });
 
    state.idCounter++;
  },
 
  // unbind click event and remove from lookups
  teardown: function (namespaces) {
    state = jQuery.event.special.clickoff.state;
 
    var $this = jQuery(this);
    var id   = $this.data('clickoffId');
    var clickEvent = "click.clickoff" + id;
    $this.unbind(clickEvent);
    delete state.lookups[clickEvent];
  },
 
  state: { idCounter: 0, lookups: {}, ignores: {} }
};
 
// add shortcuts for clickoff
jQuery.fn.extend({
  clickoff: function (fn) {
    if (fn) {
      return jQuery.event.add(this[0], 'clickoff', fn, null);
    } else {
      return jQuery.event.trigger('clickoff', null, this[0], false, null);
    }
  }
});

Basically, I take a hash and store all the registrants and then bind the registrants with a “click” event. When the click is fired, I make sure that the registrant is included in an ignore hash for that particular event.

Hope this helps someone.

PuDong Sky Scrappers in Shanghai

Filed under: Shanghai — Tags: , — Jeff @ 8:29 am

Personally, I think the SWFC looks nice, but the JinMao Tower’s look will probably keep while the SWFC’s might be look as outdated as the Pearl Tower’s.

[simage=19,200,y,left]
[simage=21,200,y,left]

Powered by WordPress