Skip to content

Instantly share code, notes, and snippets.

View lichengwu's full-sized avatar

Oliver Lee lichengwu

View GitHub Profile
@lichengwu
lichengwu / defaultdict.py
Created June 22, 2015 00:35
字典默认值
dt = {}
if "key" in dt:
dt["key"] = 1
else:
dt["key"] += 1
# 默认字典
dt = collections.defaultdict(int)
dt["key"] += 1
@lichengwu
lichengwu / LightObject.py
Created June 22, 2015 00:28
轻量级Python对象,更少内存占用
LightObject = namedtuple('LightObject', ['shortname', 'otherprop'])
n = LightObject(shortname='something', otherprop='something else')
n.shortname # something
@lichengwu
lichengwu / Crash.java
Created June 2, 2012 15:25
diff Xss & ThreadStackSize
import java.util.concurrent.TimeUnit;
import sun.dc.pr.PathDasher;
public class Crash {
public static void main(String[] args) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
/*
* Copyright (c) 2010-2011 lichengwu
* All rights reserved.
*
*/
package oliver.test.sync;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
@lichengwu
lichengwu / generic type erased
Created September 14, 2012 05:20
when will generic type be erased
when you declare generic type, you can get it. when you use generic type, it will be erased. eg:
public class Generics {
public <T> T m1(T object){
return object;
}
public void m2(){
List<Integer> list = new ArrayList<Integer>();
list.add(1);
@lichengwu
lichengwu / default.vcl
Created September 28, 2012 00:35
intranet cache config
#This is a basic VCL configuration file for varnish. See the vcl(7)
#man page for details on VCL syntax and semantics.
#
#Default backend definition. Set this to point to your content
#server.
#
backend default {
.host = "hostname1.com";
#.host = "meituan.com";
#.host = "debug.ct.dev.sankuai.com";
@lichengwu
lichengwu / jvm.cfg
Created December 21, 2012 16:19
my jvm command line options
-server
-Xverify:none
-Xmn512m
-Xms1024m
-Xmx1024m
-Xss1m
-XX:PermSize=256
-XX:MaxPermSize=384m
-XX:+UseG1GC
-XX:MaxGCPauseMillis=300
@lichengwu
lichengwu / DoNotUseBuildInLockTest
Last active December 10, 2015 01:48
JVM's build-in lock is not safe enough, it may cause deadlock while the build-in lock acquired by other threads.
package oliver.test.conurrency;
import java.util.Date;
import java.util.concurrent.TimeUnit;
/**
* do not use build-in lock
*
* if a class use build-in lock ensure concurrence access it's field, thread
* will be blocked by other threads who had acquired the lock.
@lichengwu
lichengwu / meituan.js
Created January 12, 2013 10:43
meituan mail script for x-notifier
/**********************************************************
mail.meituan.com
@author:lichengwu
@created:2013-01-11
@version:1.0
**********************************************************/
var name="Meituan Mail";
var ver="2013-01-11";
function init(){
@lichengwu
lichengwu / Resource.java
Created January 31, 2013 14:29
lazy init by placeholder(thread safe) more graceful than `double check locking`
/**
* lazy init by placeholder(thread safe)
*
* @author lichengwu
* @version 1.0
* @created 2013-01-31 10:19 PM
*/
public class Resource {
public static Resource getInstance() {