Skip to content

Instantly share code, notes, and snippets.

@liquidgenius
liquidgenius / postgres-cheatsheet.md
Created August 7, 2020 14:20 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@liquidgenius
liquidgenius / logging.py
Created February 24, 2020 23:02 — forked from kingspp/logging.py
Python Comprehensive Logging using YAML Configuration
import os
import yaml
import logging.config
import logging
import coloredlogs
def setup_logging(default_path='logging.yaml', default_level=logging.INFO, env_key='LOG_CFG'):
"""
| **@author:** Prathyush SP
| Logging Setup
@liquidgenius
liquidgenius / logging.py
Created February 21, 2020 01:32 — forked from vtemian/logging.py
logging flask
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {},
'formatters': {
'syslog': {
'format': '%(asctime)s ' + HOSTNAME_SHORT +
' %(name)s: %(levelname)s: %(message)s',
'datefmt': '%b %d %H:%M:%S',
}
@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 / ExternalAccess.py
Created February 7, 2020 04:46
ExternalAccess provides convenience methods for using PyNgrok with FastAPI.
from pathlib import Path
from pyngrok import ngrok
class ExternalAccess:
""" ExternalAccess provides convenience methods for using PyNgrok with FastAPI. It assumes
you have a custom NGROK config file at resources/ngrok.yml. Pyngrok install is required:
https://pyngrok.readthedocs.io/en/latest/
USAGE:
@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
@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 / delete_expired_files.py
Created October 14, 2019 17:33
A Python function using Pathlib that checks for all files in a given directory and if the creation day of a file is greater than a specified number of days into the past and deletes the file if it has expired.
from datetime import datetime
from pathlib import Path
def remove_expired_files(file_path, expiry_days=60, use_UTC=False):
""" Checks if the creation day of a file is greater than the file_expiry_days and deletes it if it is.
:param file_path: Pathlib.Path: The path to a file
:param expiry_days: int: Age in days after which the file should be deleted
:param use_UTC: bool: Flag to determine if now should be in UTC time, defaults to False.
:return: None
@liquidgenius
liquidgenius / install-docker.md
Created July 26, 2019 16:08 — forked from npearce/install-docker.md
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command
@liquidgenius
liquidgenius / python-parsing-dates.py
Created May 28, 2019 00:23 — forked from aviafelix/python-parsing-dates.py
Python datetime / dateutil parsing dates example
import datetime
import dateutil.parser
timestring1 = '2007-03-04T21:08:12.127'
timestring2 = '2012-03-04 12:08:12.354'
dt1 = datetime.datetime.strptime(timestring1, '%Y-%m-%dT%H:%M:%S.%f')
dt2 = datetime.datetime.strptime(timestring2, '%Y-%m-%d %H:%M:%S.%f')
dup1 = dateutil.parser.parse(timestring1)
dup2 = dateutil.parser.parse(timestring2)