Archive | May, 2009

How To Apply Full CSS Reset on an Arbitrary Selector with Compass

30 May

compassCompass comes with a very handy utility for completely resetting the styling accross all browsers. In the author’s own words on the github wiki:

The Reset module provides mixins that allow you to reset your html so that every element has browser-supplied no styling

The default compass stylesheet comes with this module included, i.e. the @import compass/reset.sass you see at the top, and spits out the reset styles into the global namespace.

But, lets say you have a separate stylesheet that is to be included on a third party domain and that is namespaced under a selector. You can still take advantage of the Compass reset styling through the following method:

@import compass/utilities/general/reset.sass

#hh
  +global-reset

The result is the complete resetting of every child element of your namespace, i.e:

...
  #hh div, #hh span, #hh object, #hh iframe, #hh h1, #hh h2, #hh h3, #hh h4, #hh h5, #hh h6, #hh p,
  #hh pre, #hh a, #hh abbr, #hh acronym, #hh address, #hh code, #hh del, #hh dfn, #hh em, #hh img,
  #hh dl, #hh dt, #hh dd, #hh ol, #hh ul, #hh li, #hh fieldset, #hh form, #hh label, #hh legend, #hh caption, #hh tbody, #hh tfoot, #hh thead, #hh tr {
    margin: 0;
    padding: 0;
    border: 0;
    font-weight: inherit;
    font-style: inherit;
    font-size: 100%;
    font-family: inherit;
    vertical-align: baseline; }

...

Using a Location Proxy for URL Bindings in the Sammy Javascript Framework

25 May

As I hinted in my previous post, the Sammy javascript framework is a great organization layer ontop of javascript heavy apps because it brings web developers back to familiar ground – the URL. But, there are occasions where we don’t want the actual URL in the browser to change, including the hash parameters.

Why? Maybe we don’t want Back-button accessibility, or as in my case, we are running our scripts on a 3rd party domain and we want to minimize our impact.

So, how can we maintain the organization that URLs provide, but prevent the actual URL from changing? Use a proxy!

You can find my fork of the Sammy project here.

Usage

var app = $.sammy(function(){ with(this) {

  // denote that we will be using a location proxy
  use_location_proxy = true;

  get('#/home', function() {
    //... do something
  });

  //...
});

And the corresponding link would look like:

<a onclick="app.setLocation('#/home'); return false;" href="#/home">Home</a>

Even though we are preventing the URL from changing in the browser (with return false), the Sammy framework still activates the ‘#/home’ routing.

Some things to note: if you define use_location_proxy in your application, it will no longer listen to the browser URL. Future versions may have more flexibility with this.

Erlang Supervisor Behavior Gotcha – Worker Init Params

23 May

When starting up a behavior like supervisor, the start_link func looks something like:

start_link() ->
  supervisor:start_link({local, ?MODULE}, ?MODULE, []).

Which in turn calls the initialization callback:

init(_Args) ->
  %% do some stuff.

Notice that the initialization callback takes 1 argument event though the params list (the third parameter) is empty in your start_link func.

So, naturally (am I alone in this?) I assumed that when defining a Child Spec for a Supervisor, the {M, F, A} definition would follow the same pattern:

Childspec = {child1,
            {child1, start, []},
            permanent, brutal_kill, worker, dynamic},
%% ...

But the above definition does not call child1:start/1, where the one parameter is the emtpy list. Instead, the list items are extracted as individual parameters. So {child1, start, [p1, p2, p3]} would call child1:start/3, and {child1, start, []} calls child1:start/0. Just something to look out for if you’re new to erlang and the supervisor behavior like me.

23 May

  • “When a man runs from fatherhood, he’s not really running from responsibility, he’s running from the guilt of a mediocre life”http://bit.ly/ #
  • last tweet’s link: http://bit.ly/gU6y4 #

Powered by Twitter Tools.

22 May

  • Voxtrot: Blood Red Blood http://dora.fm/Xu #dora #
  • when my commit messages turn into grunts, it’s time to take a break. latest commit message: “blah” #

Powered by Twitter Tools.

21 May

Powered by Twitter Tools.

20 May

  • The twitter plugin for adium makes twitter feel like a giant global IRC channel. this is a good thing #
  • The Shins: So Says I http://dora.fm/XU #dora #
  • spending some quality time with The Soft Bulletin #
  • Trying to find by excuse to get out and walk on this beautiful day. Lunch at pei wei #
  • it’s time for a major life change. I’ve decided to move from a dark vim theme to a light one #
  • The Magic Numbers: Love Me Like You http://dora.fm/x7 #dora #

Powered by Twitter Tools.

19 May

  • This Sammy project is piquing my interest – lightweight, stateful ajax, plus more. http://bit.ly/5BXFk @sammy_js #
  • trying out the official twitter support in Adium 1.4b #
  • giving @sammy_js a run, going to see if it works well in my workflow #
  • two thumbs up for Twitter in Adium 1.4b — anything that unifies apps wins in my book #
  • just told our Roomba to dock and sleep and it beeped a definitive “no” … it’s the beginning of the end for humankind #
  • keep fighting the good fight phonegap devs http://bit.ly/qDl9G #
  • @rossbates hah, awesome – yeah I swear I’m going to come home one day and see a “KILL ALL HUMANS” pattern in the floor in reply to rossbates #

Powered by Twitter Tools.

The Return of the HREF – The Sammy Javascript Microframework

18 May

Recently, for me at least, it seemed as if Javascript development had (de)volved into:

<a href="#" onclick="Some.module.call(); return false;">Click Me!</a>

Or worse yet, binding event handlers to every anchor on the page with jQuery. That’s so meh if you ask me.

That’s why I’m excited about Sammy by Aaron at http://quirkey.com, a javascript microframework built ontop of jQuery and modeled after the Sinatra microframework for Ruby. On the surface, it’s a simple and convenient way rely on to the href attribute we web developers have become so fond of. Digging deeper, it provides a lightweight, stateful, organized framework to our increasingly prevelant AJAX applications.

Stateful AJAX with Sammy

One of the primary benefits that Sammy provides is that it’s based around event binding to URLs. That means we can do:

<a href="#/blah">Click Me!</a>

and it will be mapped to a Sammy framework event that handles the URL http://mysite.com/#/blah.

Note the hash in the URL that does not reload the entire page, instead (with Sammy) it fires any events bound to the #/blah URL. Why is this important? Firstly, I’m a firm believer that the average web user subconsciously likes to see the URL change whenever they click something on a web page. Secondly, that user can then use the “back” button and remain in the AJAX application you’ve built, possibly undoing the action you’ve just performed (depending on how you coded your app).

The Sammy framework provides everything you need to be able to handle these hash URLs by abstracting RESTful requests ontop of jQuery.

app = $.sammy(function() {
  this.get('/#blah', function() {
    $('.do').something():
    cool();
  });
});

$(function() {
  app.run();
});

Any link to “#/blah” will fire the function you do define that $('.does').something(); cool();

Aaron says it better than I can:

jQuery is probably the fastest, most robust way to abstract basic low-level Javascript functionality that every Javascript devleoper needs. However, it really remains low-level and does not imply any structure or organization for larger scale Javascript applications.

The key here is "larger scale" javascript apps. If your app has one or two small javascript effects, then it may not make sense for your app to use Sammy. Just use the onclick attribute or event bindings in your favorite javscript framework. But, if your app works natively without page refreshes, then I strongly recommend using Sammy to organize your AJAX events.

18 May

Powered by Twitter Tools.