Skip to content

Instantly share code, notes, and snippets.

@hktonylee
hktonylee / parse_standard_chartered_csv.py
Created March 7, 2018 07:28
parse_standard_chartered_csv.py
#!/usr/bin/env python3
import os
import re
import argparse
ACCOUNT_FILE_NAME_EX = re.compile(r'AccountTransactions\d+.csv')
CARD_FILE_NAME_EX = re.compile(r'CardTransactions\d+.csv')
PAYMENT_LINE_EX = re.compile(r'^\d{2}/\d{2}/\d{4},PAYMENT - THANK YOU,')
TRANSACTION_LINE_EX = re.compile(r'^\t\t\t\t\t\t\t\t\t\t\t')
@hktonylee
hktonylee / run-service.sh
Created December 1, 2017 02:12
Run multiple service in one script
#!/usr/bin/env bash
updateRate=1
shutdown() {
updateRate=0.2
for pid in $(jobs -p); do
pkill -TERM -P "$pid"
@hktonylee
hktonylee / manage.py
Last active December 19, 2018 21:41
Flask + manage.py + gunicorn + auto-reload + Flask-Sockets + anything you can do with gunicorn script
#!./venv/bin/python3
import os
import sys
import subprocess
from flask_migrate import MigrateCommand
from flask_script import Manager, Command, Option
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@hktonylee
hktonylee / replace_node_modules_buildToolsVersion.sh
Last active April 29, 2017 04:43
Replace buildToolsVersion in all build.gradle in node_modules
#!/usr/bin/env bash
targetVersion="$1"
if [ "$1" == "" ]; then
echo "Usage: $0 <buildToolsVersion>";
else
find \
node_modules \
-type f \
@hktonylee
hktonylee / index.d.ts
Created November 27, 2016 16:50
Typescript Typing Definition for react-native-fbsdk
declare module "react-native-fbsdk" {
export interface LoginResult {
isCancelled: boolean,
grantedPermissions?: Array<string>,
declinedPermissions?: Array<string>,
}
export type DefaultAudience = 'friends' | 'everyone' | 'only_me';
export type LoginBehaviorIOS = 'native' | 'browser' | 'system_account' | 'web';
#!/bin/sh
exec scala "$0" "$@"
!#
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world! " + args.toList)
}
}
HelloWorld.main(args)
@hktonylee
hktonylee / spawn.sh
Created October 23, 2014 09:33
Fork Processes in Shell (With Smart Cleanup)
ALL_PIDS=()
on_die() {
for pid in "${ALL_PIDS[@]}"; do
echo "Killing $pid..."
kill -9 $pid
done
}
add() {
@hktonylee
hktonylee / check.py
Created October 23, 2014 09:19
Check ZeroMQ Version in Python
from zmq import zmq_version_info; print zmq_version_info()
@hktonylee
hktonylee / run.sh
Last active August 29, 2015 14:04
Run task/daemon in the background
#!/bin/bash
# **** You may add `exec` ****
# eg.
# exec python manage.py runserver 0.0.0.0:9000
@hktonylee
hktonylee / backup.sh
Last active August 29, 2015 14:03
Regularly backup mysql
#!/bin/bash
# Configs
MY_HOST='localhost' # the host of this script
BACKUP_MATRIX=(
"localhost;userName;password;dbName"
)