Skip to content

Instantly share code, notes, and snippets.

View ross-nordstrom's full-sized avatar

Ross Nordstrom ross-nordstrom

View GitHub Profile
@ross-nordstrom
ross-nordstrom / rxjs-recursive-poll.js
Last active December 31, 2016 18:57
Demonstration of using RxJS to implement a recursive API Poller. This is an improvement on the simple `Observable.interval()` approach, because we won't kill long-running queries.
const rxjs = require('rxjs');
/**
* The entrypoint function. Pass it the thing to call
*/
function dynamicPoll(pollFunc/*, delayFunc*/) {
// A recursive stream, which triggers an API call
let i = 0; // just here for debugging
const trigger = new rxjs.BehaviorSubject(i++);
@ross-nordstrom
ross-nordstrom / pre-commit
Last active March 26, 2016 17:54
Prevent commits with keywords you shouldn't ever have in production code. Just put this file under `<repo>/.git/hooks/pre-commit`
#!/bin/sh
for FILE in `git diff-index --name-only HEAD --` ; do
# Check if the file contains 'debugger'
if cat $FILE | grep -q 'debugger' $FILE; then
echo $FILE ' contains debugger!'
exit 1
fi
# Check if the file contains 'console.log'
@ross-nordstrom
ross-nordstrom / prepare-commit-msg
Last active March 26, 2016 16:50
Takes a branch name like `myBranch_name-with/any^separators#12345` and adds `\n[#12345]` after the first line.
#!/bin/sh
#
# Automatically add branch name to every commit message except merge commits.
#
COMMIT_MSG=$1
addBranchName() {
branchPath=$(git symbolic-ref -q HEAD)
#!/usr/bin/env python
import json
from datetime import datetime
data = {}
now = datetime.now()
data['general_state'] = 1
data['year'] = now.year
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_SLA.rb
Created August 23, 2015 19:05
Speedtest.net Ping/Download/Upload breakdown
#!/usr/bin/env ruby
require 'json'
#
# Output with --simple looks like:
# Ping: 31.823 ms
# Download: 80.53 Mbit/s
# Upload: 11.25 Mbit/s
#
speed = `speedtest --simple`
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_CHANNEL_STRENGTHS.rb
Last active August 29, 2015 14:27
Get a breakdown of 2.4GHz channel utilization. Assumes wireless interface accessible at "wlan0".
#!/usr/bin/env ruby
require 'json'
ALLOWED_CHANNELS = ['Ch 1', 'Ch 6', 'Ch 11']
Infinity = Float::INFINITY
wifi = `iwlist wlan0 scan`
pieces2ghz = wifi.split("Cell ")[1..-1].select{|x| x.include?('Frequency:2') && x.include?('Channel ') }
data = pieces2ghz.map{ |x| [ x.split('Channel ')[1].split(')')[0].to_i, (x.split('Signal level=')[1].split('/')[0] rescue '0').to_i, (x.split('Protocol:')[1].split("\n")[0] rescue '[UNKNOWN]') ] }
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_WEATHER.rb
Last active August 29, 2015 14:25
Trend temperature and humidity. Note: only works on a Raspberry Pi with a DHT22 temp/humidity sensor.
#!/usr/bin/env ruby
require 'json'
NORMAL = 1
DEGRADED = 2
EXCESSIVE = 3
DOWN = 4
def is_number? string
true if Float(string) rescue false
end
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_SIGNALS.rb
Created October 5, 2014 17:34
Get a breakdown of WiFi utilization by relative signal strength. Assumes wireless interface accessible at "wlan0".
#!/usr/bin/env ruby
require 'json'
wifi = `iwlist wlan0 scan`
pieces2ghz = wifi.split("Cell ")[1..-1].select{|x| x.include?('Signal level=')}
data = pieces2ghz.map{ |x| [(x.split('Signal level=')[1].split('/')[0] rescue '0').to_i ]}
signals = { :'Very Weak' => 0, :Poor => 0, :Fair => 0, :Strong => 0 }
signals = data.reduce(signals) do |signals, x|
if(x[0] > 70)
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_PROTOCOLS.rb
Created October 5, 2014 17:14
Get a breakdown of wifi protocol usage. Assumes wireless interface accessible at "wlan0".
#!/usr/bin/env ruby
require 'json'
wifi = `iwlist wlan0 scan`
pieces2ghz = wifi.split("Cell ")[1..-1]
data = pieces2ghz.map{ |x| [ (x.split('Protocol:')[1].split("\n")[0] rescue '[UNKNOWN]') ] }
protocols = data.reduce({}) do |protocols, x|
protocols[x[0]] = protocols[x[0]] ? protocols[x[0]] + 1 : 1
protocols
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_CHANNEL_COUNTS.rb
Last active August 29, 2015 14:07
Get a breakdown of 2.4GHz channel utilization. Assumes wireless interface accessible at "wlan0".
#!/usr/bin/env ruby
require 'json'
ALLOWED_CHANNELS = ['Ch 1', 'Ch 6', 'Ch 11']
wifi = `iwlist wlan0 scan`
pieces2ghz = wifi.split("Cell ")[1..-1].select{|x| x.include?('Frequency:2') && x.include?('Channel ') }
data = pieces2ghz.map{ |x| [ x.split('Channel ')[1].split(')')[0].to_i, (x.split('Signal level=')[1].split('/')[0] rescue '0').to_i, (x.split('Protocol:')[1].split("\n")[0] rescue '[UNKNOWN]') ] }