This file contains 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 | |
import time | |
import tarfile | |
import zipfile | |
def bytes2str(bytes): | |
if bytes < 0: return "0 B" | |
if bytes < 1024: return "%.2f B" % (bytes) | |
elif bytes < 1048576: return "%.2f Kb" % (bytes / 1024) | |
elif bytes < 1073741824: return "%.2f Mb" % (bytes / 1048576) |
This file contains 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 __future__ import division | |
import sys | |
class Person(object): | |
attrs = ('name', 'surname', 'birth', 'birth_place', 'gender', 'marital_status', 'address', 'job') | |
def __init__(self, name, surname, birth, birth_place, gender, marital_status, address, job): | |
kw = locals() |
This file contains 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
--- a/werkzeug.css_t | |
+++ b/pyg.css_t | |
@@ -7,8 +7,8 @@ | |
*/ | |
{% set page_width = '980px' %} | |
-{% set sidebar_width = '220px' %} | |
-{% set font_family = "Georgia, serif" %} | |
+{% set sidebar_width = '230px' %} | |
+{% set font_family = "'Ubuntu', serif" %} |
This file contains 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 re | |
import os | |
import ast | |
import glob | |
import collections | |
class ImportVisitor(ast.NodeVisitor): | |
def __init__(self): | |
self.imports = [] | |
self.modules = collections.defaultdict(list) |
This file contains 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
''' | |
vc.py is a slight modification of virtualenvcontext, and it offers the possibility | |
to use the context manager without virtualenvwrapper. | |
This is useful while testing things, because it allows you to works with ad hoc | |
virtualenvs. | |
''' | |
## Modified from virtualenvcontext (C) 2011 Ralph Bean | |
## http://pypi.python.org/pypi/virtualenvcontext/ |
This file contains 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 floor(x, y): | |
return (x - x % y) / float(y) | |
def ceil(x, y): | |
return floor(x - 1, y) + 1 | |
def integer_part(x, y): | |
if x * y >= 0: | |
return floor(x, y) | |
return ceil(x, y) |
This file contains 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 math | |
def from_root(n): | |
''' | |
Construct a continued fraction from a square root. The argument | |
`n` should be an integer representing the radicand of the root: | |
>>> from_root(2) | |
(1, [2]) |
This file contains 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 poly | |
import operator | |
import fractions | |
import functools | |
import itertools | |
def is_root(p, k): | |
''' | |
True if k is a root of the polynomial p, False otherwise. |
This file contains 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
1964 function calls in 0.024 seconds | |
Ordered by: standard name | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1 0.000 0.000 0.024 0.024 <string>:1(<module>) | |
2 0.000 0.000 0.000 0.000 clock.py:121(_hash) | |
2 0.000 0.000 0.000 0.000 clock.py:135(__init__) | |
1 0.000 0.000 0.000 0.000 clock.py:159(get_callback) | |
1 0.000 0.000 0.000 0.000 clock.py:178(release) |
This file contains 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
''' | |
Split a long number in batches. | |
>>> k = 178684461669052552311410692812805706249615844217278044703496837914086683543763273909969771627106004287604844670397177991379601L | |
>>> print pretty(k) | |
17868446 16690525 52311410 69281280 57062496 15844217 27804470 34968379 | |
14086683 54376327 39099697 71627106 00428760 48446703 97177991 379601 | |
>>> print pretty(k, 3, 9) |
OlderNewer