Skip to content

Instantly share code, notes, and snippets.

View attaboy's full-sized avatar

Luke Andrews attaboy

View GitHub Profile
@attaboy
attaboy / autobind.ts
Created November 19, 2019 14:26
Simple utility to bind all methods of an instance so that they have `this` context no matter what.
const blacklist = [
'constructor',
'componentDidMount',
'componentDidUpdate',
'componentWillMount',
'componentWillReceiveProps',
'componentWillUnmount',
'componentWillUpdate',
'render',
'shouldComponentUpdate'
@attaboy
attaboy / pre-commit
Last active July 25, 2016 14:45
Run eslint on the pending git commit
#!/bin/sh
DIFF_FILES=$(git diff --cached --name-only|egrep app/assets/.+\.jsx?$)
if [ ! -z $DIFF_FILES ];
then
./node_modules/.bin/eslint -- $DIFF_FILES
fi
if [ $? -eq 1 ];
then
printf "Lint failed. Commit with --no-verify to continue or fix your errors\n\n";
@attaboy
attaboy / object_equality.js
Last active June 8, 2016 20:40
Object equality
/*
deepEquals tests two objects and returns true if:
- both objects are === identical
- both objects are NaN
- both objects are arrays, and at each index, the values are deepEquals (recursively)
- both objects have the same prototype, the same keys, and at each key, the values are deepEquals (recursively)
- a function reference is compared to another reference to the same function
deepEquals returns false if:
- two objects have the same keys and values, but were created with different constructors
@attaboy
attaboy / react_cheatsheet.markdown
Last active June 2, 2016 17:56
React cheatsheet

React cheatsheet

Notes from a beginner's perspective on things that may trip you up when you start using React, the JS interface library

Gotchas

Form inputs

To work properly and allow user modification, form element components like <input>s must:

  • set the value attribute of the element using the component state, e.g. value={this.state.value}
  • rely on an onChange handler to keep the component state in sync with the element value e.g.
    ``
@attaboy
attaboy / pre-commit
Last active October 6, 2015 07:08
git pre-commit hook for jshinting before you commit
#!/bin/sh
# A pre-commit hook for git to lint JavaScript files with jshint
# @see https://github.com/jshint/jshint/
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
@attaboy
attaboy / .bashrc
Created November 8, 2011 18:32
Colored bash prompt for those with git completion tools installed
if [ "$USER" = "root" ]; then
PS1='\e[1;31m[\u@\h \W$(__git_ps1 " (%s)")]\$\e[0m '
else
PS1='\[\e[0;34m\][\[\e[m\]\u@\h \[\e[0;33m\]\w\[\e[0;36m\]$(__git_ps1 " (%s)")\[\e[0;34m\]]\[\e[0m\]\$ '
fi
@attaboy
attaboy / gist:1346280
Created November 7, 2011 21:40
Destroy the localStorage copy of less.js client-side-generated CSS
// Destroys the localStorage copy of CSS that less.js creates
function destroyLessCache(pathToCss) { // e.g. '/css/' or '/stylesheets/'
if (!window.localStorage || !less || less.env !== 'development') {
return;
}
var host = window.location.host;
var protocol = window.location.protocol;
var keyPrefix = protocol + '//' + host + pathToCss;
@attaboy
attaboy / douce nuit 3.bbcolors
Created August 1, 2011 21:21
"Douce nuit" color scheme for BBEdit 10
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BackgroundColor</key>
<string>rgba(0.141497,0.133242,0.149264,1.0)</string>
<key>CommentsColor</key>
<string>rgba(0.805432,0.388983,0.620188,1.0)</string>
<key>CtagsIdentifierColor</key>
<string>rgba(0.714344,0.745660,0.922185,1.000000)</string>