Skip to content

Instantly share code, notes, and snippets.

View jeffmylife's full-sized avatar
🌊
back to learning

Jeffrey Lemoine jeffmylife

🌊
back to learning
View GitHub Profile
@jeffmylife
jeffmylife / colorized_voronoi.py
Last active June 25, 2019 18:46 — forked from pv/colorized_voronoi.py
Colorized Voronoi diagram with Scipy, in 2D, including infinite regions
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import Voronoi
def voronoi_finite_polygons_2d(vor, radius=None):
"""
Reconstruct infinite voronoi regions in a 2D diagram to finite
regions.
Parameters
@jeffmylife
jeffmylife / memorySequence.py
Created March 30, 2020 20:35
List with the ability to forget values. Kind of like a real-time sliding window.
class memorySequence(list):
def __init__(self, lst, size=10):
super().__init__(lst)
self._desired_size = size
def append(self, item):
if len(self) + 1 > self._desired_size:
del self[0]
return super().append(item)
return super().append(item)
@jeffmylife
jeffmylife / s3_multipart_upload.py
Last active October 21, 2022 22:19 — forked from teasherm/s3_multipart_upload.py
S3 Multipart Upload from request.file
'''
See comments for description & usage instructions.
'''
import boto3, botocore
from .config import S3_KEY, S3_SECRET, S3_BUCKET, S3_LOCATION
def get_file_size(file):
file.seek(0, os.SEEK_END)
@jeffmylife
jeffmylife / aws_fargate_docker_application_load_balancer_without_public_ip.md
Last active September 25, 2020 19:22 — forked from jonashaag/aws_fargate_docker_application_load_balancer_without_public_ip.md
AWS Fargate Docker Application Load Balancer How to (without public IP)

AWS Fargate Docker Simple Deployment Setup with SSL termination

How to:

  • create a Docker-based AWS Fargate/ECS deployment
  • without the Docker containers having a public IP
  • with an Application Load Balancer as reverse proxy / SSL termination proxy sitting in front of the containers

For Fargate/ECS to be able to access your Docker images hosted on ECR (or somewhere else) you'll have to allow outbound internet access to the Fargate subnets. Here's how you do it.

@jeffmylife
jeffmylife / DynamoSession.py
Created October 1, 2020 23:29 — forked from awesomebjt/DynamoSession.py
Store your Flask sessions in DynamoDB - Python 3.5
from uuid import uuid4
from datetime import datetime, timedelta
from flask.sessions import SessionInterface, SessionMixin
from werkzeug.datastructures import CallbackDict
import boto3
class DynamoSession(CallbackDict, SessionMixin):
def __init__(self, initial=None, sid=None):
CallbackDict.__init__(self, initial)
@jeffmylife
jeffmylife / routes.py
Last active October 6, 2020 00:19
Python dict to Javascipt JSON object with Jinja templating
@app.route("/testing")
def test_json():
some_dict = {
's':"some_stringy",
'bool':True,
'lst':[1,2,3],
}
return render_template("some.html", python_dict=some_dict)
@jeffmylife
jeffmylife / s3_to_rds.py
Last active November 18, 2020 23:26
Transfer a large csv file on S3 to RDS Serverless through lambda function.
import csv
import json
import os
import boto3
import botocore.response
from pprint import pprint
MINIMUN_REMAINING_TIME_MS = int(os.getenv('MINIMUM_REMAINING_TIME_MS') or 10000)
@jeffmylife
jeffmylife / aliasinate.py
Created March 16, 2021 23:51
Standardizes duplicate id's with different equivalent names, aka aliases, to an easier object.
import itertools
from operator import itemgetter
def aliasinate(lst, sep=';') -> dict:
'''
Parameters
----------
lst : list
List of strings containing aliases in any order or combination.
@jeffmylife
jeffmylife / autodockvina_steps.sh
Last active June 28, 2021 17:51
Getting autodock vina to work in MacOS 11 Big Sur
## NOTE: I wouldn't run this script by itself.
# install vina
tar xzvf autodock_vina_1_1_2_mac_64bit.tar.gz
cd autodock_vina_1_1_2_mac_catalina_64bit
./installer.sh
mv bin/vina /usr/local/bin
# test
@jeffmylife
jeffmylife / async_download_images.py
Last active May 12, 2023 19:28
Async GET request for images using aiohttp
import re
import asyncio
from io import BytesIO
import time
from pathlib import Path
from PIL import Image
import aiohttp
import requests