Skip to content

Instantly share code, notes, and snippets.

@liquidgenius
liquidgenius / gist:0e32e5230535547fa175ba2b9d7a2dff
Last active April 20, 2023 02:14
NYTElectionData: Downloads publicly available voting data from New York Times which was streamed in real-time during the 2020 elections. Data is in JSON format. Inspired by blog post: https://justamom.code.blog/2021/07/15/counting-votes/
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__license__ = "MIT"
__version__ = "0.1"
__py_version__ = "3.8.7"
__status__ = "Development"
import json
from pathlib import Path
from time import sleep
@liquidgenius
liquidgenius / PublicDevAccess.py
Last active September 19, 2022 04:23
Syntactic sugar to seamlessly integrate Pyngrok with FastApi and Uvicorn. Useful in development where remote users may need to interact with local code.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__license__ = "MIT"
__version__ = "0.0.1"
__maintainer__ = "https://github.com/liquidgenius"
__status__ = "Development"
from pathlib import Path
from pyngrok import ngrok
@liquidgenius
liquidgenius / low_pass_filter.py
Last active September 12, 2022 09:19 — forked from kperry2215/low_pass_filter.py
Implement a low-pass filter to detect anomalies in a time series, and save the filter outputs (True/False) to a new column in the dataframe.
def low_pass_filter_anomaly_detection(df: pd.DataFrame,
column_name: str,
rolling_window: int,
number_of_stdevs_away_from_mean: float):
"""
Implement a low-pass filter to detect anomalies in a time series, and save the filter outputs
(True/False) to a new column in the dataframe.
Arguments:
df: Pandas dataframe
column_name: string. Name of the column that we want to detect anomalies in
@liquidgenius
liquidgenius / scaffolder.sh
Last active November 10, 2021 12:22
A Bash based one liner for setting up Masonite 3 projects if using pyenv and pipenv. Also makes Pycharm project setup much simpler. Just select the interpreter from the in project .venv directory after opening the project directory in Pycharm. Tested on OSX Big Sur.
#! /bin/bash
# License: MIT; https://opensource.org/licenses/MIT
# Version: 0.0.1
# Maintainer: https://gist.github.com/liquidgenius
# Gist: https://gist.github.com/liquidgenius/56167cfedc7270752d207377cf618fcf
#*******************************************************************************
# Masonite 3 Project Scaffolding
@liquidgenius
liquidgenius / run.sh
Created July 23, 2021 16:10
A bash shell script for launching a python script in a pipenv envelope.
#! /bin/bash
# License: MIT; https://opensource.org/licenses/MIT
# Version: 0.0.1
# Maintainer: https://gist.github.com/liquidgenius
# Given a script main.py on an ubuntu machine in /home/ubuntu/app/src directory with the interpreter
# in /home/ubuntu/app/.venv directory in project. This script, run.sh, would be placed in the
# /home/ubuntu/app directory.
@liquidgenius
liquidgenius / pycharmer.sh
Created July 23, 2021 15:53
Create a Python project utilizing pyenv and pipenv. Easily open the project with Pycharm with the interpreter located in-project.
#! /bin/bash
# License: MIT; https://opensource.org/licenses/MIT
# Version: 0.0.1
# Maintainer: https://gist.github.com/liquidgenius
#*******************************************************************************
# Pycharmer; A Pycharm Python project creator
#*******************************************************************************
@liquidgenius
liquidgenius / app.helpers.columns.py
Last active May 23, 2021 15:58
A Masonite 3 ORM helper to get the names of the columns irrespective of the database flavor SQLite, MySQL, Postgres. Pass any model to the function. Usage details provided in function. https://orm.masoniteproject.com/
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://orm.masoniteproject.com/
# app.helpers.columns.py
from config.database import DB
from masoniteorm.collection import Collection
def columns(model):
@liquidgenius
liquidgenius / setup.sh
Created April 4, 2021 17:22 — forked from michaelbrewer/setup.sh
Setting up aws-lambda-powertools
# Ensure we have the latest pip and pipenv
pip3 install --upgrade pip pipenv
# Setup new Python 3.8 project
pipenv --python 3.8
# Install aws-lambda-powertools
pipenv install boto3 aws-lambda-powertools
# Install dev dependencies
pipenv install black pytest --dev --pre
@liquidgenius
liquidgenius / dataclass_from_dict.py
Created August 23, 2020 14:33 — forked from gatopeich/dataclass_from_dict.py
Python 3.7 dataclass to/from dict/json
from dataclasses import dataclass, fields as datafields
from ujson import dumps, loads
# Note: ujson seamlessly serializes dataclasses, unlike stdlib's json
@dataclass
class Point:
x: float
y: float
# Shallow dataclass can be rebuilt from dict/json:
@liquidgenius
liquidgenius / proxy.py
Last active October 3, 2020 15:58
Proxymesh is a Python function that proxies requests through Proxymesh's services. Just pass a qualified url and receive a Request's Response-like object in response. No error capturing is included.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from random import choice
import httpx
import fake_useragent
def Proxymesh(url, proxy_choices=None, headers=None, country='US'):