Skip to content

Instantly share code, notes, and snippets.

@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 / 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):
@michaelbrewer
michaelbrewer / setup.sh
Last active April 12, 2021 05:12
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 isort mypy --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 / 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
@wshayes
wshayes / websocket.py
Created January 19, 2020 17:06
[Websockets with fastapi] #fastapi #websockets
# https://github.com/tiangolo/fastapi/issues/883#issuecomment-575913215
# You can probably use an async queue so your MQTT client will push messages to the queue and the WS server will get from the queue and send them to the WS client.
from asyncio import Queue
queue: Queue = None
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
@wshayes
wshayes / python_example.py
Created December 24, 2019 18:46
[python multiprocessing example] writing to file from a queue #python #multiprocessing
# https://stackoverflow.com/a/13530258/886938
import multiprocessing as mp
import time
fn = 'c:/temp/temp.txt'
def worker(arg, q):
'''stupidly simulates long running process'''
start = time.clock()
@liquidgenius
liquidgenius / OmniDB.py
Last active November 22, 2019 16:26
A minimal Python class for uniform API to both Snowflake and MySQL databases.
import pymysql
import pandas as pd
from snowflake.sqlalchemy import URL as SFURL
from sqlalchemy import create_engine
from sqlalchemy.engine.url import URL
class OmniDB:
""" A minimal Python class for uniform API to both Snowflake and MySQL databases.
TODO: Error handling