This file contains hidden or 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 hidden or 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 |
NewerOlder