Skip to content

Instantly share code, notes, and snippets.

View amasad's full-sized avatar
🎱
balling

Amjad Masad amasad

🎱
balling
View GitHub Profile
@amasad
amasad / jquery.tmpl.loader
Created March 9, 2011 23:44
Load external jquery templates and compile them on the fly
(function($){
$.extend({
loadTmpl: function(url, name, cb){
var c;
if (typeof name === "function"){
cb = name;
}else if(!cb){
cb = $.noop;
}
@amasad
amasad / jquery.dwell.js
Created March 19, 2011 00:28
Dwell click jQuery plugin
//dwell click plugin
//features:
//1-Adds new dwellClick event using a defined time delay
//2-optionally make the dwell click act like a regular click, by firing the browser click event
//3-Shortcut method $.dwell() well instantiate dwell on body element using
//usage:
// $(selector).dwell([delay = 500, click = false])
// delay : time to wait with the mouse idle to trigger dwell click
// click : trigger original click event
//
@amasad
amasad / tail-calls.js
Created May 5, 2011 09:25
Exploring freeing up the stack for tail-calls with setTimeout
/******************************************************************************
Without tail-call
******************************************************************************/
var times = 0;
function test(n) {
if (++n >= 10000) {
if (++times == 100) console.timeEnd('no-tail')
} else {
test(n);
@amasad
amasad / rabin.js
Created May 14, 2011 18:03
Rabin Karp in JS
//RABIN KARP
var BASE = 256,
PRIME = 256199087;
function tonum(c){
return c.charCodeAt(0);
}
function mod(a, p, m){
keywords = ['k', 's', 'i', 'v', 'c', 'd', 'e']
code = ''
window.toPrint = ''
log = (s)-> window.toPrint += s
car = (pair) -> pair[0]
cdr = (pair) -> pair[1]
cadr = (pair) -> car cdr pair
caddr = (pair) -> car cdr cdr pair
@amasad
amasad / bloop.js
Created July 9, 2011 11:49
Bloop -> JS compiler
/* spiffy links */
// http://www.amazon.com/gp/product/offer-listing/0394756827/ref=dp_pb_a//102-3710615-5652939?condition=all
// http://cgibin.erols.com/ziring/cgi-bin/cep/cep.pl?_key=FLooP
// http://cgibin.erols.com/ziring/cgi-bin/cep/cep.pl?_key=BLooP
// http://www.pdc.kth.se/~jas/retro/retromuseum.html
// http://c2.com/cgi/wiki?BloopFloopAndGloop
/* parsing variables */
BFloop = (function () {
var util = require('util'),
spawn = require('child_process').spawn,
fs = require('fs'),
vm = require('vm'),
find = spawn('find', ['./lib', '-name', '*.js']),
jsfiles;
find.stderr.on('data', function (data) {
console.log('something went wrong with find ' + data);
process.exit();
@amasad
amasad / sinbad.js
Created August 28, 2011 11:00
Bundiling
{
controller: "control.js",
js: {
'myBundle': {
wrap: '(function ($) {%s})(jQuery)',
scripts: [
{name: 'a.js', wrap: 'funciton a() {%s}'},
{name: 'b.js', wrap: 'func}
]
}
var runMode = function (code, language, elem) {
var $elem = $(elem),
// MODES is a hash containing all ace modes we support.
mode = MODES[lang.toLowerCase()].mode,
lines = code.split('\n'),
// Tokenizer initial state.
last = 'start',
Editor.prototype.setMode = function (language) {
this.editor.setMode('mode', language);
};