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 / meta.py
Created December 1, 2019 22:43
Python meta example
import time
import types
from functools import wraps
from abc import ABCMeta
def timeit(f):
@wraps(f)
def wrapper(*args, **kwargs):
start = time.time()
resp = f(*args, **kwargs)
@lorne-luo
lorne-luo / kite.py
Last active June 4, 2021 07:46
Kite Tutorial
# -*- coding: utf-8 -*-
# SHIFT+CMD+A -> Kite: Tutorial
# CMD+P to show function parameter
# Welcome to...
#
# `hmy+. ://:
# .mMMMMMNho:` NMMm
# :NMMMMMMMMMMMds/.` NMMm :ss:
@lorne-luo
lorne-luo / tools.txt
Created December 2, 2019 00:25
Online tools
https://requestbin.com/
RequestBin gives you an instant HTTP endpoint that will collect all the requests sent so that you can interpret them easily to check and validate data.
https://cloudcraft.co/
Cloudcraft helps you design and budget your cloud. It has a very cool drag and drop interface to create 3D diagrams, by connecting different cloud infrastructure services (currently only for AWS).
@lorne-luo
lorne-luo / snippet.py
Last active January 16, 2020 04:07
Python snippet
# Occurrence Counter in List
num_lst = [1, 1, 2, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3]
cnt = Counter(num_lst)
print(dict(cnt))
# first 2 most occurrence
print(dict(cnt.most_common(2)))
str_lst = ['blue', 'red', 'green', 'blue', 'red', 'red', 'green']
print(dict(Counter(str_lst)))
@lorne-luo
lorne-luo / mouse.py
Created February 11, 2020 22:07
Mouse control on Windows
# controlar o mouse no Windows.
# https://stackoverflow.com/questions/4263608/ctypes-mouse-events
# see http://msdn.microsoft.com/en-us/library/ms646260(VS.85).aspx for details
import ctypes
import time # opcional
def pos(x, y):
ctypes.windll.user32.SetCursorPos(x, y)
@lorne-luo
lorne-luo / built-in-funct.md
Created February 27, 2020 23:31
Python Built-in Functions

Built-in Functions

abs()

delattr()

hash()

@lorne-luo
lorne-luo / lambda_pyodbc_layer.sh
Created July 21, 2020 07:14
build pyodbc lambda layer
docker run -it --rm --entrypoint bash -e ODBCINI=/opt/odbc.ini -e ODBCSYSINI=/opt/ -v "$PWD":/opt lambci/lambda:build-python3.8
# install unixODBC
curl ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.7.tar.gz -O
tar xzvf unixODBC-2.3.7.tar.gz
cd unixODBC-2.3.7
./configure --sysconfdir=/opt --disable-gui --disable-drivers --enable-iconv --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE --prefix=/opt
make
make install
cd ..
@lorne-luo
lorne-luo / template_method.py
Created October 7, 2020 23:01
Python template method real case
class BitmexAPI:
# Contructor etc...
def place_order(self, order: Order):
def place_order_api_call():
size_sign = 1 if order.order_side == OrderSide.BUY else -1
result = self.__bitmex_client.Order.Order_new(symbol='XBTUSD',
orderQty=size_sign * order.size,
@lorne-luo
lorne-luo / template.yaml
Created October 15, 2020 01:34
SQS Queue as Lambda Trigger in AWS CloudFormation
AWSTemplateFormatVersion : 2010-09-09
Resources:
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
@lorne-luo
lorne-luo / airflow_install.sh
Last active November 25, 2020 08:37
Airflow installation
# https://airflow.apache.org/docs/stable/installation.html
sudo apt-get update
sudo apt-get install -y build-essential mysql-server libmysqlclient-dev libblas-dev libatlas-base-dev
sudo apt-get install -y --no-install-recommends \
freetds-bin \
krb5-user \
ldap-utils \
libffi6 \
libsasl2-2 \