Skip to content

Instantly share code, notes, and snippets.

View datagutt's full-sized avatar
🐱

Thomas Lekanger datagutt

🐱
View GitHub Profile
@bellbind
bellbind / arcfour.js
Created July 19, 2011 15:18
[javascript]arcfour aka RC4 enc/decript function
// 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;
};
@brandenhall
brandenhall / Sample Usage
Created December 7, 2011 20:28
Secret Knock Detector module
// 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() {
@farhadi
farhadi / rc4.js
Created March 24, 2012 17:09
RC4 encryption in javascript and php
/*
* 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 = '';
@datagrok
datagrok / gist:2199506
Last active April 8, 2023 17:36
Virtualenv's `bin/activate` is Doing It Wrong
@jrf0110
jrf0110 / class.js
Created April 23, 2012 22:05
Simple extendable classes in javascript
/* 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]

});
@adamsilver
adamsilver / Calling application sample
Created August 14, 2012 13:21
jessie event delegation design
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);
@makepanic
makepanic / c.log.js
Created September 10, 2012 18:51
console log wrapper
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()
*/
@nikcub
nikcub / README.md
Created October 4, 2012 13:06
Facebook PHP Source Code from August 2007
@blixt
blixt / waiter.js
Created October 10, 2012 22:33
Waiters (promises/deferreds/futures)
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);