Skip to content

Instantly share code, notes, and snippets.

View lorne-luo's full-sized avatar

Lorne Luo lorne-luo

  • Melbourne, Australia
View GitHub Profile
@lorne-luo
lorne-luo / test.py
Created September 1, 2019 22:49
programmatically run unit test
suite = unittest.TestLoader().loadTestsFromTestCase(TestMultiplyBy5Operator)
unittest.TextTestRunner(verbosity=2).run(suite)
@lorne-luo
lorne-luo / pre-commit.sh
Created July 4, 2019 00:22
Git commit hook for python formatter black
#!/bin/sh
# see black https://github.com/python/black
set -e
if which black >/dev/null; then
REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
files=$((git diff --cached --name-only --diff-filter=ACMR | grep -Ei "\.py$") || true)
@lorne-luo
lorne-luo / bash.sh
Last active December 3, 2019 18:15
machine learning inference with AWS Lambda and Layers
pipenv lock -r > requirements.txt
zip -r MyMLfunction_layer1.zip python
aws s3 cp MyMLfunction_layer1.zip s3://mybucket/layers/
# layer 1
aws lambda publish-layer-version --layer-name MyMLfunction_layer1 --content S3Bucket=mybucket,S3Key=layers/MyMLfunction_layer1.zip --compatible-runtimes python3.6
# layer 2
@lorne-luo
lorne-luo / new_database.sql
Last active March 5, 2020 02:12
Postgres initial
create database thor2;
create user thor2 with encrypted password 'thor2';
grant all privileges on database thor2 to thor2;
@lorne-luo
lorne-luo / .gitconfig
Created May 29, 2019 02:26
gitconfig
[user]
name = Lorne
email = [email protected]
[alias]
# BASIC
cl = clone
ci = commit -m
mg = merge
st = status
co = checkout
@lorne-luo
lorne-luo / Centos7 setup.sh
Last active October 3, 2019 02:55
Centos7 init
# os lib
sudo yum update
sudo yum groupinstall "Development Tools"
sudo yum install -y gcc gcc-c++ git zlib zlib-devel libffi-devel openssl-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel findutils
# pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
@lorne-luo
lorne-luo / oauth.py
Created May 2, 2019 05:04
oauth with python
import requests
import json
import uuid
from flask_oauthlib.client import OAuthRemoteApp
from flask_oauthlib.utils import to_bytes
from jose import jws
from oauthlib.oauth2 import WebApplicationClient
try:
@lorne-luo
lorne-luo / post-receive
Created April 29, 2019 10:20
Templates for Git hooks script
#!/bin/bash
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ]; then
sudo git --git-dir=/home/git/ozsales.git --work-tree=/opt/ozsales checkout -f master >/dev/null
cd /opt/ozsales
PIP=/home/luotao/venv/ozsales/bin/pip
@lorne-luo
lorne-luo / debug.py
Created April 14, 2019 23:35
debug decorators
import time
import pprint
import functools
from functools import wraps
def repeat(num_times=1):
def decorator_repeat(func):
@functools.wraps(func)
def wrapper_repeat(*args, **kwargs):
@lorne-luo
lorne-luo / Neural Network from Scratch with PyTorch.ipynb
Created April 13, 2019 05:26
Neural Network from Scratch with PyTorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.