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
@echo off
:: http://weblogs.asp.net/jgalloway/archive/2006/11/20/top-10-dos-batch-tips-yes-dos-batch.aspx
echo %%~1 = %~1
echo %%~f1 = %~f1
echo %%~d1 = %~d1
echo %%~p1 = %~p1
echo %%~n1 = %~n1
echo %%~x1 = %~x1
echo %%~s1 = %~s1
echo %%~a1 = %~a1
#!/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/
@zed
zed / pet.py
Created September 15, 2009 20:03
#!/usr/bin/env python
"""Playing with pets.
http://stackoverflow.com/questions/1427479/managing-object-instances/1429344#1429344
"""
"""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
#!/usr/bin/env python
"""solve-puzzle.py: Solve Sergey's puzzle.
Usage:
$ wget http://codespeak.net/svn/user/niemeyer/constraint/trunk/constraint.py
$ python solve-puzzle.py [matrix size (should be perfect square)]
Example: