Skip to content

Instantly share code, notes, and snippets.

Oliver Lee lichengwu

Block or report user

Report or block lichengwu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View defaultdict.py
dt = {}
if "key" in dt:
dt["key"] = 1
else:
dt["key"] += 1
# 默认字典
dt = collections.defaultdict(int)
dt["key"] += 1
@lichengwu
lichengwu / LightObject.py
Created Jun 22, 2015
轻量级Python对象,更少内存占用
View LightObject.py
LightObject = namedtuple('LightObject', ['shortname', 'otherprop'])
n = LightObject(shortname='something', otherprop='something else')
n.shortname # something
@lichengwu
lichengwu / AttackJVM.md
Last active Jan 4, 2016
利用反射,攻击JVM
View AttackJVM.md

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

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

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

@lichengwu
lichengwu / InputStreamAsString
Created Dec 28, 2013
最简单的方式把一个InputStream转换成String
View InputStreamAsString
/**
* 最简单的方式把一个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 Dec 31, 2015
run shell on local/remote target
View run_command.py
#!/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 Dec 14, 2013
run jenkins shell
View jenkins.sh
#!/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 Dec 23, 2015
GarbageCollect Notification in JDK7
View GCMonitoring.java
/**
* 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 Jan 31, 2013
lazy init by placeholder(thread safe) more graceful than `double check locking`
View Resource.java
/**
* 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 Jan 12, 2013
meituan mail script for x-notifier
View meituan.js
/**********************************************************
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 Dec 10, 2015
JVM's build-in lock is not safe enough, it may cause deadlock while the build-in lock acquired by other threads.
View DoNotUseBuildInLockTest
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.
You can’t perform that action at this time.