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 hammock | |
class Hammock(hammock.Hammock): | |
def __init__(self, name=None, parent=None, append_slash=False, **kwargs): | |
import requests | |
self.request_kwargs = {} | |
for k in list(kwargs.keys()): | |
if k not in requests.Session.__attrs__: | |
self.request_kwargs[k] = kwargs[k] | |
del kwargs[k] | |
super(Hammock, self).__init__(name, parent, append_slash, **kwargs) |
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 types import GeneratorType | |
import logging | |
def mydata(): | |
for a in range(202): | |
yield a | |
def chunks(data, size): | |
"""Yield successive n-sized chunks from l.""" | |
if isinstance(data, GeneratorType): | |
broken = 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
import pickle | |
import json | |
from json import JSONEncoder | |
import datetime | |
class PythonObjectEncoder(JSONEncoder): | |
def default(self, obj): | |
if isinstance(obj, (datetime.datetime, datetime.date)): | |
return obj.isoformat() |
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 os | |
from multiprocessing.dummy import current_process, Pool | |
import json | |
TOPIC = os.environ.get('SNS_TOPIC') | |
def make_hashable(obj): | |
if hasattr(obj, 'items'): | |
return tuple(obj.items()) | |
elif isinstance(obj, (list, tuple)): |
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 os | |
import time | |
import logging | |
from multiprocessing.dummy import Pool, current_process | |
import boto3 | |
from botocore.exceptions import ClientError | |
current_region = os.environ['AWS_DEFAULT_REGION'] | |
THREAD_CLIENT = {} | |
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 logging | |
def configure_logging(log_context, log_level=logging.INFO, logfmt=None, datefmt=None): | |
"""Configure logging.""" | |
default_logfmt = " ".join( | |
[ | |
"[%(levelname)s]", | |
"%(asctime)s.%(msecs)dZ", | |
"{aws_request_id}", |
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 logging | |
FORMAT = '%(asctime)-15s %(levelname)s %(module)s.%(funcName)s %(message)s' | |
DATEFMT = "%Y-%m-%d %H:%M:%S" | |
logging.basicConfig(level=logging.INFO, format=FORMAT, datefmt=DATEFMT) |
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 pretty_print(obj, indent=2, indent_level=0): | |
"""Pretty Print Objects.""" | |
if isinstance(obj, dict): | |
for k, v in obj.items(): | |
if isinstance(v, dict): | |
print('{}{}'.format(' '*indent*indent_level, k)) | |
pretty_print(v, indent=indent, indent_level=indent_level+1) | |
elif isinstance(obj, (list, tuple)): | |
for ele in v: | |
pretty_print(v, indent=indent, indent_level=indent_level+1) |
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/perl | |
# Generate string of x characters, type is a optional argument that if not empty then uses only alpha-numeric strings | |
use strict; | |
use warnings; | |
my $length = shift; | |
my $type = shift; | |
sub rand_string { | |
my ($length, @chars) = @_; | |
unless ($length) {$length = '32'}; |
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/python | |
""" | |
A cryptographically useful password generator. | |
Totally re-written by Kionmaru. | |
Modified again by blade2005 | |
""" | |
import string | |
import argparse |