Skip to content

Instantly share code, notes, and snippets.

View bpgould's full-sized avatar
💭
drinking from the firehose, happily

Bennett Gould bpgould

💭
drinking from the firehose, happily
View GitHub Profile
@bpgould
bpgould / main.py
Created May 13, 2024 19:33
Find unrequited Instagram followers using python
import instaloader
L = instaloader.Instaloader()
L.login("username", "password")
# Obtain profile metadata
profile = instaloader.Profile.from_username(L.context, "username")
# people who follow you
@bpgould
bpgould / http_requests.py
Created May 21, 2023 19:50
async python http requests using exponential backoff, jitter, and event logging
"""
This module provides functionality for making HTTP requests. It leverages the `aiohttp`
library for asynchronous HTTP requests, and the `backoff` library to implement exponential
backoff in case of failed requests.
The module defines a child logger for logging purposes and implements two methods, `on_backoff`
and `on_giveup`, which log information about the retry attempts and when the retry attempts are
given up respectively.
The `http_request` function is the primary function of the module, making an HTTP request with the
@bpgould
bpgould / package.sh
Last active April 19, 2023 20:15
Create a zip archive for python lambdas that includes external dependencies from requirements.txt
#!/bin/bash
# Script to package a Lambda function directory
# into a deployment zip that can be uploaded to S3
# Usage:
# ./package.sh <lambda name/ dir name>
if ! command -v pip >/dev/null 2>&1 || ! command -v python3 >/dev/null 2>&1 || ! command -v zip >/dev/null 2>&1; then
echo "pip, python3, and/or zip are not installed"
@bpgould
bpgould / block_commit_to_main.sh
Last active February 13, 2023 02:19
block commit to main using git hooks
#!/bin/bash
protected_branch='main'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [[ "$protected_branch" = "$current_branch" ]]; then
input=''
read -p "You're about to commit to master, is that what you intended? [y|n] " -n 1 -r </dev/tty
if [[ "$input" == [yY] || "$input" == [yY][eE][sS] ]]; then
@bpgould
bpgould / list-of-curl-options.txt
Created January 31, 2023 04:54 — forked from eneko/list-of-curl-options.txt
List of `curl` options
$ curl --help
Usage: curl [options...] <url>
--abstract-unix-socket <path> Connect via abstract Unix domain socket
--alt-svc <file name> Enable alt-svc with this cache file
--anyauth Pick any authentication method
-a, --append Append to target file when uploading
--basic Use HTTP Basic Authentication
--cacert <file> CA certificate to verify peer against
--capath <dir> CA directory to verify peer against
-E, --cert <certificate[:password]> Client certificate file and password
@bpgould
bpgould / main.py
Created November 11, 2022 22:32
convert webp images to png
'''
convert webp images to png
'''
from sys import argv
from PIL import Image
# requirements: `pip install pillow`
# example usage:
# python main.py input.webp output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bpgould
bpgould / parameterized_access_policy.tf
Last active October 27, 2022 20:14
common terraform access policy for IBM cloud across different services
locals {
redis-viewer = [
ibm_database.team1-redis-us-south-uat.id,
ibm_database.team3-redis-uat.id,
ibm_database.team1-redis-us-south-prod.id
]
# Processes out the resource_instance_id
redis-viewer-processed = [for infra in local.redis-viewer : element(split(":", infra), 7)]
rabbitmq-viewer = [
@bpgould
bpgould / find_and_check_shell_files.sh
Last active October 19, 2022 14:11
Find shell files based on file content, not extension, and run shellcheck for CICD
#!/bin/bash
# finds every file in the directory specified starting with '#!' and ending with 'bash' on the same line
# i.e. #!/bin/bash this allows us to only shellcheck shell files, but this would
# have been a lot simpler if the shell files all had .sh extensions
# added --serverity option due to egregious output in CICD, valid values in order of severity are
# error, warning, info and style. The default is style.
for file in $(find source/legacy -type f -exec awk '/^#!.*bash/{r=1};{exit} END {exit(1-r)}' {} \; -print)
do
@bpgould
bpgould / parse_version_from_setuptools.sh
Last active October 27, 2022 18:00
bash regex to parse semver
#!/bin/bash
# fancy regex will parse 0.8.39, can be used to parse semver
VERSION_FROM_SETUP=$(sed -n 's/^ *version="\([^"]*\).*/\1/p' setup.py)
# example setup.py file, start multi-line comment
: '
import setuptools
import os
setuptools.setup(