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 / AttackJVM.md
Last active January 4, 2016 15:59
利用反射,攻击JVM

Java中,Integer,Long等都是有-127~128的缓存的,利用反射: 可以达到攻击目的

Field value = Integer.class.getDeclaredField("value");
value.setAccessible(true);
value.set(42, 43);

同样,String这个“不变”对象也可以:

@lichengwu
lichengwu / InputStreamAsString
Created December 28, 2013 02:42
最简单的方式把一个InputStream转换成String
/**
* 最简单的方式把一个InputStream转换成String
*
* @author lichengwu
* @version 1.0
* @created 2013-12-28 10:37 AM
*/
public class InputStreamAsString {
public static void main(String[] args) throws IOException {
@lichengwu
lichengwu / run_command.py
Last active December 31, 2015 08:28
run shell on local/remote target
#!/usr/bin/python
#encoding=gbk
__author__ = 'lichengwu'
import pexpect
import sys
import getopt
import time
import os
def run_command(ip, user, password, cmd, tmo=600):
@lichengwu
lichengwu / jenkins.sh
Created December 14, 2013 14:34
run jenkins shell
#!/bin/sh
DESC="Jenkins CI Server"
NAME=jenkins
PIDFILE=/var/run/$NAME.pid
RUN_AS=admin
COMMAND=JAVA_TOOL_OPTIONS=-Dfile.encoding=GBK /opt/taobao/java64/bin/java -jar -server -Xms2048m -Xmx2048m -XX:NewSize=320m -XX:MaxNewS
ize=320m -XX:PermSize=128m -XX:MaxPermSize=256m /usr/lib/jenkins/jenkins.war --httpPort=9000
#COMMAND=/opt/taobao/java/bin/java -jar /home/jenkins/jenkins.war
@lichengwu
lichengwu / GCMonitoring.java
Last active December 23, 2015 02:29
GarbageCollect Notification in JDK7
/**
* gc monitoring only on jdk7 or later
*
* @author lichengwu
* @version 1.0
* @created 2013-09-14 10:44 PM
*/
public class GCMonitoring {
@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() {
@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 / 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.