Skip to content

Instantly share code, notes, and snippets.

View tsonglew's full-sized avatar
:atom:
I may be slow to respond.

Tsonglew tsonglew

:atom:
I may be slow to respond.
View GitHub Profile
@tsonglew
tsonglew / multiple_rand_insert.sql
Created September 3, 2018 06:28
mysql insert multiple random rows
DELIMITER $$
DROP PROCEDURE IF EXISTS test_mysql_while_loop$$
CREATE PROCEDURE test_mysql_while_loop()
BEGIN
DECLARE x INT;
DECLARE str VARCHAR(255);
SET x = 1;
SET str = '';
@tsonglew
tsonglew / infinite.py
Created September 4, 2018 05:46
python infinite loop
#!/usr/bin/python3
for i in iter(int, 1):
...
@tsonglew
tsonglew / vis-cnn.py
Created March 30, 2019 13:02
cnn model feature channel visualization
activation_model = keras.models.Model(inputs=model.input, outputs=[layer.output for layer in model.layers])
layer_names = []
for layer in model.layers[:8]:
layer_names.append(layer.name)
images_per_row = 8
for layer_name, layer_activation in zip(layer_names, activations):
n_features = layer_activation.shape[-1]
size1 = layer_activation.shape[1]
@tsonglew
tsonglew / gan.py
Created August 6, 2019 02:50
GAN keras sample
class GAN():
def __init__(self):
self.img_rows = 28
self.img_cols = 28
self.channels = 1
self.img_shape = (self.img_rows, self.img_cols, self.channels)
optimizer = Adam(0.0002, 0.5)
# Build and compile the discriminator
@tsonglew
tsonglew / ci.yml
Created September 2, 2019 12:07
python gitlab ci
image: "python:3.7"
before_script:
- python --version
- pip install -r requirements.txt
stages:
- Static Analysis
- Test
@tsonglew
tsonglew / migrate_db.py
Created November 21, 2019 01:27
migrate data between connections
import pymysql
db_conf_dev = {
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': 3307
}
db_conf_prod = {
@tsonglew
tsonglew / mongo_remove_dup.js
Created November 21, 2019 01:32
this gist is illustrated in mongodb script
// https://stackoverflow.com/questions/14184099/fastest-way-to-remove-duplicate-documents-in-mongodb
var duplicates = [];
db.getCollection("appstore").aggregate([
{ $match: {
game: { "$eq": 'yyygg' } // discard selection criteria
}},
{ $group: {
_id: { userReviewId: "$userReviewId"}, // can be grouped on multiple properties
@tsonglew
tsonglew / copy_redis_keys.sh
Created December 23, 2019 07:42
copy key from a redis to another
#set connection data accordingly
source_host=*.*.*.*
source_port=6379
target_host=*.*.*.*
target_port=6379
passwd=redisPasswd
key=testKey
redis-cli --raw -h $source_host -p $source_port -a $passwd DUMP "$key" | head -c -1 | redis-cli -x -h $target_host -p $target_port -a $passwd RESTORE "$key" 0
@tsonglew
tsonglew / sources.list
Last active November 18, 2020 11:39
ubuntu apt etc/apt/sources.list by 163
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
@tsonglew
tsonglew / morris-traversal.go
Created January 20, 2020 14:55
morris traversal go implementation
package main
import (
"fmt"
)
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode