Skip to content

Instantly share code, notes, and snippets.

@whille
whille / py2_http_bind_ip.py
Created August 30, 2024 17:55
test gevent bind ip , in python2, urllib2
#!/usr/bin/env python
import gevent.monkey
gevent.monkey.patch_all()
import gevent.socket as socket
#import socket
from gevent.pool import Pool
import logging
import urllib2
@whille
whille / t_pack.py
Last active December 31, 2021 09:28
test knapsack, basic dynamic programing problem
import random
import functools
def pack_prestore(ws, avail, vs=None):
"""
ws: weight list, integer
vs: value list; if None, reduced to subset sum problem
use cache to pre store recursive value
return optimal value
hash_sim = (bin(xor).count('0'))/float(d))