Skip to content

Instantly share code, notes, and snippets.

@kimniche
kimniche / iife.js
Last active October 14, 2016 16:47
// http://benalman.com/news/2010/11/immediately-invoked-function-expression/
// defining functions
// 1. function declaration
function f1() {
console.log('i do declare');
}
// 2. function expression
// Open Questions
// Q: Should we use void 0 or undefined?
// ---
// A: Very old versions of JS allow for assigning to `undefined`, which was an argument for preferring `void 0`,
// but strict mode will throw an error on attempted assignment to non-writeable properties (like `undefined`)
// ---
// tldr; `void 0` is JS trivia, prefer more expressive and totally safe `undefined`
// ----
// Rules added
// ---
// 1. yoda
// http://eslint.org/docs/rules/yoda
// ---
// a: bad
if ('red' === color) { ... }
// b: good (readability)
if (color === 'red') { ... }
function pluralizer(strings, ...values) {
// `strings` is [ 'I ate ', ' ' ]
let output = []
suffix = ''
if (values[0] !== 1) {
suffix = 's'
}
{
"extends": "airbnb/base",
"rules": {
"array-bracket-spacing": [ "warn", "always", { "singleValue": false, "objectsInArrays": false, "arraysInArrays": false } ],
"camelcase": "warn",
"indent": [ "warn", 4, { "SwitchCase": 1 } ],
"max-len": 0,
"no-dupe-keys": "error",
"no-nested-ternary": "warn",
"no-fallthrough": "warn",
@kimniche
kimniche / commit-msg
Last active December 12, 2016 13:45
Git commit message hook that checks for issue number within your commit message if you're on a bug branch. To enable: add this file into your repo's `.git/hooks` directory and make it executable (`chmod +x commit-msg`)
#!/usr/bin/env python
import sys, os, re
from subprocess import check_output
# Collect the parameters
commit_msg_filepath = sys.argv[1]
# Figure out which branch we're on
branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip()
#!/bin/bash
# First confirm we actually have commits to push
commits=`git log @{u}..`
if [ -z "$commits" ]; then
exit 0
fi
# Get OX-specific test command
# Assume not Mac OSX by default
@kimniche
kimniche / package.json
Last active December 13, 2016 14:28
Scripts section of package.json should match this in order to work with git hooks
"scripts": {
"start": "node index",
"dev": "node_modules/.bin/webpack",
"build": "node_modules/.bin/webpack -p",
"test:base": "mocha --recursive --compilers js:babel/register --no-timeouts",
"test:base-watch": "mocha -w --recursive --compilers js:babel/register --no-timeouts",
"test:base-silent": "npm run test:base 1>&- 2>&-",
"test:nowatch": "export NODE_ENV=test&& npm run test:base-silent",
"test:nowatch-win": "set NODE_ENV=test&& npm run test:base-silent",
"test": "export NODE_ENV=test&& npm run test:base-watch",
@kimniche
kimniche / pre-push
Last active December 12, 2016 20:45
Safety net: 1) asks user to confirm that files have been linted, and 2) enforces passing tests
#!/bin/bash
# Confirm we actually have commits to push
commits=`git log @{u}..`
if [ -z "$commits" ]; then
exit 0
fi
LOG="[pre-push]"
@kimniche
kimniche / post-commit
Last active December 22, 2016 23:04
After commit, warn if `eslint-disabled` is found in any of the commit's files
#!/bin/bash
LOG="[post-commit]"
unlinted=`grep eslint-disable $(git diff-tree --no-commit-id --name-only -r HEAD~1) -H`
if [ -z "$unlinted" ]; then
tput setaf 2; echo "$LOG no lint-disabled files found in commit"
else
tput setaf 3; echo "$LOG WARNING: lint-disabled files detected in commit"