Skip to content

Instantly share code, notes, and snippets.

@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
(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 / unit_test_generator.sh
Last active August 21, 2018 09:42
Jasmine Unit Test Generator
#!/bin/bash
# Jasmine Unit Test Generator
# Assumes the codebase uses this module pattern:
# (https://gist.github.com/andrewchilds/ffcae28b2b01c5fbbb12)
# App.module('ModuleName', function (exports) {
# exports.myFunctionName = function () {};
# });
@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 / gist:11831dc82093e53d41af
Last active September 10, 2021 16:22
Rollbar RQL Cheat Sheet
# List users by average and maximum session length.
SELECT person, max(client.runtime_ms), avg(client.runtime_ms)
FROM item_occurrence
GROUP BY 1
ORDER BY 2 DESC
# List active date ranges for each deploy.
SELECT client.javascript.code_version, min(timestamp), max(timestamp)
FROM item_occurrence
GROUP BY 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 / clubhouse.sh
Last active January 23, 2020 00:07
Clubhouse/git/deploy utility functions
# Clubhouse / git / deploy utility functions
#
# API docs: https://clubhouse.io/api
#
# Assuming the following:
# 1. We have a range of git commits that represent the changes being deployed
# 2. Our git branches and pull requests use the username/ch123/story-name format,
# so that "ch123" ends up in a commit message
# 3. We have a Clubhouse API token set to the $CLUBHOUSE_API_TOKEN environment variable
#