Skip to content

Instantly share code, notes, and snippets.

@ttor
ttor / pandas_dataframes_are_equal.py
Created January 12, 2022 17:06
Compare two pandas dataframes for equality, pandas_dataframes_are_equal
def pandas_dataframes_are_equal(df1, df2):
return list(sorted(df1.columns)) == list(sorted(df2.columns)) and \
len(df1.merge(df2, how="outer", indicator=True).query("_merge!='both'"))==0
@ttor
ttor / tag_volumes.py
Created September 9, 2019 11:48
Copy tags from EC2 instance to attached EBS volume
#adapted from https://gist.github.com/mlapida/931c03cce1e9e43f147b
import boto3
tags_to_use = ['Owner']
def copy_tags():
instances = boto3.resource('ec2').instances.all()
for instance in instances:
tags = instance.tags
to_tag = [t for t in tags if t['Key'] in tags_to_use]
@ttor
ttor / gist:40891d4c757cfc7f90a07f192b9c2be3
Created August 14, 2019 18:20
Install mssh for EC2 instance connect
aws s3 cp s3://ec2-instance-connect/cli/ec2instanceconnectcli-latest.tar.gz .
sudo pip3 install ec2instanceconnectcli-latest.tar.gz
mssh instanceid
@ttor
ttor / create_aws_lambda_layer_matplotlib.txt
Last active March 25, 2022 17:47
Create AWS Lambda Layer for Matplotlib (Python3.7)
sudo docker pull amazonlinux
sudo docker run -it amazonlinux:latest /bin/bash
# inside container
yum -y install python37 zip
python3 -m venv python
source python/bin/activate
pip3 install matplotlib
deactivate
rm -rf python/{bin,include,lib64,pyvenv.cfg} python/lib/python3.7/site-packages/{__pycache__,easy_install.py,numpy*,pip*,pkg_resources,setuptools*}
#/!bin/bash
# This scripts downloads images from flickr from a search results page (flickr.html).
# Sketch to generate flickr.html (in Chrome):
# Search on flickr, select Creative Commons commercial use
# Change tiling to second choice (or adapt "_n" in the processing below)
# In Inspector (ctrl-shift-I), select top <html> element, right-click: copy element
# Paste into flickr.html
# grep image references
@ttor
ttor / convert_to_ipynb.py
Created September 29, 2017 10:18
Convert .py with cells (e.g., from Hydrogen) to .ipynb
from nbformat import v3, v4
import sys
import os
infilename=sys.argv[1]
outfilename=os.path.splitext(infilename)[0]+".ipynb"
with open(infilename) as fpin:
text = fpin.read()
text=text.replace("#%%", "# <codecell>")
text=text.replace("# %%", "# <codecell>")