Skip to content

Instantly share code, notes, and snippets.

View liushuaikobe's full-sized avatar

Shuai Liu liushuaikobe

  • Alibaba
  • Hangzhou, China
  • 13:15 (UTC +08:00)
View GitHub Profile
@liushuaikobe
liushuaikobe / BM-algorithm.py
Last active December 18, 2015 11:09
Boyer-Moore algorithm Implementation via Python.
'''
Created on 2013-6-13
@author: liushuai
'''
import time
badCharShift = {}
goodSuffixShift = {}
@liushuaikobe
liushuaikobe / Java-Singleton.java
Last active December 22, 2015 10:38
简单单例模式的实现,用JVM保证线程安全
import java.net.UnknownHostException;
import com.mongodb.DB;
import com.mongodb.MongoClient;
import com.qingcong.mobile.constant.AppConfig;
public class MongoHelper {
private MongoClient mongoClient;
private DB db;
@liushuaikobe
liushuaikobe / easy-config-Ubuntu.sh
Last active December 25, 2015 06:49
Run when Ubuntu was installed on some PC.
sudo apt-get install make
sudo apt-get install tree
sudo apt-get install unzip
sudo apt-get install htop
sudo apt-get install ntp
sudo apt-get install g++
sudo apt-get install libssl-dev
sudo apt-get install apache2
sudo apt-get install git-core
git config --global user.name liushuaikobe
import gevent.monkey
gevent.monkey.patch_all()
import time
import pymongo
connection = pymongo.Connection(use_greenlets=True)
def task():
collection = connection.autoref.all_cars
# First install tmux
brew install tmux
# For mouse support (for switching panes and windows)
# Only needed if you are using Terminal.app (iTerm has mouse support)
Install http://www.culater.net/software/SIMBL/SIMBL.php
Then install https://bitheap.org/mouseterm/
# More on mouse support http://floriancrouzat.net/2010/07/run-tmux-with-mouse-support-in-mac-os-x-terminal-app/
@liushuaikobe
liushuaikobe / datetime-operation.py
Last active December 27, 2015 07:19
Python获取当前日期,以及进行转换。
from datetime import datetime
# Get a datetime object
now = datetime.now()
# General functions
print "Year: %d" % now.year
print "Month: %d" % now.month
print "Day: %d" % now.day
print "Weekday: %d" % now.weekday() # Day of week Monday = 0, Sunday = 6
from gevent import monkey; monkey.patch_all()
import gevent
import gevent.greenlet
from functools import partial
from random import random
import urllib
import urllib2
def on_exception(fun, greenlet):
@liushuaikobe
liushuaikobe / easy-refresh.py
Last active January 3, 2016 07:28
开机时执行这个脚本,自动打开默认浏览器,然后尽情的刷一会。
import webbrowser
import os
urls = [
'http://www.douban.com',
'http://weibo.com',
'http://www.zhihu.com',
'http://www.v2ex.com/',
'https://github.com/',
'https://mail.google.com/',
function(req, res, db) {
db.collection("location").count(function(err, location_count){
db.collection("actor").count(function(err, actor_count){
db.collection("record").count(function(err, record_count){
res.json({
location_count: location_count,
actor_count: actor_count,
record_count: record_count
});
});
from datetime import datetime
import time
dt = datetime(2015, 8, 1, 0, 0, 0, 0)
timestamp = (dt - datetime(1970, 1, 1)).total_seconds()
print timestamp