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 / fetch.sh
Last active December 25, 2015 02:39
Script to "git fetch" all repos with a given prefix
#! /bin/bash
TargetDir="*"
DateStamp=$(date +"%Y%m%d");
for Dir in $(find $TargetDir* -maxdepth 0 -type d );
do
FolderName=$(basename $Dir);
cd $FolderName
pwd
@ross-nordstrom
ross-nordstrom / prepare-commit-msg
Last active December 30, 2015 23:59
This goes in `.git/hooks/prepare-commit-msg`. Be sure to chmod +x it. It adds the user story id to every commit based on branch name. Intended for Pivotal tracker, but can be modified for other syntaxes.
#!/bin/sh
#
# Automatically add branch name and branch description to every commit message except merge commit.
# Prefix commit messages with "[US1234]: ""
#
COMMIT_EDITMSG=$1
addBranchName() {
branchPath=$(git symbolic-ref -q HEAD)
@ross-nordstrom
ross-nordstrom / .vimrc
Last active December 31, 2015 05:19
My vimrc. Minimalistic, with a focus on tabs
set hlsearch
set smartindent
set shiftwidth=3
set tabstop=3
set expandtab
set softtabstop=3
set expandtab
set shiftround
set autoindent
set copyindent
@ross-nordstrom
ross-nordstrom / sublime-keymap
Last active January 1, 2016 01:19
My Sublime Text (3) keybinding preferences. "Preferences > Key Bindings - User"
[
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" },
{ "keys": ["control+shift+w"], "command": "close_all" },
{ "keys": ["enter"], "command": "noop", "context":
[
{ "key": "auto_complete_visible" },
{ "key": "setting.auto_complete_commit_on_tab", "operand": false }
]
},
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_PROCESSES.rb
Last active August 29, 2015 14:07
Get process usage
#!/usr/bin/env ruby
require 'json'
p_main = `ps`
p_all = `ps -a`
users = `who`
data = {
:local => `ps`.split("\n").size - 1,
:tty => `ps a`.split("\n").size - 1,
:non_tty => `ps x`.split("\n").size - 1,
:total => `ps -A`.split("\n").size - 1
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_MEMORY.rb
Last active August 29, 2015 14:07
Get mem usage
#!/usr/bin/env ruby
require 'json'
memstr = `free`
memPieces = memstr.split("\n")[1].split(" ")
memData = {
:available => (100*memPieces[1].to_f/1000).round/100.0,
:used => (100*memPieces[2].to_f/1000).round/100.0,
:free => (100*memPieces[3].to_f/1000).round/100.0,
:shared => (100*memPieces[4].to_f/1000).round/100.0,
:buffers => (100*memPieces[5].to_f/1000).round/100.0,
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_CPU.rb
Last active August 29, 2015 14:07
Get CPU usage
#!/usr/bin/env ruby
require 'json'
cpu = `mpstat -P ALL`
cpuLines = cpu.split("\n")[3..-1]
max = 0
cpuData = cpuLines.map{|s| [s.split(" ")[2], s.split(" ")[3]]}.reduce({}) do |acc, s|
key = s[0] == 'all' ? 'total' : "cpu#{s[0]}"
acc[key] = s[1].to_f unless key == 'total'
max = [max, acc[key]].max unless key == 'total'
acc
#!/usr/bin/env ruby
require 'json'
time = Time.new
data = {
:general_state => 1, # TODO: Fancy logic to set based on value
:year => time.year % 100,
:month => time.month,
:day => time.day,
:hour => time.hour,
:minute => time.min
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_TEMP.rb
Last active August 29, 2015 14:07
Get a breakdown of CPU temperatures. Requires `sudo apt-get install lm-sensors && sudo sensors-detect`
#!/usr/bin/env ruby
require 'json'
temps = `sensors`
tempLines = temps.split("\n").select{|l| l.include?('Core') }
max = 0
tempData = tempLines.map{|l| [ l.split(':')[0].split(' ').join(''), l.split('+')[1].split('C')[0][0..-2] ] }.reduce({}) do |acc, l|
acc[l[0]] = l[1].to_f
max = [acc[l[0]], max].max
acc
end
@ross-nordstrom
ross-nordstrom / PLAYDOUGH_DEVICES.rb
Last active August 29, 2015 14:07
Get a count of devices. Requires nmap (apt-get install nmap)
#!/usr/bin/env ruby
require 'json'
me = `nmap --iflist | grep eth0`
myIp = me.split("\n")[0].split(' ')[2]
devices = `nmap -sP #{myIp}`
deviceCount = devices.split("\n").select{|l| l.include?('Host is up') }.size
#devices = `sudo nmap -sP #{myIp}`
#deviceCountSudo = devices.split("\n").select{|l| l.include?('Host is up') }.size