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
#!/usr/bin/python | |
__doc__ = """Tiny HTTP Proxy. | |
This module implements GET, HEAD, POST, PUT and DELETE methods | |
on BaseHTTPServer, and behaves as an HTTP proxy. The CONNECT | |
method is also implemented experimentally, but has not been | |
tested yet. | |
Any help will be greatly appreciated. SUZUKI Hisao |
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
getDistanceFromLatLonInKm = (lat1, lon1, lat2, lon2)-> | |
R = 6371 # Radius of the earth in km | |
dLat = deg2rad(lat2 - lat1) # deg2rad below | |
dLon = deg2rad(lon2 - lon1) | |
a = Math.sin(dLat/2) * Math.sin(dLat/2) + | |
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * | |
Math.sin(dLon/2) * Math.sin(dLon/2) | |
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)) | |
d = R * c # Distance in km | |
return d |
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
cnt = {} | |
MAX_DEP = 10 | |
def traverse(dep, i, size): | |
cnt[i] = cnt.get(i, 0) + 1 | |
if dep >= MAX_DEP: return | |
for j in range(size): | |
traverse(dep + 1, i + j + 1, size + 1 - j) | |
traverse(0, 0, 1) |
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
""" | |
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=203 | |
""" | |
import math | |
def prim(n, edges): | |
g = [[] for i in range(n)] | |
for u, v, w in edges: |
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 sys | |
import json | |
import socket | |
import h2.connection | |
import h2.events | |
def send_response(conn, event): | |
stream_id = event.stream_id | |
response_data = json.dumps(dict(event.headers)).encode('utf-8') |
OlderNewer