{{ message }}

Instantly share code, notes, and snippets.

# Terry Chia Ayrx

Created Apr 6, 2014 — forked from ntrrgc/memdump.py
View memdump.py
 #!/usr/bin/env python from __future__ import print_function import sys import os import re import ctypes import argparse ulseek = ctypes.cdll['libc.so.6'].lseek ulseek.restype = ctypes.c_uint64
Created Jun 16, 2013
This is a simple python script to scrape comments from a web page.
 #!/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()
Created Jun 25, 2013
Sieve of Eratosthenes
View prime_sieve.py
 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:
Created Jul 11, 2013
Factorization snippet
View factorize.py
 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)))
Created Jul 11, 2013
Prime factorization snippet
View prime_factorize.py
 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:
Created Jul 12, 2013
LCM function for python.
View lcm.py
 def lcm(*numbers): """Return lowest common multiple.""" def lcm(a, b): return (a * b) // gcd(a, b) return reduce(lcm, numbers, 1)
Created Jul 13, 2013
A generator for Pythagorean triplets.
View pythagorean_triplets.py
 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:
Created Jul 17, 2013
The most awesomest scanner in the whole world!
View vuln_scanner.py
 import os for r,d,f in os.walk("/var/www"): for files in f: if files.endswith(".php"): print "You are fucked!"
Created Aug 20, 2013
A function to safely cast a long to an int without relying on any external libraries. From the brilliant Jon Skeet @ http://stackoverflow.com/questions/1590831/safely-casting-long-to-int-in-java
View safeLongToInt.java
 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; }
Created Aug 28, 2013
A simple piece of C code to print out the memory address of a specific environmental variable.