Skip to content

Instantly share code, notes, and snippets.

@seanickle
seanickle / aws_v4.py
Created September 19, 2020 16:03
AWS Signature V4 for API Gateway
import sys
import base64
import datetime
import hashlib
import hmac
import requests
import json
import urlparse
# This file is derived from the example here
@seanickle
seanickle / parallel.md
Created March 1, 2020 17:50
parallel_async_invoke
import traceback
from multiprocessing import Process, Pipe

def parallel_async_invoke(payloads, work_func):
    # => https://aws.amazon.com/blogs/compute/parallel-processing-in-python-with-aws-lambda/
    # create a list to keep all processes
    processes = []
@seanickle
seanickle / plot.md
Created October 18, 2019 00:22
overlaid matplot lib histograms
# Nice technique from https://srome.github.io/Covariate-Shift,-i.e.-Why-Prediction-Quality-Can-Degrade-In-Production-and-How-To-Fix-It/ 
# ... put two histograms on same plot ...

def produce_overlayed_hists_for_col_dfs(col, dfs):
    fig = plt.figure(figsize=(12,12))

 ax = fig.add_subplot(121)
@seanickle
seanickle / foo.md
Created September 2, 2019 17:39
handy openssl certificate foo

Source: Copied the below from stackoverflow

With SNI

If the remote server is using SNI (that is, sharing multiple SSL hosts on a single IP address) you will need to send the correct hostname in order to get the right certificate.

openssl s_client -showcerts -servername www.example.com -connect www.example.com:443 
@seanickle
seanickle / quick codes.md
Created June 28, 2019 15:46
Comparing python dictionaries

Quick back of the manilla envelope for comparing first level of two dictionaries

  • Below, diff has just the left, right keys for which d1 and d2 do not agree
  • Inserting NOKEY when left or right do not have that value.
import hashlib
import json
hsh = lambda x: hashlib.sha512(json.dumps(x)).hexdigest()[:5]
make_sorted_ordered = lambda d: OrderedDict(sorted(d.items(), key=lambda x:x[0]))

def delta(d1, d2):
@seanickle
seanickle / some retry code.md
Created April 12, 2019 22:06
some retry code.md
import requests
import time
import json
from functools import partial
from requests.exceptions import ConnectionError, Timeout
@seanickle
seanickle / resize image in markdown.md
Created April 12, 2019 21:47
resize image in markdown
 <img src="https://blahblahblah/blah.png" alt="alt text" width="654" height="208">
 
@seanickle
seanickle / quick partitions .md
Last active July 12, 2019 14:15
partitions

.

import math
def get_partitions(vec, slice_size):
    assert slice_size > 0
    assert isinstance(vec, list)
    num_slices = int(math.ceil(len(vec)/slice_size))
    size_remainder = len(vec) - num_slices*slice_size
    slices = [vec[k*slice_size:k*slice_size+slice_size] for k in range(num_slices)]
@seanickle
seanickle / aws s3 copy cp .md
Created February 4, 2019 17:56
aws copy cp awscli cheat sheet

Copy from s3 to local

aws --profile blahmyprofile s3 cp  s3://mybucket/test2.txt .
@seanickle
seanickle / notes.md
Created December 26, 2018 21:39
unicode and ascii unicode error

Normalize unicode with handy vanilla python

  • note this only works for unicode and crashes if s is not unicode.
In [19]: s = u'Cañon City, cool'

In [20]: s.encode('ascii', 'replace')
Out[20]: 'Ca?on City, cool'

In [21]: s.encode('ascii', 'ignore')
Out[21]: 'Caon City, cool'