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
#!/usr/bin/env python | |
""" | |
Extract all attachments from MS Outlook '.eml' file EML_FILE into | |
directory OUTPUT_DIR. If OUTPUT_DIR does not exist, it will be | |
created. | |
Usage: extract_attachments.py EML_FILE OUTPUT_DIR | |
""" | |
from __future__ import print_function | |
import sys |
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 requests | |
class QuotesAPIClient: | |
def __init__(self, baseurl, session): | |
self._baseurl = baseurl | |
self._session = session | |
@classmethod | |
def default(cls, api_token): | |
session = requests.Session() |
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 collections | |
from twisted.internet import protocol | |
class LineParser(object): | |
def __init__(self, delimiter, max_length): | |
self.delimiter = delimiter | |
self.max_length = max_length | |
self._buffer = b'' |
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 asyncio | |
import itertools | |
import aiohttp | |
import async_timeout | |
async def fetch_with_response_delay(session, delay): | |
if not 0 <= delay <= 10: | |
raise ValueError('Delay must be between 0 and 10 inclusive') |
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 six | |
class TypedField(object): | |
def __init__(self, classinfo): | |
self._classinfo = classinfo | |
self.fieldname = None # Set by the metaclass | |
def __get__(self, instance, owner): | |
try: |
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 _Transform: | |
transform = None | |
transargs = () | |
def __call__(self, image): | |
""" | |
Run the transformation and return the tranformed image data | |
""" | |
args = [getattr(self, arg) for arg in self.transargs] | |
return self.transform(image, *args) |
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
web: twistd -n web -p $PORT --class=miscserver.resource |
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 random | |
def default_diceroller(): | |
return random.randint(1, 6) | |
class CrapsGame(object): | |
_diceroller = default_diceroller | |
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
slugs = ['unipain', 'pyiter', 'pypackages', 'pytest0', 'ircbot'] | |
print('\n'.join('http://bit.ly/{0}'.format(slug) for slug in slugs)) |
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 sqlite3 | |
conn = sqlite3.connect(':memory:') | |
conn.execute('CREATE TABLE user (user_id INTEGER PRIMARY KEY, name TEXT)') | |
conn.commit() | |
cursor = conn.cursor() | |
for name in ['alice', 'bob', 'carol', 'david']: | |
cursor.execute('INSERT INTO user (name) VALUES (?)', (name,)) |
NewerOlder