Skip to content

Instantly share code, notes, and snippets.

View shawndumas's full-sized avatar

Shawn Dumas shawndumas

View GitHub Profile
@shawndumas
shawndumas / range.js
Last active August 29, 2015 13:56
Stupid Hack for a Range Function
var range = function (from, to) {
if (arguments.length === 1) { to = from; }
var a = new Array(to + 1).join(0).split(0).map(function (v, i) { return i; });
if (from !== to) { a = a.slice(from, a.length); }
return a;
};
@shawndumas
shawndumas / contains.js
Created February 9, 2014 05:32
Contains
!!(~('xxxXXXxxx').indexOf('xxx'));
@shawndumas
shawndumas / spawn.js
Created March 27, 2014 18:04
ES6 Spawn
var spawn = function (generatorFn) {
var continuer = function (verb, arg) {
var r;
try {
r = generator[verb](arg);
} catch (error) {
return Promise.reject(error);
}
@shawndumas
shawndumas / requiredParam.js
Created May 8, 2014 17:49
ES6 -- Required Parameter
var throwMissinParamError = function () {
throw new Error('Missing parameter');
},
requiredParamFn = function (requiredParam = throwMissinParamError()) {
// use required parameter
return requiredParam;
};
(new Array(101)).join(0).split(0).map(function (v, i) {
var r = '';
i += 1;
(i%3 < 1) && (r += 'Fizz');
(i%5 < 1) && (r += 'Buzz');
!r && (r = i);
return r;
}).join('\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
@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);
JSON.parse(
((window.location.search) ?
window.location.search
.replace(/^\?/, '{"')
.replace(/=/g, '":"?')
.replace(/&/g, '"?,"')
.replace(/$/, '"}'):
'{}')
);
@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 / 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