Skip to content

Instantly share code, notes, and snippets.

(function () {
function isSupported() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch(e) {
return false;
}
}
if (!isSupported()) {
@andrewchilds
andrewchilds / toSelector.js
Created February 28, 2014 18:22
Simple element-to-CSS-selector conversion
function toSelector(elem) {
var css = '';
if (elem && elem.tagName) {
css += elem.tagName.toLowerCase();
if (elem.id) {
css += '#' + elem.id;
}
if (elem.className) {
css += '.' + elem.className.trim().split(' ').join('.');
}
@andrewchilds
andrewchilds / app.js
Last active August 29, 2015 14:03
A Better JavaScript Module Pattern
var App = (function () {
var pub = {};
pub.module = function (ns, fn) {
var context = pub;
var modules = ns.split('.');
var last = modules.pop();
for (var i = 0; i < modules.length; i++) {
context[modules[i]] = context[modules[i]] || {};
@andrewchilds
andrewchilds / librato.sh
Created November 3, 2014 02:58
Librato.sh: send basic VM health stats to Librato
#!/bin/bash
# Librato.sh
# Send basic VM health stats to Librato:
# - Network bytes sent/received
# - IO reads/writes
# - 1min, 5min, 15min load averages
# - Disk used/free
# - Memory used/free
#!/bin/bash
# Run every minute using cron:
# */1 * * * * /path/to/mysqlrestarter > /dev/null 2>&1
serverName="website.com"
adminEmail="me@example.com"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
UP=$(service mysql status | grep 'mysql start/running' | wc -l);
@andrewchilds
andrewchilds / .gitconfig
Last active July 12, 2016 20:45
My Git Config
[color]
diff = auto
status = auto
branch = auto
interactive = auto
ui = auto
[alias]
st = status
br = branch
@andrewchilds
andrewchilds / moving-stories-to-deployed.sh
Last active August 4, 2016 19:42
Moving Clubhouse Stories to Deployed
# Define the range of commits in this deploy.
old_sha="87d4fed"
new_sha="2d5b22d"
# Define a comment to be posted to each story.
deploy_id="v1.1234"
deploy_url="https://github.com/company/repo/compare/$old_sha...$new_sha"
comment="This story was deployed as part of $deploy_id.$deploy_url"
# Move stories to deployed and post a comment.
@andrewchilds
andrewchilds / extract-stories-from-commits.sh
Last active August 4, 2016 19:43
Extracting Clubhouse story IDs from a set of git commits
old_sha="87d4fed"
new_sha="2d5b22d"
git log $old_sha..$new_sha --oneline
# 2d5b22d Merge pull request #6 from company/me/ch345/my-story-name
# e730351 Fix bug
# c410ba0 Fix other bug [ch1004]
function clubhouse_find_stories_in_commit_range {
old_sha="$1"
@andrewchilds
andrewchilds / gitbr.sh
Created February 18, 2016 17:44
A more GitHub-like `git branch`
#!/bin/sh
# gitbr
#
# Example output:
#
# $ gitbr
#
# 3 months ago ac/1999/labels-redesign-spike
# 745f166 WIP.
@andrewchilds
andrewchilds / commit-and-branch-formatting-example.sh
Last active September 14, 2016 17:42
Clubhouse Branch & Commit Formatting Examples
# Associate a branch with story 123:
git checkout -b ac/ch123/my-story-name
# Or, you might want to associate a single commit with story 123:
git commit -m "Fix bug [ch234]"