Skip to content

Instantly share code, notes, and snippets.

@a-laughlin
a-laughlin / ObjectCreationPerformance.js
Last active May 1, 2017 03:04
memory allocation of different js objects
window.__MemoryTest__ = {
proto:[],
concat:[],
creat:[],
newFn:[],
factory:[]
};
function proto(){return new Foo()}
function concat(){return Object.assign({},baseObj)}
@a-laughlin
a-laughlin / eslint-pushed-changes.sh
Created March 15, 2017 19:45 — forked from stalniy/eslint-pushed-changes.sh
ESLINT + pre-receive git hook
#!/bin/bash
TEMPDIR=`mktemp -d`
ESLINTRC=$TEMPDIR/.eslintrc
COMMAND="eslint --color -c $ESLINTRC --rule 'import/no-unresolved: 0' --rule 'import/no-duplicates: 0' --rule 'import/export: 0'"
git show HEAD:.eslintrc > $ESLINTRC
echo "### Ensure changes follow our code style... ####"
# See https://www.kernel.org/pub/software/scm/git/docs/githooks.html#pre-receive
@a-laughlin
a-laughlin / pre-commit
Created March 15, 2017 19:13 — forked from broofa/pre-commit
Git pre-commit hook that runs `eslint` with the `--fix` option to fix up issues where possible, and adds "fix"ed files into the commit
#!/bin/bash
cd "$(git rev-parse --show-toplevel)"
ESLINT="node_modules/.bin/eslint"
pwd
if [[ ! -x "$ESLINT" ]]; then
printf "\t\033[41mPlease install ESlint\033[0m (npm install eslint)\n"
exit 1
fi
(function(){
// problem 1
const curryJoin = a => b =>`${a}-${b}`;
// test 1 (expected: 'foo-bar')
console.log(curryJoin('foo')('bar'));
// problem 2 (not the cleanest solution, but not bad for hand-written with a 5 minute time constraint)
function pickGroup(groupsCollection){
@a-laughlin
a-laughlin / composeWalker.js
Last active March 9, 2018 08:45
composeWalker - Composable Graph Walker
// Copyright 2017 Adam Laughlin (github.com/a-laughlin).
// License - MIT
const _ = require('lodash');
// Temporarily abstracting this to a gist from private functions in another repo.
// Eventually destined for its own repo with documentation and testing given its usefulness.
// TBD notes are scattered through the code, and need creation as GH issues on transfer.
/**
* composeWalker
@a-laughlin
a-laughlin / lodash_reduce_experiments.md
Last active October 21, 2016 02:20
lodash reduce experiments for composing values

###Results from running function at bottom in console: ###Lodash 4.10 reduce vs vanilla reduce

_.reduce(['a','b','c'],(last,next)=>(last+next)) vs ['a','b','c'].reduce((last,next)=>(last+next))
// abc vs abc
_.reduce(['a','b','c'],(last,next)=>(last+next),undefined) vs ['a','b','c'].reduce((last,next)=>(last+next),undefined)
// undefinedabc vs undefinedabc
_.reduce(['b','c'],(last,next)=>(last+next),'a') vs ['b','c'].reduce((last,next)=>(last+next),'a')
// abc vs abc
_.reduce(['a'],(last,next)=>(last+next),undefined) vs ['a'].reduce((last,next)=>(last+next),undefined)
@a-laughlin
a-laughlin / instababel.sh
Created September 18, 2016 18:40
install babel and transpile a directory of files appropriate for your specified environment (e.g., node 6, ie9+ browsers)
function instababel(){
outputEnv=$1
destDir=$2
srcDir=$3
if [[ ! $3 ]]; then
echo "Must call as $ instababel <outputEnv> <srcDir> <destDir>"
echo "outputEnv options are node6 & ie9+"
return;
fi
[Enter steps to reproduce below:]
1. ...
2. ...
**Atom Version**: 1.6.1
**System**: Mac OS X 10.9.5
**Thrown From**: Atom Core
[Enter steps to reproduce below:]
1. ...
2. ...
**Atom Version**: 1.6.1
**System**: Mac OS X 10.9.5
**Thrown From**: Atom Core
[Enter steps to reproduce below:]
1. ...
2. ...
**Atom Version**: 1.6.1
**System**: Mac OS X 10.9.5
**Thrown From**: Atom Core