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
nommbp:~ fletcher$ python -m timeit "1" | |
100000000 loops, best of 3: 0.0176 usec per loop | |
nommbp:~ fletcher$ python -m timeit "''" | |
100000000 loops, best of 3: 0.0175 usec per loop | |
nommbp:~ fletcher$ python -m timeit "pass" | |
100000000 loops, best of 3: 0.0175 usec per loop | |
nommbp:~ fletcher$ python -m timeit "" | |
100000000 loops, best of 3: 0.0175 usec per loop | |
nommbp:~ fletcher$ |
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
# Some people have said that this import function violates the nature of functions by modifying it's caller's globals | |
# I would say that with such an essential as import an exception can be made. In any case, practicality over purity, and | |
# import('x') is a lot more practical and clean than x = import('x') | |
import django | |
# becomes | |
import('django') |
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
class Rectangle: | |
""" | |
A simple rectangle "literal" thingy. It uses operator overloading and the variable o to visually denote any rectangle of integer dimensions. | |
The "literals" are %100 valid Python syntax. | |
A line literal of width ten. | |
a = o- - - - - - - - - -o | |
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
Day job: | |
Freelance programmer and web developer | |
Favorite Python project: | |
Django! | |
Favorite Conference: |
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 is_hidden(self): | |
if self.state == 'HIDDEN': | |
return True | |
return False |
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 | |
id="some_id" | |
href="http://matchfwd.com/" | |
class="some_class et_cetera" | |
rel="twipsy" | |
title="Mouseover tooltip text." | |
> | |
Link text | |
</a> |
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 pascals_triangle(): | |
row = [1] | |
while True: | |
yield row | |
row = map(sum, zip([0] + row, row + [0])) |
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 english_count(count, object = None, plural = None): | |
""" | |
Generate an English representation of the count of objects. Plural defaults to object + 's' or object[:-1] + 'ies' for objects ending in 'y'. | |
Examples: | |
In [2]: english_count(0, 'hat') | |
Out[2]: 'no hats' | |
In [4]: english_count(1, 'hat') |
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
In [41]: from Crypto.Cipher import AES | |
In [42]: from Crypto import Random | |
In [43]: | |
In [43]: key = b'Sixteen byte key' | |
In [44]: iv = Random.new().read(AES.block_size) |
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 base64 | |
from Crypto.Cipher import AES | |
from Crypto.Hash import SHA256, HMAC | |
from Crypto.Random import get_random_bytes | |
class Cipher(object): | |
# This can be 16 (AES-128), 24 (AES-192), or 32 (AES-256) | |
key_length = 32 | |
OlderNewer