Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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'):
@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 / usaddress_adapter.py
Created August 20, 2020 17:15 — forked from andersontep/usaddress_adapter.py
Normalizing addresses with the usaddress package
"""
* requires usaddress https://github.com/datamade/usaddress
* check out the website! https://parserator.datamade.us/usaddress
The usaddress package is pretty great for normalizing inconsistent address data,
especially when if you have a lot to process and can't rely on using a geocoding api.
The results are really granular, probably moreso than you'll need, and definitely
more than most CRM systems if integrating these addresses is your goal.
This is just a simple wrapper around the usaddress.tag() function that I feel will
@liquidgenius
liquidgenius / gist:956790dc251369091eccce511d61534d
Created August 8, 2020 15:37 — forked from vehrka/gist:c33c65ab366e7aec14ad
How to create hexagonal grids in PostGIS
-- Function: makegrid_epsg3857(text, text, text, numeric)
-- DROP FUNCTION makegrid_epsg3857(text, text, text, numeric);
CREATE OR REPLACE FUNCTION makegrid_epsg3857(schemaname text, boundingbox text, gridtable text, halfwidth numeric)
RETURNS text AS
$BODY$
DECLARE
tbl_cnt int;
XMIN numeric;