Skip to content

Instantly share code, notes, and snippets.

@hktonylee
hktonylee / domMouseClickEvent.js
Last active December 13, 2015 23:39
Use Javascript to fire DOM mouse click events
function fireEvent(obj,evt) {
var evObj = document.createEvent('MouseEvents');
evObj.initEvent(evt, true, false );
obj.dispatchEvent(evObj);
}
// fireEvent(document.getElementById('someID'), 'click');
@hktonylee
hktonylee / Django Multilingual Model.md
Last active December 20, 2015 01:49
django-hvad Sample Code

I tried the first 2 items from Django Packages. And I found that django-hvad is better for me.

@hktonylee
hktonylee / mysqlOperations.sh
Last active December 20, 2015 01:49
MySQL Basic Operations
# create user
mysql -uroot -e "create user '$YOUR_NAME'@'localhost' identified by '$YOUR_PASS'"
# create database
mysql -uroot -e "create database $YOUR_DB_NAME character set utf8 collate utf8_general_ci;"
# grant privileges
mysql -uroot -e "grant all privileges on $YOUR_DB_NAME.* to '$YOUR_NAME'@'localhost' with grant option;"
| Location | Time (HKT) | Ping | Down | Up |
| ------------------- | ---------------- | ---- | ------ | ------ |
| STC, HK | 2014/03/16 09:26 | 33 | 189.07 | 191.74 |
| STC, HK | 2014/03/16 22:36 | 32 | 135.39 | 111.48 |
| Far Eastone, Taipei | 2014/03/16 22:36 | 62 | 93.03 | 10.20 |
| Telstra, Sydney | 2014/03/16 22:38 | 133 | 50.56 | 36.65 |
| SoftLayer, Seattle | 2014/03/16 22:42 | 199 | 54.26 | 78.77 |
| Namesco, London | 2014/03/16 22:46 | 295 | 3.38 | 3.94 |
| London Web, London | 2014/03/16 22:48 | 362 | 0.68 | 1.12 |
@hktonylee
hktonylee / raw_result.txt
Last active August 29, 2015 14:02
Simple Performance Comparison Between Swift, C and Java
test1.swift
==========================================
Run #1
------
real 0m0.356s
user 0m0.352s
sys 0m0.003s
Run #2
@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"
)
@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 / 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 / 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() {
#!/bin/sh
exec scala "$0" "$@"
!#
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world! " + args.toList)
}
}
HelloWorld.main(args)