Skip to content

Instantly share code, notes, and snippets.

View nevans's full-sized avatar

nicholas a. evans nevans

View GitHub Profile
@nevans
nevans / gist:1013141
Created June 7, 2011 20:56
some silly tracert diagnostics...
ip_prefix=xxx.yyy.zzz
count=4
for (( i=96; i <= 127; i=i+1 )); do ip=$ip_prefix.$i; echo Trying $ip; mtr -nr -c $count $ip; done
# or
for (( i=96; i <= 127; i=i+1 )); do ip=$ip_prefix.$i; echo Trying $ip; arping -c $count -w $count $ip; done
# ...
@nevans
nevans / cidr_to_netmask.rb
Created June 3, 2011 17:19
Just a simple CIDR to netmask conversion
def unpack_ip(packed_ip)
octets = []
4.times do
octet = packed_ip & 0xFF
octets.unshift(octet.to_s)
packed_ip = packed_ip >> 8
end
ip = octets.join('.')
end
@nevans
nevans / eydeploy.rb
Created January 6, 2011 15:36
how to use private git repos with bundler at Engine Yard
# put this into your config/eydeploy.rb
def bundle
if File.exist?("#{c.release_path}/Gemfile")
info "~> Gemfile detected, bundling gems"
lockfile = File.join(c.release_path, "Gemfile.lock")
bundler_installer = if File.exist?(lockfile)
get_bundler_installer(lockfile)
else
warn_about_missing_lockfile
@nevans
nevans / environment.rb
Created September 3, 2010 15:23
Paperclip on rails 1.2.6
# stick this code at the bottom of your config/environment.rb
# (unless, of course, you already have something similar)
initializer_glob = File.join(RAILS_ROOT, "config/initializers/*.rb")
initializers = Dir[initializer_glob].map {|f| File.expand_path(f) }.sort
initializers.each {|f| require f }
@nevans
nevans / collapse_array_of_ranges.rb
Created August 26, 2010 01:39
Collapse an array of ranges into the union of their ranges
def collapse_array_of_ranges(array)
# simplify, by sorting on range.begin
array.sort_by(&:begin).inject([]) do |a, r|
# compared with last range...
last_range = a[-1]
if last_range && last_range.include?(r.begin)
# ignore range if it is completely inside of last range
unless(last_range.include?(r.end))
# this range overlaps last range,
# thus, pull off last range and merge them
Is there a way to get mustache to do the following?
ip addr show |
grep 'inet' |
awk '{ print $2 }' |
awk -F / '{ print $1 }' |
sort
@nevans
nevans / gist:335569
Created March 17, 2010 18:36
count files and disk usage
echo -e 'count\t size\t name'
for dir in *; do
echo -e `find "$dir" -type f | wc -l` '\t' \
`du -sh "$dir" | awk '{ print $1 }'` '\t' \
"$dir"
done | sort -n
@nevans
nevans / gist:330605
Created March 12, 2010 18:40
what IPs are trying to hack my server
sudo last -i -f /var/log/btmp |
awk '{ per[$3] += 1 } END { for (i in per) print per[i], i }' |
sort -n |
tail -15
@nevans
nevans / gist:330603
Created March 12, 2010 18:37
disk space for backups
mount |
awk '/ext3/{ print $3 }' |
grep -v '/tmp' |
xargs df |
awk 'NR==1{next}
$4~/%/{ print "+ "$2" ("$5")"; SUM += $2 }
$5~/%/{ print "+ "$3" ("$6")"; SUM += $3 }
END { print "=> " SUM/1024/1024 }'