Skip to content

Instantly share code, notes, and snippets.

@mLuby
mLuby / powerset.js
Created December 21, 2015 22:50
Generate power set from a string
function powerset (input) {
return input
.split(input ? '' : false)
.filter(duplicates({}))
.map(concatEmptyStr)
.reduce(multiplyMatrix)
}
function concatEmptyStr (str) {
return str ? ['', str] : ['']
@mLuby
mLuby / what-forces-layout.md
Created January 28, 2016 04:59 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@mLuby
mLuby / home-brewed redux.js
Last active July 26, 2016 21:05
Implementation of redux pattern and simulated use within a react-like app.
"use strict"
// Redux
const bindActionCreators = (actionCreator, dispatch) => args => dispatch(actionCreator(args))
const createStore = reducer => { // (state -> action -> state) -> Store
let state = null
const subscribers = []
const dispatch = action => {
state = reducer(state, action)
@mLuby
mLuby / .eslintrc.json
Last active January 29, 2017 03:58
Comprehensive JS lint file (+ es6, react)
{
"rules": { // And why they're best practice (alphabetized).
"accessor-pairs": [2, {"getWithoutSet": true}], // omission is usually by mistake.
"array-bracket-spacing": 2, // spaces can make arrays take up a lot of space, and concise code allows for more reading context.
"array-callback-return": 2, // omission is usually by mistake.
"arrow-body-style": [2, "as-needed"], // improves consistency and readability.
// "arrow-parens": [2, "as-needed"], // allows for concise arrows while improving consistency.
"arrow-spacing": 2, // improves consistency and readability.
"block-scoped-var": 2, // can behave unexpectedly due to variable hoisting.
"block-spacing": 2, // helps differentiate blocks (spaced) from objects (not spaced).
@mLuby
mLuby / kill-on-port.sh
Created September 2, 2016 21:02
kill processes running on a port
test $(uname) == "Darwin" && lsof -t -i tcp:9001 | xargs kill
test $(uname) == "Linux" && fuser -k 9001/tcp
@mLuby
mLuby / kill-by-proc-name.sh
Created September 2, 2016 21:03
kill a process by name
# where process has name thing1...
ps aux | grep [t]hing1 | awk '{print $2}' | xargs kill
@mLuby
mLuby / sed-newline.sh
Created September 2, 2016 21:04
sed newline
# in data2.js replace , with ,\n then dump into data.js
cat data2.js | sed -e 's/,/,\'$'\n/g' > data.js
@mLuby
mLuby / rename.sh
Created September 2, 2016 21:05
rename files en-masse
IFS=$'\n'; # change delimiter so it works on all but newline filenames
for file in $(find ./ -name '*.js');
do mv "${file}" "${file}x" # file%jsx removes jsx from end of file
done
for file in $(find ./ -name '*spec.jsx');
do mv "${file}" "${file/unit.spec.jsx/spec.js}" # file%jsx removes jsx from end of file
done
@mLuby
mLuby / if.sh
Created September 2, 2016 21:07
if global var
BOB=true
echo $BOB
if $BOB; then
BOB=false
echo $BOB
fi
@mLuby
mLuby / git-tag-rename.sh
Created September 2, 2016 21:07
rename git tags
# tag a specific commit
git tag v1.7.1 4e13624
# rename a tag
old="1.7.1"
new="v1.7.1"
echo "$old -> $new"
git tag $new $old
git tag -d $old # delete the old tag locally
git push origin :refs/tags/$old # delete the old tag on remote