Skip to content

Instantly share code, notes, and snippets.

@edfuh
edfuh / pre-commit
Created November 22, 2011 23:56 — forked from mklabs/pre-commit
run jshint as git/hg hooks, NO COMMIT IF NO LINT FREE.
#!/usr/bin/env node
// todo: try to require jshint here, instead of spawning process, then fallback to spawning process.
var jshint = nrequire('jshint');
if (jshint) return process.exit(0);
// jshint not installed locally, spawn process instead.
// basically the same, but less pretty.
var exec = require('child_process').exec;
@edfuh
edfuh / gist:1299726
Created October 19, 2011 21:23
Turn any string into a start up band name
// 'toaster'.toStartUpBand();
String.prototype.toStartUpBand = function () {
return this.replace(/[^aeiuo]([aeiuo]{1})[^aeiuo]+$/g, function(m,m1){return m.replace(m1, '')}) + 'ly';
};
@edfuh
edfuh / gist:1271740
Created October 8, 2011 01:58
convert characters to their unicode equivalents
function toUnicode(str) {
var unicodeStr = '',
i = 0,
strlen = str.length,
theUnicode;
for (; i < strlen; i++) {
code = str.charCodeAt(i).toString(16).toUpperCase();
while (code.length < 4) {
code = '0' + code;
}
@edfuh
edfuh / min
Created October 5, 2011 00:37
portable text editor, copy and paste into address bar
data:text/html,<textarea contenteditable spellcheck=false ></textarea><button>Save</button><style>body{margin:0; padding:0;}textarea{background%3A%23666%3Bcolor%3A%230F0%3Bheight:100%;width:100%;line-height:1.3;font-size:14px;letter-spacing:1px;padding:10px;}button{position:absolute;color:black;right:20px;top:20px;border:1px solid grey;font-size:14px;padding:6px 14px;border-radius:8px;background%3A%239ECFF5%3B}</style><script>p = document.body.firstChild;p.focus();var val,tabs = 2,spaces = (function (s, t){while (--t) s += s;return s}(' ', tabs));p.onkeydown = function (e) {val = this.value;sstart = this.selectionStart;s = val.substr(0, sstart);n = val.substr(sstart);if (e.which === 9) {this.value = s + spaces + n;this.selectionStart = this.selectionEnd = sstart + tabs;return false;}};document.querySelector('button').onclick = function () {window.location = 'data:application/json,' + val;}</script>
@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]
@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 / bored.js
Created September 9, 2011 17:50
bored
_=(typeof{});$=[];__=(typeof+$);alert((''+!!+$)[+$]+(''+$[+!+$])[+$]+__[+$]+_[+!+$+!+$+!+$+!+$]+_[+!+$+!+$+!+$+!+$+!+$]+(typeof'')[+!+$+!+$+!+$]+_[+$]+__[+$])
@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 / 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 / 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