Skip to content

Instantly share code, notes, and snippets.

View tamsanh's full-sized avatar

Tam Nguyen tamsanh

View GitHub Profile
@tamsanh
tamsanh / get_calling_file_name.py
Created April 12, 2018 00:11
Gets the name of the calling file.
def get_calling_file_name():
# If this function is embedded in another function, offset the stack appropriately
import inspect
stack_offset = 1
stack = inspect.stack()
calling_file = stack[stack_offset][1]
return calling_file
@tamsanh
tamsanh / shifty.py
Created April 30, 2018 23:09
Python __rshift__ __lshift __rrshift__ __rlshift__ Examples and Order of Operations
# Setup Classes for the Example
class Shifter:
def __init__(self, label):
self.label = label
def __str__(self):
return str(self.label)
def __rshift__(self, other):
print("#%s.__rshift__(%s)" % (self, other))
@tamsanh
tamsanh / .ssh_config
Created June 4, 2018 02:10
Settings file to specify a specific host for a different ssh key.
Host target-repo-name.github.com
HostName github.com
User git
IdentityFile /home/ec2-user/.ssh/target-repo-name
IdentitiesOnly yes
@tamsanh
tamsanh / virtualenv_venv_quick_setup_macosx.sh
Last active September 24, 2018 21:48
virtualenv venv Quick Setup MacOSX - Python 3
# Instructions for setting up a virtualenv venv
#########
# SETUP #
#########
## Make sure you have python3
python3 --version
@tamsanh
tamsanh / dict_hash.py
Last active July 5, 2020 09:49
Consistent Dictionary Hash
import hashlib
import json
from typing import Dict, Any
def hash_dict(data: Dict[str, Any]):
data_str = json.dumps(data, sort_keys=True, default=str)
md5 = hashlib.md5()
md5.update(data_str.encode("utf-8"))
hash_value = md5.hexdigest()
return hash_value
@tamsanh
tamsanh / example_shared_catalog.yml
Created September 19, 2020 04:16
Example Shared Kedro Catalog
iris_data:
type: pandas.CSVDataSet
filepath: data/01_raw/iris.csv
@tamsanh
tamsanh / github_catalog_hook.py
Created September 19, 2020 06:46
GithubCatalogHook
from io import StringIO
from typing import Optional, Dict, Any
import yaml
from kedro.framework.hooks import hook_impl
from kedro.io import DataCatalog
from kedro.versioning import Journal
def _read_github_repo_file(access_token, repo_name, filepath, branch='master'):
@tamsanh
tamsanh / mfa_on_aws_cli.sh
Last active March 16, 2021 10:28
Multi-Factor Authentication on AWS Cli
#########################################################################################################
# Call this script locally using:
# eval "$(curl --silent https://gist.githubusercontent.com/tamsanh/92f0546322583dfd46f7d85d3510bdb7/raw)"
# This will override current AWS environment variables
#########################################################################################################
# First type in a token code that will expire after at least 20 seconds
# Ex: TOKEN_CODE=192392
read -p TOKEN_CODE= TOKEN_CODE
@tamsanh
tamsanh / setup-brew-and-asdf.sh
Last active February 23, 2023 20:58
asdf setup script
#!/bin/bash
# Install brew and asdf
# Setup Brew
brew --help > /dev/null 2>/dev/null
if [ $? -ne 0 ]; then
## Install if does not exist
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo "brew setup complete"
#!/bin/bash
# Setup based on .tool-version in the current directory
while read package; do
plugin=${package%% *}
version=${package#* }
printf "Checking ${package}... "
asdf list $plugin | grep $version >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then