Skip to content

Instantly share code, notes, and snippets.

@zed
zed / .gitignore
Created January 23, 2009 16:49
Generate performance plot
*.db
*.xy
*.pdf
*.png
*.pyc
*.pyo
#!/usr/bin/env python
"""Solution for project euler problem #12.
Based on:
http://stackoverflow.com/questions/571488/project-euler-12-in-python/571526#571526
"""
def ndiv(n, prime_factors):
"""Return number of divisors of `n`.
@zed
zed / .gitignore
Last active August 12, 2017 08:24
Find executables in %PATH% that match PATTERN.
*.py[co]
*.egg-info/
/MANIFEST
/build/
/dist/
"""Measure relative performance of answers to [1].
[1] http://stackoverflow.com/questions/1456617
"""
import linecache
import random
from timeit import default_timer
WORDS_FILENAME = "/etc/dictionaries-common/words"
#!/usr/bin/env python
"""$ python autocmd.py /exam/ple .txt,.html /pri/vate some_script.pl
Answer for http://stackoverflow.com/questions/1533923/monitor-folder-for-new-files-using-unix-ksh-shell-script-or-perl-script-and-trigg
Adopted from autocompile.py [1] example.
[1] http://git.dbzteam.org/pyinotify/tree/examples/autocompile.py
Advantages:
@zed
zed / main.py
Created November 15, 2009 18:46
#!/usr/bin/env python
"""Measure performance for 3 cases:
1. dict has key at the start of list
2. dict has key at the end of list
3. dict has no key in a list
See http://stackoverflow.com/questions/1737778/dict-has-key-from-list
"""
from functools import wraps
#!/usr/bin/env python2
"""Generate performance graphs. See
http://stackoverflow.com/questions/464960/code-golf-combining-multiple-sorted-lists-into-a-single-sorted-list#464967
"""
from __future__ import with_statement
from optparse import OptionParser, make_option
import collections
import copy
import glob
@zed
zed / .gitignore
Created March 28, 2010 20:11
profile performance of countchars() functions
*.py[co]
/cachegrind.out.profilestats
/profilestats.prof
@zed
zed / .gitignore
Created April 2, 2010 10:20
xor string: numpy vs. pyublas vs. fortran vs. C vs. Cython vs. Boost.Python
boost-python/bin/
*.py[co]
*.so
*.o
/xorcy.c
@zed
zed / dp.py
Last active January 19, 2022 00:24
Find height, width of the largest rectangle containing all 0's in the matrix
#!/usr/bin/env python
"""Find height, width of the largest rectangle containing all 0's in the matrix.
The algorithm for `max_size()` is suggested by @j_random_hacker [1].
The algorithm for `max_rectangle_size()` is from [2].
The Python implementation [3] is dual licensed under CC BY-SA 3.0
and ISC license.
[1]: http://stackoverflow.com/questions/2478447/find-largest-rectangle-containing-only-zeros-in-an-nn-binary-matrix#comment5169734_4671342