Skip to content

Instantly share code, notes, and snippets.

@edfuh
edfuh / templateloader.js
Created March 11, 2015 01:20
template loader
// The Template Loader. Used to asynchronously load templates located in separate .html files
window.templateLoader = {
load: function(views, callback) {
var deferreds = [];
$.each(views, function(index, view) {
if (window[view]) {
deferreds.push($.get('tpl/' + view + '.html', function(data) {
@edfuh
edfuh / amazon links without referral
Created April 22, 2015 18:54
don't give bloggers money
@edfuh
edfuh / shuffle.js
Created April 29, 2011 19:31
the fuuu?
var shuffle = function(v){
for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
return v;
};
@edfuh
edfuh / fibo.js
Created May 19, 2011 18:15
fibonacci functions
/// RECURSIVE
var fib = function (n) {
return n < 2 ? n : fib(n-1) + fib(n-2);
}
/// MEMOIZED
var memo = [0,1];
var fib = function(n) {
@edfuh
edfuh / mysqlbackupall.sh
Created July 25, 2011 18:24
saving this here because I always lose it
#!/bin/sh
echo "MySQL User:";
read MYSQLUSER;
echo "MySQL Pass:";
read MYSQLPASS;
for I in $(mysql -h localhost -u $MYSQLUSER --password=$MYSQLPASS -e 'show databases' -s --skip-column-names);
do mysqldump -u $MYSQLUSER -h localhost --password=$MYSQLPASS $I | gzip > "$I.sql.gz";
done
@edfuh
edfuh / curry.js
Created August 26, 2011 22:52
curry
//extend native. bad?
Function.prototype.curry = function () {
var aslice = [].slice, _method = this, args = aslice.call(arguments);
if (!args.length) return _method;
return function () {
var a = args.concat(aslice.call(arguments));
return _method.apply(this, a);
}
@edfuh
edfuh / timetil.js
Created September 7, 2011 00:19
the time until...
function timeTil(date) {
var t = [
[60 * 60 * 24 * 7 * 4 * 12, 'year'],
[60 * 60 * 24 * 7 * 4, 'month'],
[60 * 60 * 24 * 7, 'week'],
[60 * 60 * 24, 'day'],
[60 * 60, 'hour'],
[60, 'minute'],
[1, 'second']
],
@edfuh
edfuh / bored.js
Created September 9, 2011 17:50
bored
_=(typeof{});$=[];__=(typeof+$);alert((''+!!+$)[+$]+(''+$[+!+$])[+$]+__[+$]+_[+!+$+!+$+!+$+!+$]+_[+!+$+!+$+!+$+!+$+!+$]+(typeof'')[+!+$+!+$+!+$]+_[+$]+__[+$])
@edfuh
edfuh / gist:1233020
Created September 21, 2011 19:14
No methods in constructor, no properties in prototype
var Class = function () {
this.a = 'abc';
this.b = 666;
this.c = function () {
return 3 * 3;
};
}
Class.prototype.d = function () {
return 2 + 2;
@edfuh
edfuh / gist:1257717
Created October 2, 2011 18:10
Euler #5
memo = [0, 1]
def memofib(n):
if n >= len(memo):
i = len(memo)
while i <= n:
memo.append(memo[i-1] + memo[i-2])
i += 1
return memo[n]