This article is now published on my website: Prefer Subshells for Context.
// arcfour aka RC4 enc/decrypt function | |
// see: http://en.wikipedia.org/wiki/RC4 | |
arcfour = (function () { | |
"use strict"; | |
var swap = function (a, i, j) { | |
var tmp = a[i]; | |
a[i] = a[j]; | |
a[j] = tmp; | |
}; | |
// Shave-and-a-haircut, two bits! In the upper left corner | |
var secret = [{delay:0.5, x:0, y:0, radius:200}, | |
{delay:0.25, x:0, y:0, radius:200}, | |
{delay:0.25, x:0, y:0, radius:200}, | |
{delay:0.5, x:0, y:0, radius:200}, | |
{delay:1, x:0, y:0, radius:200}, | |
{delay:0.5, x:0, y:0, radius:200}, | |
{delay:0, x:0, y:0, radius:200}]; | |
function allowInside() { |
/* | |
* RC4 symmetric cipher encryption/decryption | |
* | |
* @license Public Domain | |
* @param string key - secret key for encryption/decryption | |
* @param string str - string to be encrypted/decrypted | |
* @return string | |
*/ | |
function rc4(key, str) { | |
var s = [], j = 0, x, res = ''; |
/* This WAS a two-line function until an awesome reddit user pointed out my logical flaw. Now It's a 5-line function :( */ | |
var Class = function(d){ | |
d.constructor.extend = function(def){ | |
for (var k in d) if (!def.hasOwnProperty(k)) def[k] = d[k]; | |
return Class(def); | |
}; | |
return (d.constructor.prototype = d).constructor; | |
}; |
Forget AMD and that's straight from the source. Sorry for the long build-up on the history, but if I'm to convince you to forget this non-technology, I think it's best you know where it came from. For those in a hurry, the executive summary is in the subject line. ;)
In Spring of 2009, I rewrote the Dojo loader during a requested renovation of that project. The primary pattern used to make it more practical was:
dojo.provide('foo', ['bar1', 'bar2'], function() { [module code] });
var containerEl = jessie.getElement('container'); | |
jessie.delegateClassNameListener(containerEl, 'click', 'myClass', function(e, secondParam) { | |
// NOTE: | |
// 1) Our handler only fires when the anchor with a class of 'myClass' is clicked | |
// or if the img inside the anchor is clicked etc | |
// 2) In our handler we provide the raw event object as the first param | |
// this could be the anchor or it could be the img so the target in this case is | |
// not consistently going to give us what we want. | |
var target = jessie.getEventTarget(e); |
var c = { | |
/* | |
* @reference: http://blog.rndm.de/p/console-log-wrapper | |
* @author: Christian http://rndm.de/ | |
* @license: Licensed under Apache License v2.0. See http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* example: c.log("Hello World") | |
* @param obj - variable to log | |
* @param trace - boolean display console.trace() | |
*/ |
In August 2007 a hacker found a way to expose the PHP source code on facebook.com. He retrieved two files and then emailed them to me, and I wrote about the issue:
http://techcrunch.com/2007/08/11/facebook-source-code-leaked/
It became a big deal:
http://www.techmeme.com/070812/p1#a070812p1
The two files are index.php (the homepage) and search.php (the search page)
function Waiter(context) { | |
if (context) { this.context = context; } | |
} | |
Waiter.prototype.failed = function (cb) { | |
if (this.result) { | |
if (!this.success) { cb.apply(this.context || this, this.result); } | |
} else { | |
if (!this.failedCbs) { this.failedCbs = []; } | |
this.failedCbs.push(cb); |