Skip to content

Instantly share code, notes, and snippets.

View rdammkoehler's full-sized avatar

Rich Dammkoehler rdammkoehler

View GitHub Profile
@rdammkoehler
rdammkoehler / foo.py
Created May 15, 2017 14:43
Undry Impl of Foo.py
from unittest import TestCase
import nose.tools as nt
def foo(x,y):
return (x+y), (x*y)
class FooTests_0(TestCase):
def test_foo_does_add(self):
@rdammkoehler
rdammkoehler / trunc_file.sh
Created February 3, 2017 02:24
Truncation a file without restarting a service
: > app.log && ls -halt app.log
@rdammkoehler
rdammkoehler / x.rb
Created December 13, 2016 19:55
return chain with gimme in ruby
require 'gimme'
class C
def f
return 1
end
end
l = [ 2, 3, 4, 5 ]
c = gimme(C)
#!/bin/bash
rm -f x.dat
for id in $( diff new.care_logs.ids old.care_logs.ids | grep ">" | awk '{print $2}' | grep -e "^[0-9]" ); do
jq ".[] | select(.id == $id)" old/care_logs.jsonl | jq .updated | cut -c1-12 >> y.dat
done
cat y.dat | sort | uniq
#!/bin/bash
rm -f x.dat
for id in $( diff new.shifts.ids old.shifts.ids | awk '{print $2}' | grep -e "^[0-9]" ); do
jq ".[] | select(.id == $id)" old/shifts.jsonl | jq .updated | cut -c1-12 >> x.dat
done
cat x.dat | sort | uniq
@rdammkoehler
rdammkoehler / FasterOfPuppet.lyrics
Created November 18, 2016 21:43
Lyrics of Master of Puppets rewritten to Faster of Puppet
End of development play, crumbling away
I’m your source of code-destruction
Veins that pump with fear, sucking darkest clear
Leading on your death’s construction
Taste me you will see
More is all you need
You’re dedicated to
This build is killing you
Come crawling faster
#!/bin/sh
email_to=${1:-default@yourdomain.com}
limit=${2:-90}
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $limit ]; then
echo "Running out of space \"$partition ($usep%/$limit%)\" on $(hostname) as on $(date)\n\nThe machine needs more disk or it will eventually crash!\n\nSend someone in to clean up log files and/or other files that are gobbling up the space.\n\nDetails:\n$output" |
mail -s "Alert: Almost out of disk space $usep%/$limit%" $email_to
server {
listen 80;
root /var/www/nginx;
index index.html;
server_name ender.noradltd.com;
rewrite ^/e/(\d+)$ /f?id=$1 last;
@rdammkoehler
rdammkoehler / muddled.rb
Last active May 13, 2016 00:49
Not what you thought you'd get
a = [ { :items => [{ 'item' => 'junk' },{ 'item' => 'junk' },{ 'item' => 'junk' }] }]
# => [{:items=>[{"item"=>"junk"}, {"item"=>"junk"}, {"item"=>"junk"}]}]
a[0][:items].count # => 3
d = [] # => []
d.push a[0][:items] # => [[{"item"=>"junk"}, {"item"=>"junk"}, {"item"=>"junk"}]]
d.count # => 1, not 3
d.push a[0][:items] # => [[{"item"=>"junk"}, {"item"=>"junk"}, {"item"=>"junk"}], [{"item"=>"junk"}, {"item"=>"junk"}, {"item"=>"junk"}]]
d.count # => 2, not 6
d.flatten.count # => 6
@rdammkoehler
rdammkoehler / copy_iso_to_usb.sh
Created April 21, 2016 20:25
Copy an ISO to a USB stick with a progress bar (linux/mac)
# with a progress bar
dd if=/Users/rich/Downloads/kali-linux-2016.1-amd64.iso | pv | dd of=/dev/disk2 bs=1m