Skip to content

Instantly share code, notes, and snippets.

View dead_branches.rb
require 'rubygems'
require 'grit'
require 'active_support'
include Grit
#
# USAGE: dead_branches <path_to_repo>
#
View resize image while maintaining aspect ratio
<html>
<head>
<title>Image</title>
<script type="text/javascript">
function resizeImage()
{
var window_height = document.body.clientHeight
var window_width = document.body.clientWidth
@aerickson
aerickson / unix rename files
Created Mar 9, 2011
easier than dealing with sed (for me at least)
View unix rename files
for f in *.MP3; do mv "$f" "`basename "$f" .MP3`.mp3"; done;
View ruby seconds to human readable
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
View parallel_bash_runner
#!/bin/bash
FAIL=0
echo "starting"
./sleeper 2 0 &
./sleeper 2 1 &
./sleeper 3 0 &
./sleeper 2 0 &
@aerickson
aerickson / gist:1111135
Created Jul 28, 2011
making sudo work on lion
View gist:1111135
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
@aerickson
aerickson / rsync_with_progress.py
Created Oct 13, 2011
Get total rsync progress using Python
View rsync_with_progress.py
# 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,
View urbanspoon_reservations.rb
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' }
View find_external_ip.rb
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
@aerickson
aerickson / PyCurlSSLFixOnUbuntu
Last active Dec 16, 2018
how to rebuild PyCurl against OpenSSL on Ubuntu (12-13+)
View PyCurlSSLFixOnUbuntu
XBMC uses pycurl/libcurl to fetch stuff. YouTube requires the RC4
cipher that GnuTLS has removed for security reasons (or doesn't allow
it to be selected, or XBMC doesn't allow to specify the cipher...).
PyCurl linked against OpenSSL can take the RC4 argument and make the
Youtube plugin work (Ubuntu ships it linked against GnuTLS), so we
need to rebuild to make it work.
///
from: https://code.google.com/p/wfuzz/wiki/PyCurlSSLBug