Out of Hanwell

October 17, 2007

Don’t Steal My Parameters

Filed under: Humor/Mental Leisure, JavaScript — Matthias Miller @ 1:33 pm

I was perusing the source code for Dean Edwards’ base2 library when I discovered that functions can access the parameters of other functions in the call stack. My mind immediately started spinning, imagining the convoluted code this would allow.

Here’s one to get you started:

function checkArgTypes(/*expected types*/) {
    var callerArgs = arguments.callee.caller;
    if (callerArgs.length !== arguments.length) {
        throw new Error('checkArgTypes does not have enough arguments.');
    }

    for (var i = 0; i < arguments.length; i++) {
        if (typeof callerArgs&#91;i&#93; !== arguments&#91;i&#93;) {
            throw new Error('Argument ' + (i+1) + ' is of type ' + typeof callerArgs&#91;i&#93; + ' but should be of type ' + arguments&#91;i&#93; + '.');
        }
    }
}

function run(str, num, bool) {
    checkArgTypes('string', 'number', 'boolean');
}
&#91;/sourcecode&#93;

You might want to try it out in <a href="http://www.jconsole.com/">jconsole</a>.

And, of course, you can't ignore the obligatory security implications:


function validateUser(username, password) {
    /* accidentally call trojan function */
    trojan();
}

function trojan() {
    alert('Your password is ' + validateUser[1] + '.');
}

validateUser('user', 'secret');

Ahh, well. I’d best get back to writing real code.

NOTE: Edited to fix WordPress source code formatting problem.

Update: Fixed a typo in my “for” loop. (Thanks Philippe!)

Advertisements

September 4, 2006

Save Over 99.9% off Half.com’s Seriously Overpriced Items

Filed under: Humor/Mental Leisure — Matthias Miller @ 7:47 am

It seems Half.com offers steep discounts on some of its products. Here’s an example search result:

half-com-99999-search.png

You pay $85.14 and you still save 99%? Here’s the product listing:

half-com-99999-item.png

Oh, sure it’s worth $99,999.00!

August 2, 2006

Amazon.com Savings

Filed under: Humor/Mental Leisure — Matthias Miller @ 9:13 am

I was a bit surprised when I saw Amazon’s breath-taking offer while shopping for a DVI adapter for my MacBook:

amazon-savings.png

April 28, 2006

Not-So-Intelligent Spammers

Filed under: Humor/Mental Leisure — Matthias Miller @ 7:07 pm

This evening I got a spam comment on my recent post about Akismet spam filtering, and I thought it was too ironic to delete. The spam must have been triggered by the following sentence:

If Akismet reports a comment as spam, the comment is stored with a special “spam” comment type and the e-mail notification contains a bold “**SPAM**” in the subject. If an item is incorrectly flagged as spam, I can use the MySQL client or online administrator to turn it into a real comment.

The nascar flags spammer wrote:

I have a giant flag collection. I am thinking of starting a blog about its history. Now I am just doing research…thanks.

To which I responded:

Glad to be of help, nascar flags. I don’t know much about flags, but I’m pretty good at flagging spam. Sorry I had to remove the link to your website.

While you do your research, you might try limiting your comments to blog posts containing “flag” but not “spam”.

If you want me to keep your spam comments on my blog, try shooting yourself in the foot.

February 21, 2006

Amazon Promotion: The 53rd Way to Save Your Job

Filed under: Humor/Mental Leisure — Matthias Miller @ 7:11 am

I just received four copies of Chad Fowler’s book My Job Went to India: 52 Ways to Save Your Job from Amazon. I laughed out loud when I opened the box. Is Amazon offering the 53rd way to save your job?

I laughed even harder when I removed the paper wrapper. Where in the book was that? Maybe Chad Fowler didn’t endorse this promotional item after all.

Amazon’s 53rd Way to Save Your Job

Amazon’s 53rd Way to Save Your Job

Create a free website or blog at WordPress.com.