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 threading, sys | |
import urlparse, httplib | |
is_done = False | |
class Downloader(threading.Thread): | |
def __init__(self, url, buf, n, semin, semout): | |
self.buf = buf | |
self.bufn = n | |
self.semin = semin |
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
# | |
# Rails template: rspec, guard, spork, libnotify, capybara | |
# $ rails -T -m <path-to-me> | |
gem_group :development, :test do | |
gem 'rspec-rails' | |
gem 'guard-rspec' | |
gem 'guard-spork' | |
gem 'spork' | |
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
# http://programmers.stackexchange.com/questions/117136/converting-a-bounded-knapsack-problem-to-0-1-knapsack-problem | |
# weight: cable length | |
# total weight: target span | |
# value: 1 for each cable | |
# want minimum number of cables, i.e. minimum total value | |
def knapsack_01_exact_min(weights, values, W): | |
# 0-1 knapsack, exact total weight W, minimizing total value | |
n = len(weights) |
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
# | |
# This piece of code is in the public domain. | |
# <zh.jesse@gmail.com> | |
# | |
from datetime import datetime | |
def get_age(date): | |
'''Take a datetime and return its "age" as a string. | |
The age can be in second, minute, hour, day, month or year. Only the |
OlderNewer