Skip to content

Instantly share code, notes, and snippets.

@alexbain
alexbain / extract.sh
Last active December 30, 2015 18:04
Extract all .7z files in a directory into subdirectories that match the file name
#!/bin/bash
for i in *.7z; do
subdirectory_name=$(echo $i | sed 's/.7z//');
7z x "$i" -o"$subdirectory_name"
done
@alexbain
alexbain / iphone-checker.py
Last active August 29, 2015 14:08
iPhone inventory checker
# Couple notes here:
# 0) Apple might change their APIs. If they do, this won't work any more.
# 1) If you want a different model iPhone, you'll have to do some sleuthing on apple.com "check availability" network requests to figure out what to look for.
import requests
import twilio
import sys
import time
import twilio.rest
@alexbain
alexbain / gist:18f83ac40a1369224173
Created May 26, 2014 02:25
btc-box kibana dashboard
{
"title": "btc-box",
"services": {
"query": {
"list": {
"0": {
"query": "plugin:\"load\"",
"alias": "Load",
"color": "#7EB26D",
"id": 0,
@alexbain
alexbain / agent.nut
Last active May 28, 2024 15:02
Electric Imp code (agent & device) for a laundry monitoring device. Read more at $BLOG_POST (tbd)
// Run on Agent
// Thresholds to adjust for better accuracy
dataThreshold <- 300; // Minimum accelerometer value to count as ON
onThreshold <- 24; // Number of ON samples before machine enters RUNNING state
offThreshold <- 60; // Number of OFF samples before machine enters OFF state
// State variable
running <- false;
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/-(git\/ \1 )/'
}
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
force_color_prompt=yes
@alexbain
alexbain / app.com.conf
Last active December 10, 2015 09:49
Upstart configuration template for a NodeJS app on Ubuntu 12.04LTS. Expected to live in ``/etc/init``
# /etc/init/APP.com.conf
description "APP.com"
start on runlevel [2345]
stop on runlevel [016]
# Restart when job dies
respawn
@alexbain
alexbain / chef_solo_bootstrap.sh
Created November 23, 2012 19:52 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap Chef Solo
#!/usr/bin/env bash
# Ensure things are up to date
apt-get -y update
apt-get -y upgrade
# Setup a build environment
apt-get install build-essential
apt-get install -y zlib1g-dev libssl-dev lib64readline-gplv2-dev libyaml-dev
@alexbain
alexbain / gist:3152023
Created July 20, 2012 17:26
Guardfile (Rocco)
# Generate documentation whenever a file is changed
guard 'rocco', :dir => 'docs', :stylesheet => 'http://jashkenas.github.com/docco/resources/docco.css' do
watch(%r{^app/.*\.(js)$})
end
@alexbain
alexbain / BB-FB-example.js
Created April 5, 2012 01:02
BackboneFirebase example
// Create a new instance of the Rooms collections
FireDrop.Rooms = new FireDrop.collections.Rooms();
// Fetch the initial data from Firebase
FireDrop.Rooms.fetch({ success: function (response) {
// Keep this collection in sync with Firebase.
// You could save this as a property on the collection for later access.
new BackboneFirebase(FireDrop.Rooms);