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 | |
| import argparse | |
| import urllib | |
| import urlparse | |
| from HTMLParser import HTMLParser | |
| arg_parser = argparse.ArgumentParser() | |
| arg_parser.add_argument('url') | |
| args = arg_parser.parse_args() |
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 gen_prime_sieve(n): | |
| # Implementation uses the Sieve of Eratosthenes | |
| # Optimized code from: http://stackoverflow.com/a/3941967/1170681 | |
| a = [True] * n | |
| a[0] = a[1] = False | |
| for (i, isprime) in enumerate(a): | |
| if isprime: |
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 factors(n): | |
| return set(reduce(list.__add__, | |
| ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))) |
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 prime_factors(n): | |
| """Returns all the prime factors of a positive integer""" | |
| factors = [] | |
| d = 2 | |
| while n > 1: | |
| while n % d == 0: | |
| factors.append(d) | |
| n /= d | |
| d += 1 | |
| if d*d > n: |
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 lcm(*numbers): | |
| """Return lowest common multiple.""" | |
| def lcm(a, b): | |
| return (a * b) // gcd(a, b) | |
| return reduce(lcm, numbers, 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
| def pythagorean_triplets(n): | |
| for i in xrange(1, n): | |
| j = i+1 | |
| k = j+1 | |
| while k <= n: | |
| while k*k < (i*i) + (j*j): | |
| k += 1 | |
| if k*k == (i*i) + (j*j) and k <= n: |
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 | |
| for r,d,f in os.walk("/var/www"): | |
| for files in f: | |
| if files.endswith(".php"): | |
| print "You are fucked!" |
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
| public static int safeLongToInt(long l) { | |
| if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { | |
| throw new IllegalArgumentException | |
| (l + " cannot be cast to int without changing its value."); | |
| } | |
| return (int) l; | |
| } |
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
| #include <stdlib.h> | |
| #include <stdio.h> | |
| int main(int argc, char *argv[]) { | |
| char *addr; | |
| if (argc < 2) { | |
| printf("Usage:\n%s <environment variable name>\n", argv[0]); | |
| exit(0); | |
| } |
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 | |
| def get_case_sensitive_pathname(path, top): | |
| for root, dirs, files in os.walk(top): | |
| for d in dirs: | |
| if os.path.join(root, d).lower() == path.lower(): | |
| return os.path.join(root, d) | |
| for f in files: | |
| if os.path.join(root, f).lower() == path.lower(): | |
| return os.path.join(root, f) |
OlderNewer