Archive for the ‘javascript’ Category

javascript; sending me insane

>>> []
[]
>>> [] == true
false
>>> [] == false
true
>>> [] == []
false
>>> false == false
true

Posted by Matthew on January 19th, 2010

Filed under javascript, programming | No Comments »

array_unique javascript snippet

function array_unique(a)
{
    return a.reduce(function(u, e)
    {
        if(!(e in u))
            u.push(e);

        return u;
    }, []);
}

Posted by Matthew on February 23rd, 2009

Filed under javascript, programming | No Comments »

Javascript map-sort

I’m sure sorting method has a real name, but I’ve had no luck searching for it.
function mapSort(array, mapFunction, sortFunction)
{
    // Store both original value, and transformed value
    var mapData = array.map(function(e)
    {
        return [e, mapFunction(e)];
    });
   
    // Sort the data using the second element of [...]

Posted by Matthew on January 20th, 2009

Filed under javascript, programming | No Comments »

Javascript…

Javascript is both infuriating and awesome at the same time. I don’t think I’ve ever speant so much time tracking down annoying bugs (even compared to PHP), yet at the same time it makes functions like the one below very simple to write.
For reference, the below code returns a `getter` method that we use [...]

Posted by Matthew on March 23rd, 2008

Filed under javascript | No Comments »

Very simple captcha decoding using the Canvas tag

Ever since learning about the canvas tag, I’ve been wanting to try this…. Yes, the captcha I used is amazingly simple to break, but, I doubt I'm smart enough to tackle anything more complicated. Though I feel it still serves a good proof of concept (espcially when combined with Greasemonkey)

Canvas Captcha Results.png (57 [...]

Posted by Matthew on February 10th, 2007

Filed under javascript, programming | No Comments »

Digg: Javascript overload?

The Digg front page (28KB) requires 2 (3?) CSS files and 17 Javascript files to be downloaded before it can be displayed. This shouldn’t be a problem as the files should be cached on the first visit. But I wouldn’t be here writing this if that was the case. It appears that max-age [...]

Posted by Matthew on January 28th, 2006

Filed under javascript, programming | No Comments »