Skip to content

Instantly share code, notes, and snippets.

View edthrn's full-sized avatar

ed edthrn

View GitHub Profile
@edthrn
edthrn / remove-from-git.sh
Created February 10, 2021 20:15
Remove old data from Git repo and Git history
# Taken from https://docs.github.com/en/github/authenticating-to-github/removing-sensitive-data-from-a-repository
# Warning:
# --------
# All stashes may be lost!
PATH_TO_REMOVE=big-folder/commited/by/error
# 1. Force Git to process, but not check out, the entire history of every branch and tag
# 2. Remove the specified file, as well as any empty commits generated as a result
@edthrn
edthrn / execute.py
Last active January 26, 2023 18:08
Execute Shell command on EC2 Linux instance with Python and Boto3
# Following https://stackoverflow.com/questions/34028219/how-to-execute-commands-on-aws-instance-using-boto3
import boto3
ssm = boto3.client('ssm')
response = ssm.send_command(
InstanceIds=['i-abcde12345...'],
DocumentName='AWS-RunShellScript',
Parameters={'commands': ['echo "This command ran on $(date)"']
)
@edthrn
edthrn / 1-Unit-testing with PyGithub.md
Last active October 19, 2023 05:09
Unit-testing with PyGithub

Intro

Lately, I've been building a Python platform that relies heavily on interactions with Github. Instead of re-inventing the wheel, I decided to go with PyGithub as a wrapper around Github v3 API.

The problem

This library implements the full API, which allows me to be very productive when I need to add a workflow in my platform that involves Github. However, it quickly became a real PITA to write unit tests. Even if the package comes with its own testing Framework, it is not documented yet and I didn't manage to crack it up in a decent amount of time.

I decided to hack the testing a little bit, using another very cool package, httpretty. Httpretty allows you to monkey patch the socket module during testing, so you can respond anything you want to any kind of network requests. Here's what I came up with, do not hesitate to give any feedback.