Skip to content

Instantly share code, notes, and snippets.

View shawndumas's full-sized avatar

Shawn Dumas shawndumas

View GitHub Profile
[0, ['a', 'b', 'c'], 2, 'd', 4, 5, 'f', 7, ['g', 'h'], 9].reduce(function rec (prev, curr) {
if (/array/i.test(curr.constructor)) {
return curr.reduce(rec, prev);
} else if (/string/i.test(curr.constructor)) {
prev.push(curr);
}
return prev;
}, []);
@shawndumas
shawndumas / index.html
Last active August 29, 2015 14:10
jsbin.com/mewixa
<html>
<head>
<style>
b {
font-weight: normal;
}
</style>
<script src="http://cdn.jsdelivr.net/handlebarsjs/2.0.0/handlebars.js"></script>
</head>
<body>
@shawndumas
shawndumas / git-init.sh
Created November 24, 2014 19:01
Create, init, root, README.md, initial, origin, push...
git init
git commit -m 'root commit' --allow-empty
touch README.md
echo "$(pwd | rev | cut -d"/" -f1 | rev)" >> README.md
git add .
git commit -m 'initial commit'
git remote add origin git@git.corp.yahoo.com:sdumas/$(pwd | rev | cut -d"/" -f1 | rev).git
git push -u origin master
@shawndumas
shawndumas / guid.js
Last active May 4, 2022 15:35
GUID
var guid = function fn (n) {
return n ?
(n ^ Math.random() * 16 >> n/4).toString(16) :
('10000000-1000-4000-8000-100000000000'.replace(/[018]/g, fn));
};
@shawndumas
shawndumas / makeWorker.js
Last active August 29, 2015 14:10
In-Line Worker
var makeWorker = function (fn) {
var blobURL = URL.createObjectURL(
new Blob(
[ '(', fn.toString(), ')()' ],
{ type: 'application/javascript' }
)
),
worker = new Worker(blobURL);
return worker;
@shawndumas
shawndumas / boundHelper.html
Last active July 26, 2023 10:07
Pure Handlebars Bound Helper via Object.observe
<html>
<head>
<style>
b {
font-weight: normal;
}
</style>
<script src="http://cdn.jsdelivr.net/handlebarsjs/2.0.0/handlebars.js"></script>
</head>
<body>
JSON.parse(
((window.location.search) ?
window.location.search
.replace(/^\?/, '{"')
.replace(/=/g, '":"?')
.replace(/&/g, '"?,"')
.replace(/$/, '"}'):
'{}')
);
@shawndumas
shawndumas / partialApplication.js
Last active August 29, 2015 14:09
Partial Application with Substitution
var partial = function () {
var toArray = function (a) { return [].slice.call(a); },
appliedArgs = toArray(arguments),
fn = appliedArgs.shift(),
placeholderPositions = appliedArgs.map(function (e, i) {
if (e === '_') { return i; }
}).join('').split('');
return function () {
var args = toArray(arguments);
var template = function (str, options) {
var re = /{{(.+?)}}/g,
reExp = /(^( )?(var|if|for|else|switch|case|break|{|}|;))(.*)?/g,
code = 'with(obj) { var r=[];\n',
cursor = 0,
result,
add = function (line, js) {
js ? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') :
(code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : '');
@shawndumas
shawndumas / rhel-install.sh
Last active August 29, 2015 14:09
Git/Vim on RHEL
cd ~
wget http://ftp.gnu.org/gnu/stow/stow-latest.tar.gz
tar -xf stow-latest.tar.gz
cd ~/stow-latest
./configure && make && sudo make install
cd ~
wget https://www.kernel.org/pub/software/scm/git/git-2.1.3.tar.xz
tar -xf git-2.1.3.tar.xz
cd ~/git-2.1.3
./configure && make && sudo make install