Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am djk29a on github.
  • I am djk29a (https://keybase.io/djk29a) on keybase.
  • I have a public key ASCQLM9VXCy9BpHeqxj2zEb_VtmPOBbFS3lMYT-D1wgQdwo

To claim this, I am signing this object:

@djk29a
djk29a / gittricks.sh
Last active March 3, 2017 17:39
git tricks
# get all files modified in a branch
git diff --name-only <notMainDev> $(git merge-base <notMainDev> <mainDev>)
# shorter alternative for git versions... ?+
git whatchanged --name-only --pretty="" origin..HEAD
@djk29a
djk29a / gist:4888b852aea250d2ae836e939a19064f
Last active February 22, 2017 03:13 — forked from hummus/gist:8592113
aws cli + jq example
wget http://stedolan.github.io/jq/download/linux64/jq || sudo apt-get -y --force-yes install jq || sudo yum install -y jq
aws ec2 describe-instances --filters "Name=tag:Name,Values=$NAME" \
"Name=instance-state-name,Values=running" \
| jq -r \
".Reservations[] | .Instances[] | .InstanceId" \
aws ec2 describe-volumes --filters \
"Name=status,Values=available" \
| jq -r ".Volumes[] | .VolumeId" \
@djk29a
djk29a / timer_obj.scala
Last active October 4, 2016 01:28
Simple Scala timer I haven't tried to use since Scala 2.08
object Timer {
def time[R](block: => R): Pair[Long,_] = {
val t0 = System.nanoTime()
val result = block
val diff = System.nanoTime() - t0
// Post-timing processing can be added here, maybe
// an optional argument to this method?
Pair(diff, result)
}
}
@djk29a
djk29a / deconsolidate.rb
Last active September 30, 2016 18:38
Remove duplicate files in iTunes as a result of Consolidate Files
require 'find'
root = '/Volumes/music' # pick your path
Find.find(root) do |path|
if FileTest.directory? path and File.basename(path)[0] == '.'
Find.prune
else
d, f = File.split path
if f =~ /^(\d+(\-\d+)?.+)(\s\d+)\.(mp3)$/i
orig_file = File.join(d, $1 + '.' + $4) # check for existence of original file name including extension case
if File.readable? orig_file
@djk29a
djk29a / useradd.bash
Created March 31, 2016 20:53
Add users in a list
for u in username1 username2; do
# Ok, the groups are probably off but you get the point
useradd -p $(openssl passwd -1 ABC123def) -G primarygroup -g additionalgroups ${u}
end
@djk29a
djk29a / prune-chef-nodes.sh
Created March 22, 2016 00:30
Delete stale / not checking in Chef nodes
for node in $(knife search node "ohai_time:[* TO $(date +%s -d '5hours ago')]" -i); do
knife client delete -y $node
knife node delete -y $node
done
@djk29a
djk29a / zscaler-status.py
Last active March 22, 2016 00:28
Parse zScaler client info page; suitable for Sensu/Nagios/Check_MK monitoring checks
from HTMLParser import HTMLParser
import sys
"""
ZScaler IP Page Parser
$ curl -sL http://ip.zscaler.com/cgi-bin/index.cgi | python zscaler-status.py
{"proxycloud": "zscalertwo.net",
"proxyhost":"zs2-*redacted*",
"ip": "*redacted_ip*"}
scala> for(masked <- 0 until 8) { println("Bits: 0xff & masked bits (" + masked + ") => " + (256 - (255 & (1 << masked)))) }
Bits: 0xff & masked bits (0) => 255
Bits: 0xff & masked bits (1) => 254
Bits: 0xff & masked bits (2) => 252
Bits: 0xff & masked bits (3) => 248
Bits: 0xff & masked bits (4) => 240
Bits: 0xff & masked bits (5) => 224
Bits: 0xff & masked bits (6) => 192
Bits: 0xff & masked bits (7) => 128
@djk29a
djk29a / mtr_mpls.sh
Created October 9, 2015 16:04
Usage of mtr to get mpls label info
sudo mtr --port 443 --show-ips -T $1 -4 --no-dns --mpls # not sure why I needed both --show-ips and --no-dns, hmm