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 / 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 / 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 / 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 / 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 / xp.py
Last active December 19, 2018 21:56
Wows XP Calculator
def xp(exp_flag, free_exp_flag, exp=4000, first_victory=0.5, is_premium=True):
premium_ratio = 1.5 if is_premium else 1
xp_ratio = 1 + exp_flag + 0.07
if first_victory:
xp_ratio += first_victory
base_exp = exp * premium_ratio * xp_ratio
return int(base_exp), int(base_exp * 0.05 * (1 + 0.2 + free_exp_flag))
# XP Free Captain
# Spring Sky 2 7.77
@lorne-luo
lorne-luo / django inline formset2.diff
Last active May 8, 2019 01:35
django inline formset version2
--- b/apps/product/forms.py
+
+class ProductAnalysisInlineForm(forms.ModelForm):
+ class Meta:
+ model = ProductAnalysis
+ fields = '__all__'
+
+ def __init__(self, *args, **kwargs):
+ super(ProductAnalysisInlineForm, self).__init__(*args, **kwargs)
+ for field_name in self.fields:
@lorne-luo
lorne-luo / .bash_profile
Created May 15, 2018 02:46
.bash_profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@lorne-luo
lorne-luo / django inline formset.diff
Last active May 22, 2018 23:10
django inline formset with jquery.formset.js
--- b/apps/product/forms.py
+
+class ProductAnalysisInlineForm(forms.ModelForm):
+ class Meta:
+ model = ProductAnalysis
+ fields = '__all__'
+
+ def __init__(self, *args, **kwargs):
+ super(ProductAnalysisInlineForm, self).__init__(*args, **kwargs)
+ for field_name in self.fields:
@lorne-luo
lorne-luo / documentation process.md
Created April 24, 2018 05:46
[Butterfly] Documentation process

For each project, dev team should have two kinds of documentation:

  1. documentation for project
  2. documentation for problem-solving which could share with team

Documentation for project

This part should be done in README.md of project root, the content should include:

  1. How to setup/config/build/test/deploy
  2. Brief architecture design
  3. Note for third-party service integration
  4. Troubleshooting
@lorne-luo
lorne-luo / post-receive
Last active June 2, 2018 11:11
Git hooks for deployment
#!/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}/venv/ozsales/bin/pip