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 print_function | |
import getpass | |
import hashlib | |
import urllib2 | |
def check_password(password): | |
sha = hashlib.sha1(password).hexdigest().upper() | |
sha_prefix = sha[:5] | |
sha_suffix = sha[5:] |
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
try: | |
raise Exception("source") | |
finally: | |
print "in finally" | |
try: | |
raise Exception("in finally") | |
except Exception: | |
print "handling exception in finally" |
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 | |
# | |
# $ cat ~/.bash_history | bash-history-to-zsh-history.py >> ~/.zsh_history | |
import sys | |
import time | |
def main(): | |
timestamp = int(time.time()) |
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 Model(AttrDict): | |
read_preference = read_preferences.PRIMARY | |
... | |
@contextmanager | |
def read_preference(pref): | |
try: | |
prev_pref = Model.read_preference | |
Model.read_preference = pref |
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
#!/bin/bash | |
# Copies an entire mongodb collection into an RDS table, skipping existing rows. | |
MONGOHOST="" | |
RDS="" | |
TABLE="" | |
DB="cureatr" | |
COLLECTION="" |
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 gc | |
from threading import Thread | |
import boto3 | |
import botocore | |
def client(): | |
boto3.Session().client("s3") | |
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 stream(q): | |
def before_cursor_execute(conn, cursor, statement, parameters, context, executemany): | |
cursor.scrollable = True | |
with sql.rds_engine.engine.connect() as conn: | |
streamconn = conn.execution_options(stream_results=True) | |
sa.event.listen(streamconn, "before_cursor_execute", before_cursor_execute) | |
results = streamconn.execute(q) | |
print "rowcount", results.rowcount | |
r = conn.execute("MOVE FORWARD ALL FROM {}".format(results.cursor.name)) | |
r = conn.execute("MOVE BACKWARD ALL FROM {}".format(results.cursor.name)) |
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 sqlalchemy as sa | |
>>> from cureatr.model import sql | |
>>> t = sa.Table( | |
... "cureatr.user_messages", sql.rds_metadata, | |
... sa.Column("_id", sql.ObjectIdType, primary_key=True), | |
... sa.Column("document", sa.dialects.postgresql.JSONB)) | |
>>> message_id = t.c.document['message_id'].label("message_id") | |
>>> iid = t.c.document['iid'].label("iid") | |
>>> q = sa.select([message_id, iid]) | |
>>> r = sql.rds_engine.engine.execute(q) |
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 contextlib | |
>>> import struct | |
>>> import bson | |
>>> import mock | |
>>> | |
>>> @contextlib.contextmanager | |
... def timed_oid(time): | |
... increment = [0] | |
... RealObjectId = bson.ObjectId | |
... def TimedObjectId(oid=None): |