Skip to content

Instantly share code, notes, and snippets.

View aerickson's full-sized avatar

Andrew Erickson aerickson

View GitHub Profile
@aerickson
aerickson / find_external_ip.rb
Created September 16, 2013 18:20
Get your IP address on unix-y system without a fork in Ruby. http://coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/
require 'socket'
def local_ip
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
UDPSocket.open do |s|
s.connect '64.233.187.99', 1
s.addr.last
end
ensure
require 'rubygems'
require 'mechanize'
FIRST_NAME = 'FIRST_NAME'
LAST_NAME = 'LAST_NAME'
PHONE = 'PHONE'
EMAIL = 'EMAIL@provider.com'
PARTY_SIZE = 2
SCHEDULE_RANGE = { :start_time => '19:00', :end_time => '20:30' }
@aerickson
aerickson / rsync_with_progress.py
Created October 13, 2011 05:09
Get total rsync progress using Python
# from https://libbits.wordpress.com/2011/04/09/get-total-rsync-progress-using-python/
import subprocess
import re
import sys
print('Dry run:')
cmd = 'rsync -az --stats --dry-run ' + sys.argv[1] + ' ' + sys.argv[2]
proc = subprocess.Popen(cmd,
shell=True,
@aerickson
aerickson / gist:1111135
Created July 28, 2011 07:10
making sudo work on lion
from: http://forums.macrumors.com/showthread.php?t=447812
///////////////
Reboot into single user mode (hold Option S while booting until it switches to text mode)
At the single user prompt, type: /sbin/fsck -fy
This checks the filesystem integrity
#!/bin/bash
FAIL=0
echo "starting"
./sleeper 2 0 &
./sleeper 2 1 &
./sleeper 3 0 &
./sleeper 2 0 &
def humanize secs
[[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name|
if secs > 0
secs, n = secs.divmod(count)
"#{n.to_i} #{name}"
end
}.compact.reverse.join(' ')
end
@aerickson
aerickson / unix rename files
Created March 9, 2011 05:47
easier than dealing with sed (for me at least)
for f in *.MP3; do mv "$f" "`basename "$f" .MP3`.mp3"; done;
<html>
<head>
<title>Image</title>
<script type="text/javascript">
function resizeImage()
{
var window_height = document.body.clientHeight
var window_width = document.body.clientWidth
require 'rubygems'
require 'grit'
require 'active_support'
include Grit
#
# USAGE: dead_branches <path_to_repo>
#