This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, hashlib, urllib2, optparse | |
def get_remote_md5_sum(url, max_file_size=100*1024*1024): | |
remote = urllib2.urlopen(url) | |
hash = hashlib.md5() | |
total_read = 0 | |
while True: | |
data = remote.read(4096) | |
total_read += 4096 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fixnum | |
def power_of?(i) | |
self != 0 and Math.log(self.abs, i) % 1 == 0 | |
end | |
end | |
puts 8.power_of? 2 # => true | |
puts 64.power_of? 2 # => true | |
puts 27.power_of? 3 # => true | |
puts 27.power_of? 4 # => false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Timer(func, delay, start) { | |
this.func = func; | |
this.delay = delay; | |
this.running = false; | |
if(start) this.start(); | |
} | |
Timer.prototype.start = function(delay) { | |
this.running = true; | |
return this.interval = setInterval(this.func, (delay || this.delay)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.__defineGetter__('proc', function() { | |
var prop = this; | |
return function(obj) { | |
if(typeof obj[prop] == 'function') | |
return obj[prop](); | |
return obj[prop]; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window?.exports = window # allows more conventional client-side 'exporting' | |
# nicer timeouts/intervals in coffeescript | |
exports.timeout = (ms, fn) -> setTimeout(fn, ms) | |
exports.interval = (ms, fn) -> setInterval(fn, ms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sometimes I just want a quick-and-dirty thing to shove attributes onto without caring. | |
class Bucket | |
def method_missing(*args) | |
prop = args.first.to_s.sub(/\=$/, '').to_sym | |
self.class.send :attr_accessor, prop | |
send *args | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# helper | |
def with_stubbed_yml_config(yml, &block) | |
# stub, yield, unstub | |
end | |
# in examples.. | |
with_stubbed_yml_config(<<-YML) { url.should == 'http://test:5984' } | |
test: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
unless ARGV.length >= 2 | |
STDERR.puts "git old <commit/refspec> <file> [file2] ..." | |
Kernel.exit(1) | |
end | |
ref = ARGV.shift | |
ARGV.each { |f| `git show #{ref}:#{f} | $EDITOR` } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stop postgres | |
pg_ctl -D /usr/local/var/postgres stop && | |
# obliterate old postgres data | |
rm -Rf /usr/local/var/postgres && | |
# fresh start.. | |
initdb /usr/local/var/postgres -E utf8 && | |
# start postgres | |
pg_ctl -D /usr/local/var/postgres start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install "PowerBlock" (freeware) from this site: http://www.irradiatedsoftware.com/labs/ | |
Choose "Run AppleScript when power button is pressed" | |
Make it run this AppleScript: | |
do shell script "open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app" |
OlderNewer