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
from threading import Thread | |
from Queue import Queue | |
def thread_func(filename, queue): | |
num_lines = sum(1 for _ in open(filename)) | |
queue.put(num_lines) | |
def total_lines(*files): | |
threads = [] | |
queue = Queue() |
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
from datetime import date, timedelta | |
from calendar import SUNDAY | |
def main(): | |
day = timedelta(days=1) | |
start = date(1901, 1, 1) | |
end = date(2000, 12, 31) | |
total = 0 | |
while start < end: |
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
from gmpy import is_prime | |
from math import sqrt | |
def largest_prime_factor(n): | |
for i in xrange(int(sqrt(n)), 1, -1): | |
if (n%i == 0) and is_prime(i, 100): | |
return i | |
def main(): | |
print largest_prime_factor(600851475143) |
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/env python | |
from os.path import getsize, isdir, exists, join | |
from os import walk | |
def main(argv=None): | |
import sys | |
from argparse import ArgumentParser | |
argv = argv or sys.argv |
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/env python | |
from itertools import imap, chain | |
from sys import stdin, stdout | |
def iterfile(filename): | |
fo = stdin if filename == "-" else open(filename) | |
return iter(fo) | |
def main(argv=None): |
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
def test_empty(): | |
assert sum([]) == 0 | |
def test_positive(): | |
assert sum([1, 2, 3]) == 6 | |
def test_negative(): | |
assert sum([-1, -2]) == -3 | |
def test_floats(): |
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
def test_empty(): | |
assert sum([]) == 0 | |
def test_positive(): | |
assert sum([1, 2, 3]) == 6 | |
def test_negative(): | |
assert sum([-1, -2]) == -3 | |
def test_floats(): |
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/env python | |
# Shorten URL using goo.gl | |
from httplib import HTTPSConnection | |
import json | |
def shorten(url): | |
con = HTTPSConnection("www.googleapis.com", timeout=3) | |
con.request("POST", "/urlshortener/v1/url", | |
body=json.dumps({"longUrl" : url}), |
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/env python | |
data = '''GEOMETRYCOLLECTION ( | |
POINT (-8.9648437500000000 -4.1308593750000000), | |
POINT (2.0214843750000000 -2.6367187500000000), | |
POINT (-1.4062500000000000 -11.1621093750000000), | |
POINT (-11.9531250000000000 -10.8984375000000000), | |
POLYGON | |
((-21.6210937500000000 1.8457031250000000,2.4609375000000000 |
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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><error><code>WebApplication</code><message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/><stacktrace>javax.ws.rs.WebApplicationException | |
at com.sun.jersey.server.impl.uri.rules.TerminatingRule.accept(TerminatingRule.java:55) | |
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71) | |
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111) | |
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63) | |
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:654) | |
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:612) | |
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:603) | |
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:309) | |
at com.sun.jersey.spi.con |