This file contains hidden or 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
# parallelize a function n ways, automatically spliting a big list | |
# of arguments into n roughly equal sized groups | |
import math | |
from multiprocessing import Pool | |
def split(iterable, n): | |
"""Splits an iterable up into n roughly equally sized groups.""" | |
groupsize = int(math.floor(len(iterable) / float(n))) | |
remainder = len(iterable) % n |
This file contains hidden or 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
# twitter oauth example using urllib | |
# | |
# Many uses of the twitter api don't require authenticating as other users, | |
# but the documentation centers around it. In this example, we're using the | |
# twitter-provided access key & secret (keys['token']) rather than going | |
# through the handshake. | |
import json | |
import urllib2 |
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
"""post stats on amit just because""" | |
import re | |
import urllib2 | |
from lxml import html | |
url = 'http://omlettesoft.com/newjournal.php3?topic=On+the+Waterfront&who=Lord+Omlette' |
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
"""Simple async crawler/callback queue based on gevent.""" | |
import traceback | |
import logging | |
import httplib2 | |
import gevent |
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
"""A native python implementation of the par2 file format. | |
This is only intended to be able to read packets in par2, not execute | |
repair, verify, or create new par2 files.""" | |
import struct |
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
"""Simple gevent POC to check how to get ZMQ sockets working with | |
subprocesses spawned by a simple process.""" | |
# this code doesn't seem to work properly; it has a | |
# tendency to hang at various parts of the req/rep process | |
# all of this stuff works flawlessly if you change: |
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
"""Simple eventlet POC to check how to get ZMQ sockets working with | |
subprocesses spawned by a simple process.""" | |
import os | |
import eventlet | |
import multiprocessing |
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
"""Which json is the best json.""" | |
import json | |
import simplejson as sjson | |
import ujson | |
import cjson | |
import bson |
This file contains hidden or 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
#!/bin/bash | |
# capture an area on OSX and run quickup on the produced file | |
CAPPATH="$HOME/tmp-capture.png" | |
if [ -n `which screencapture` ]; then | |
screencapture -i $CAPPATH | |
# esc exits screencapture without writing, don't try to upload in this case |
This file contains hidden or 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 | |
from lxml.html.clean import Cleaner | |
from lxml.html import defs | |
class AttrWhitelistCleaner(Cleaner): | |
"""An HTML Cleaner that can use an attribute whitelist. Defaults to using | |
the attributes that are whitelisted by default with ``safe_attrs_only`` | |
turned on.""" | |
def __init__(self, **kw): |
OlderNewer