Skip to content

Instantly share code, notes, and snippets.

View khuyentran1401's full-sized avatar
🏠
Working from home

Khuyen Tran khuyentran1401

🏠
Working from home
View GitHub Profile
@khuyentran1401
khuyentran1401 / settings.json
Created April 26, 2023 19:56
vim keyboard map settings for vscode
{
"vim.normalModeKeyBindings": [
{
"before": ["J"],
"after": ["5", "j"]
},
{
"before": ["K"],
"after": ["5", "k"]
}
from sqlalchemy import create_engine
engine = create_engine(
f"postgresql://{connection.user}:{connection.password}@{connection.host}/{connection.database}",
)
df.to_sql(name=name, con=engine, if_exists="replace", index=False)
from sqlalchemy import create_engine
engine = create_engine(
f"postgresql://{connection.user}:{connection.password}@{connection.host}/{connection.database}",
)
query = f'SELECT * FROM "{name}"'
df = pd.read_sql(query, con=engine)
@khuyentran1401
khuyentran1401 / Makefile
Last active March 23, 2022 15:42
Makefile for setting up a new environment with poetry and DVC
install:
@echo "Installing..."
poetry install
activate:
@echo "Activating virtual environment"
poetry shell
pull_data:
@echo "Pulling data..."
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/khuyen/.oh-my-zsh"
# Path to VSCOde
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
export PATH="$PATH:/Library/Python/3.9/lib/python/site-packages"
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
repos:
- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
additional_dependencies: ['click==8.0.4']
- repo: https://github.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
@khuyentran1401
khuyentran1401 / Makefile
Last active March 23, 2022 13:53
Automate Python workflow using pre-commits
pip: install_format_packages download_config add_precommit install_git_hooks
poetry: poetry_install_format_packages download_config add_precommit install_git_hooks
pip_install_format_packages:
pip install pre-commit commitizen
poetry_install_format_packages:
poetry add -D pre-commit commitizen
download_config:
wget -O .flake8 https://gist.githubusercontent.com/khuyentran1401/f4a4c822320a9db266ad935b501be66e/raw/3ebf2b029490a970591caa733dd9d2e9767b184e/.flake8
[tool.black]
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
'''
Example of Wrappers
'''
from functools import wraps
from datetime import datetime
import time
def verbose_timeit(func):
@wraps(func)