Skip to content

Instantly share code, notes, and snippets.

View wangchen's full-sized avatar
🐣
On vacation

wangchen wangchen

🐣
On vacation
  • China
View GitHub Profile
@wangchen
wangchen / t.py
Last active August 5, 2016 05:16
Safe in/decreasing value without select-for-update
from sqlalchemy import Column, Integer, String
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import logging
logging.basicConfig()
Base = declarative_base()
@wangchen
wangchen / redis-mem-chk
Last active July 29, 2016 09:24
Print size of all redis keys
import redis
r = redis.Redis()
i = 0
chunk_size = 1000
while True:
i, keys = r.scan(i, count=chunk_size)
if i == 0:
break
pipeline = r.pipeline()
@wangchen
wangchen / iconv-all.sh
Last active January 28, 2016 11:10
iconv all files from GBK to UTF-8
#!/bin/sh
SUFFIX="iconv-all-backup"
function convert()
{
n_total=0
n_error=0
while read f; do
fb="$f.$SUFFIX"
@wangchen
wangchen / iterm2.zsh
Last active November 3, 2021 16:11
# Usage:
# Change profile when using ssh.
# You MUST define a profile named 'ForSSH' with diferent settings.
# I am using color schemes with different background color.
# Then:
# $ save as ~/.iterm2.zsh
# $ echo ". ~/.iterm2.zsh" >> ~/.zshrc
# iTerm2 window/tab color commands
# Requires iTerm2 >= Build 1.0.0.20110804
@wangchen
wangchen / iterm2.zsh
Last active August 29, 2015 14:26 — forked from wadey/iterm2.zsh
Change iTerm2 tab color when using SSH
# Usage:
# source iterm2.zsh
# iTerm2 window/tab color commands
# Requires iTerm2 >= Build 1.0.0.20110804
# http://code.google.com/p/iterm2/wiki/ProprietaryEscapeCodes
tab-color() {
echo -ne "\033]6;1;bg;red;brightness;$1\a"
echo -ne "\033]6;1;bg;green;brightness;$2\a"
echo -ne "\033]6;1;bg;blue;brightness;$3\a"
@wangchen
wangchen / gist:cae150fa3d3d01f8396e
Created July 9, 2015 06:21
combined 'cat' and 'zcat' in one line
#!/bin/sh
for f in "$@"
do
test ${f: -3} = ".gz" && c="zcat" || c="cat"
$c $f
done
@wangchen
wangchen / check_gzip
Last active August 29, 2015 14:16
check the gzip on/off
#!/bin/sh
if [ "$#" -lt 1 ]; then
echo "Usage: check_gzip <url>"
fi
b=$(curl "$1" --silent --write-out "%{size_download}\n" --output /dev/null)
a=$(curl "$1" --silent -H "Accept-Encoding: gzip,deflate" --write-out "%{size_download}\n" --output /dev/null)
if [ "$a" > "$b" ]; then
exit 0
./configure \
--prefix=/data1 \
--sysconfdir=/data1/etc/php \
--with-config-file-path=/data1/etc/php \
--with-config-file-scan-dir=/data1/etc/conf.d \
--with-iconv \
--enable-ftp \
--enable-sockets \
--enable-zip \
--enable-shmop \
@wangchen
wangchen / asyncore-alarm.py
Created October 13, 2014 10:05
asyncore alarm
# encoding: utf-8
import asyncore
import socket
import signal
class SignalDispatcher(asyncore.dispatcher):
def __init__(self):
asyncore.dispatcher.__init__(self)
# 0 for read, 1 for write
self.pipefd = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)
@wangchen
wangchen / demo.php
Created April 25, 2014 14:25
refectory
<?php
$mem = null;
$my = null;
/**
* Create tables
* @param array $tbl_num_list example: [100, 100, 100]
*/
function create_tables ($tbl_num_list) {