isNaN

may 6 , 2010

So, null is not an object though sometimes null is a Number.


    isNaN( null ); // false
    null === NaN; // false
    null == NaN; // false

isNaN converts null to number.


  Number( null ); // 0

But WTF. :) - @oleg008


syntax highlighting serverside with google prettyfy

may 6 , 2010

This is much more awesome. I have to thank the guys at HowToNode.org for the idea in thier WheatJS static site blog engine. Essentially, it all boils down to running the rather awesome Google Code Prettyfy serverside.

The only remaining problem with the syntax highlighting is now nested <code> elements have to be escaped to display correctly in the final render.


    // replace the raw code blocks with prettyfied html
    t = t.replace(/&lt;code&gt;[^&lt;]+&lt;\/code&gt;/g, function(code) {
        return prettyfy(code.match(/&lt;code&gt;([\s\S]+)&lt;\/code&gt;/)[1]);
    });    

Perhaps, in the future, a quick routine to fetch only the root code elements rather than blinding fetching all of them. Problem: more solved than before!


global scope mindtricks

apr 6 , 2010

An update by @deadlyicon on the previous post.

This is just a really silly way of saying this:


    Function.prototype.call.apply(function (a) {return a}, [1,2])
    // 2

If this still seems weird to you. Consider this:


    function logThisAndArgs() { 
        console.log(this, arguments); 
    };
    Function.prototype.call.apply(logThisAndArgs, [{'some':'object'},1,2,3,4])
    // logs -> Object { some="object"} [1, 2, 3, 4]

Now this!


    Function.prototype.call.call(logThisAndArgs, {'some':'object'},1,2,3,4)
    // logs -> Object { some="object"} [1, 2, 3, 4]

express js gotcha

apr 5 , 2010

Less of a wtf and more of a gotcha. In ExpressJS. you can serve static files from a /public directory with this simple directive in your configure block:


    configure(function() {
        set("root", __dirname);  
        // allow static file serving from public directory
        use(Static); 
    });

But be careful! This sets a the path to be /public/app.css rather than /app.css. More background here.


Fork me on GitHub