Skip to content

Instantly share code, notes, and snippets.

View eschaefer's full-sized avatar

Eric Schaefer eschaefer

View GitHub Profile
@eschaefer
eschaefer / node-modules-swap.sh
Last active July 19, 2016 20:55
Swap node_modules folders when they're different between git branches
#!/bin/bash
# Assumes you are not committing node_modules to git. You really shouldn't...
#
# 1. Save bash script in some folder like $HOME/Scripts/
# 2. Add nswap alias to your .bash_profile:
# alias nswap="bash $HOME/Scripts/node-modules-swap.sh"
e=$(ls | grep node_modules)
@eschaefer
eschaefer / dev.sh
Last active August 17, 2016 21:29
webpack setup
#!/bin/sh
./node_modules/.bin/webpack --config webpack/webpack.server.config.js --progress --silent
./node_modules/.bin/webpack --watch --devtool inline-source-map --silent --config webpack/webpack.server.config.js &
./node_modules/.bin/webpack-dashboard -- ./node_modules/.bin/webpack-dev-server --hot --silent --no-info --config webpack/webpack.client.config.js &
cd assets
../node_modules/.bin/nodemon -q server.generated.js
kill %2
kill %1
@eschaefer
eschaefer / Textarea.jsx
Created August 27, 2016 21:12
Textarea Auto Resize with React
const DEFAULT_HEIGHT = 20;
export default class Textarea extends React.Component {
constructor(props) {
super(props);
this.state = {
height: DEFAULT_HEIGHT,
value: "Don't get lost in the upside down",
@eschaefer
eschaefer / .bash_profile
Created December 7, 2016 09:18
Git alias for purging old local branches no longer tracked remotely.
alias gitpurge='git branch --merged | grep -v "\*" | grep -Ev "(\*|master|develop|staging)" | xargs -n 1 git branch -d'
find . -name "*.orig" -type f -delete
@eschaefer
eschaefer / linting.md
Last active June 2, 2017 13:56
Linting only staged JS files

Lint all staged .js and .jsx files

git diff --cached --diff-filter=ACMRTUXB --pretty='format:' --name-only | grep -E .jsx?\\?$ | xargs node_modules/eslint/bin/eslint.js --quiet --ext .jsx,.js

Lint all staged .scss files

git diff --name-only --staged --diff-filter=ACMRTUXB --relative | grep -E .scss\\?$ | xargs --no-run-if-empty node_modules/sass-lint/bin/sass-lint.js -v --max-warnings 0

Keybase proof

I hereby claim:

  • I am eschaefer on github.
  • I am eschaefer (https://keybase.io/eschaefer) on keybase.
  • I have a public key ASBbNCfGB9yehV7P_wkcXw09d5JhxGeUT_4GZVlmEZx-Nwo

To claim this, I am signing this object:

@eschaefer
eschaefer / reduce.re
Created February 27, 2019 18:27
ReasonML 2D array reduce or fold_left
let nestedArray = [|[|1, 1|], [|1, 2|], [|1, 3|]|];
let _ = nestedArray |> Array.fold_left(Array.append, [||]) |> Js.log;
/* [1,1,1,2,1,3] */
let _ = nestedArray |> Js.Array.reduce(Js.Array.concat, [||]) |> Js.log;
/* [1,3,1,2,1,1] */
@eschaefer
eschaefer / general-components-codemod.js
Created March 29, 2019 12:35
Codemod to convert central general/index imports into tree-shakeable imports
/*
jscodeshift --parser=flow --extensions=js,jsx -t ./mod.js ~/Projects/frontend/app/*
*/
const GENERALS = {
AddToCartBtn: 'addToCartBtn/',
AddToLightbox: 'addToLightbox/',
AdManagerExportButton: 'adManagerExportButton/',
@eschaefer
eschaefer / de-dupe.js
Last active March 31, 2019 13:56
Clean way of removing duplicates from an array
const duped = [1, 2, 3, 3, 3, 2, 1];
const deduped = [...new Set(duped)];