Skip to content

Instantly share code, notes, and snippets.

@rectalogic
rectalogic / pwned.py
Created February 24, 2018 15:25
Simple python pwned password checker for https://haveibeenpwned.com/API/v2#PwnedPasswords
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:]
try:
raise Exception("source")
finally:
print "in finally"
try:
raise Exception("in finally")
except Exception:
print "handling exception in finally"
#!/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())
class Model(AttrDict):
read_preference = read_preferences.PRIMARY
...
@contextmanager
def read_preference(pref):
try:
prev_pref = Model.read_preference
Model.read_preference = pref
#!/bin/bash
# Copies an entire mongodb collection into an RDS table, skipping existing rows.
MONGOHOST=""
RDS=""
TABLE=""
DB="cureatr"
COLLECTION=""
import gc
from threading import Thread
import boto3
import botocore
def client():
boto3.Session().client("s3")
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))
>>> 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)
>>> import contextlib
>>> import struct
>>> import bson
>>> import mock
>>>
>>> @contextlib.contextmanager
... def timed_oid(time):
... increment = [0]
... RealObjectId = bson.ObjectId
... def TimedObjectId(oid=None):
cureatr_mongodb=> select not '{"tags": ["foo"]}'::jsonb <@ '{"tags": []}';
?column?
----------
t
(1 row)
cureatr_mongodb=> select not '{"tags": []}'::jsonb <@ '{"tags": []}';
?column?
----------
f