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 / demo.py
Created February 12, 2019 00:54
Algorithm template on Quantopian
"""
This is a template algorithm on Quantopian for you to adapt and fill in.
"""
import quantopian.algorithm as algo
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.filters import QTradableStocksUS
def initialize(context):
@lorne-luo
lorne-luo / debug_decorators.py
Last active February 25, 2019 03:15
Python decorators for debug
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 / update_ssh_banlist.py
Last active March 12, 2019 03:21
update ssh banlist on centos
import subprocess
bashCommand = '''
last | awk '{ print $1"|"$3 }'
'''
process = subprocess.Popen(bashCommand,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
output, error = process.communicate()
lines=output.split('\n')
@lorne-luo
lorne-luo / tank.py
Created April 1, 2019 02:12
Germen Tank Problem
from collections import Counter
class Tank():
def __init__(self, value):
self.tab = dict(Counter(value))
def mult(self, x, factor):
self.tab[x] = self.tab[x] * factor
@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.
@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 / 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 / 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 / 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 / .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