Skip to content

Instantly share code, notes, and snippets.

@StuffbyYuki
StuffbyYuki / logging_template.py
Created August 23, 2024 17:54
A template script for logging in Python
import logging
from datetime import datetime
TODAY = f'{datetime.today()}'.replace(':', '.')
# logger set up
logger = logging.getLogger(__name__)
logger.setLevel('DEBUG')
formatter = logging.Formatter(
'{asctime} - {levelname} - {message}',
@StuffbyYuki
StuffbyYuki / downlaod_and_install_retrosheet_data.sh
Last active May 7, 2024 20:56
Script for Downloading and Parsing Restrosheet Data
# modified what's in: https://github.com/davidbmitchell/Baseball-PostgreSQL
# install the necessary tool
brew install chadwick
# create folders
mkdir -p /path/to/retrosheet/{unparsed,parsed}
cd /path/to/retrosheet/unparsed
# you can set startDecade to whichever decade you like
@StuffbyYuki
StuffbyYuki / switching ctrl and alt
Created September 7, 2023 15:28
AutoHotkey - Yuki
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Switch alt and ctrl
LAlt::LCtrl
LCtrl::LAlt
@StuffbyYuki
StuffbyYuki / SQL Server in Docker
Created April 12, 2023 18:01
Manage SQL Server in Docker
# Run SQL server 2022 image
# user name == sa
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Yuki1031" -p 1433:1433 --name mssql --hostname mssql -d mcr.microsoft.com/mssql/server:2022-latest
# Copy data into a docker file for restoring backup
docker cp /YOURPATHTOFILE/Contoso.10k.bak mssql:/var/opt/mssql/data
@StuffbyYuki
StuffbyYuki / retry_logic.py
Created May 5, 2022 18:26
Retry logic for Python API Calls with requests package
def requests_retry_sesssion(
retries=5,
backoff_factor=1,
status_forcelist=(500, 502, 503, 504),
raise_on_redirect=True,
raise_on_status=True
):
'''
Retry logic with requests package
'''
@StuffbyYuki
StuffbyYuki / jinja.txt
Created April 5, 2022 14:46
dbt jinja - store a query result in a variable
// source website
// https://stackoverflow.com/questions/64007239/hi-how-do-we-define-select-statement-as-a-variable-in-dbt
{%- call statement('my_statement', fetch_result=True) -%}
SELECT my_field FROM my_table
{%- endcall -%}
{%- set my_var = load_result('my_statement')['data'][0][0] -%}
@StuffbyYuki
StuffbyYuki / text.txt
Created March 19, 2022 22:14
Show a list of aws profiles configured on cli
aws configure list-profiles
@StuffbyYuki
StuffbyYuki / write_history.py
Created March 6, 2022 05:26
Python Shell - output history to a file
import readline
import os # don't necessarily need
filePath = os.path.expanduser('~/Downloads/my_history.py') # don't necessarily need
readline.write_history_file(filePath) # don't necessarily need
# or you can simply do
readline.write_history_file('your_file.py')
@StuffbyYuki
StuffbyYuki / .vimrc
Created March 5, 2022 19:20
My Vim Configuration
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab
" Add line numbers
set number
" syntax enabled
@StuffbyYuki
StuffbyYuki / myPandasql.py
Last active March 5, 2022 18:50
Pandasql snipet - getting started
from pandasql import sqldf
from pandasql import load_meat, load_births # import data
mysql = lambda q: sqldf(q, globals())
meat = load_meat()
birth = load_births()
# start sql queries in pandas
mysql('select * from meat limit 5')