Skip to content

Instantly share code, notes, and snippets.

View wirelessr's full-sized avatar

ChunTing Wu wirelessr

  • Taiwan
View GitHub Profile

Diff a file of two branches and apply to the cuurent branch

git diff HEAD other_branch -- file_name | git apply

Git log for the specific commit

git show commit

Add all modification/deleted changes to staged

git add -u

Commit all modification/deleted changes without staging

Add a column

echo "ALTER TABLE tname ADD column INTEGER UNSIGNED NOT NULL DEFAULT '0' AFTER insert_column ;" | mysql dname

Delete a colume

echo "ALTER TABLE tname DROP column ;" | mysql dname

@wirelessr
wirelessr / git_alias_diff.sh
Last active November 15, 2017 09:36
It can use 'git d' to view git diff in vimdiff
git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool
yum install gcc gcc-c++ kernel-devel make
yum groupinstall "Development Tools"
# centos 6
# yum install epel-release
yum install bash-completion
yum whatprovides libstdc++.so.6
yum install libstdc++-4.4.7-3.el6.i686
# search
rpm -qa | grep xxx
# install
rpm -i xxx
# remove
rpm -e xxx
# remove and ignore dependences
@wirelessr
wirelessr / singleton.py
Last active November 15, 2017 09:36
Use lock to guarantee thread-safe
import threading
from functools import wraps
global_singleton_lock = threading.Lock()
def singleton(cls):
instances = {}
@wraps(cls)
def getinstance(*args, **kw):
global global_singleton_lock
@wirelessr
wirelessr / named_lock.py
Last active November 21, 2017 07:20
This lock is more suitable for being a singleton or being an attribute of a singleton
import threading
import time
class ThreadLock(object):
def __init__(self):
self.namedlock = {}
self.lock = threading.Lock()
def __call__(self, name):
print 'name', name
//lockfile.c
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
int main()
@wirelessr
wirelessr / public_key_encryption.py
Last active December 6, 2017 05:44
I survey cross over the Internet, but most of information is talking about PEM. There are some using modulus and exponent to encrypt via PHP and javascript. About Python? No! No! Nothing! Thus, I tried to record the piece of code.
import binascii
import M2Crypto
import base64
'''
<RSAKeyValue>
<Modulus>xF9y25EXh8n99sXtU/JAsYTwML6PB7gSCE8tWw8Www2KBfDqohQBL8FMs8jzsDQa7WwoEmiVJ1resEC9YXJGbwQyWgb9qgooC9oSnCB/TkRdBybwby0DKuZOzq+609OBGkwWpgnS4QVCBc6eW+10l3qE3/2hKdcSV+08iRYp7zs=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
'''
for i in range(100001):
s = ((i/5000)*'#')+str(i)+(' %')
print ('\r'+s),