Skip to content

Instantly share code, notes, and snippets.

View oldratlee's full-sized avatar
🐥
Hello world!

李鼎 oldratlee

🐥
Hello world!
View GitHub Profile
@oldratlee
oldratlee / CalcDwsMonths.py
Created November 14, 2012 10:02
Get the months which First day is monday
# find the months which First day is monday
# My related Blog: http://oldratlee.com/post/2012-11-13/1-st-day-is-monday-month-count
dayCountOfMonthOfYear = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
dayCountOfMonthOfLeapYear = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
print "Day count of non-leap year: ", sum(dayCountOfMonthOfYear)
# 365, day count of non-leap year
print "Day count of leap year: ", sum(dayCountOfMonthOfLeapYear)
# 366, day count of Leap year

多线程使用SpyMemcached Client

2013-04-26 17:16:00.017 WARN net.spy.memcached.protocol.binary.BinaryMemcachedNodeImpl:  Operation canceled because authentication or reconnection and authentication has taken more than one second to complete.
2013-04-26 17:16:00.019 WARN net.spy.memcached.MemcachedConnection:  Could not redistribute to another node, retrying primary node for test-toolkit-1366967755495.
2013-04-26 17:16:00.020 INFO net.spy.memcached.MemcachedConnection:  Reconnecting {QA sa=/10.249.194.159:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
2013-04-26 17:16:00.034 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@79de256f
2013-04-26 17:16:00.161 INFO net.spy.memcached.auth.AuthThread:  Authenticated to /10.249.194.159:11211
2013-04-26 17:16:00.163 WARN net.spy.memcached.protocol.binary.BinaryMemcachedNodeImpl:  Discarding partially completed op: Cmd: 0 Opaque: 28 Key: test-toolk
@oldratlee
oldratlee / war-extra-resources.md
Last active December 17, 2015 02:59
download file and add it to war file via maven

How to Activate

Activate

mvn install -P Profile-Download-Extra-Resources
@oldratlee
oldratlee / ssh-break-while-loop.md
Created May 10, 2013 06:46
solve the problem that ssh break the while read loop

Description

ssh break the while loop.

0</dev/null or -n option of ssh can resolve this problem.

Sample Code

@oldratlee
oldratlee / sl
Last active December 20, 2015 14:59
application starter in terminator under mac
#!/bin/bash
# open -a '/Applications/Sublime Text 2.app' "$@"
open -a 'Sublime Text 2' "$@"
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
public class HttpServerTest {
import org.junit.Test;
import java.math.BigInteger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author ding.lid
*/
@oldratlee
oldratlee / Candy.java
Last active December 24, 2015 18:49
陈利人微博题的实现代码:http://weibo.com/1915548291/AcqqPxnEp #面试题#N个孩子站成一排,每个人分给一个权重。按照如下的规则分配糖果: 每个孩子至少有一个糖果;所分配权重较高的孩子,会比他的邻居获得更多的糖果。 问题是,最少需要多少个糖果?关注微信公众账号“待字闺中”,了解更多。 http://oj.leetcode.com/problems/candy/。 PS: 现在代码移到了 https://github.com/oldratlee/leetcode/blob/master/src/main/java/candy/Solution.java
/** 通过的UT Case:
assertEquals(0, Candy.calcCandyCount(new int[]{}));
assertEquals(1, Candy.calcCandyCount(new int[]{1,}));
assertEquals(1, Candy.calcCandyCount(new int[]{100,}));
assertEquals(2, Candy.calcCandyCount(new int[]{1, 1,}));
assertEquals(3, Candy.calcCandyCount(new int[]{1, 2,}));
assertEquals(3, Candy.calcCandyCount(new int[]{2, 1,}));
@oldratlee
oldratlee / log4j.xml
Created October 10, 2013 12:36
log4j config file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</layout>
@oldratlee
oldratlee / MethodTracer.java
Last active December 28, 2015 00:18
BTrace, MethodTracer
import com.sun.btrace.AnyType;
import com.sun.btrace.annotations.Kind;
import com.sun.btrace.annotations.Location;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.ProbeMethodName;
import static com.sun.btrace.BTraceUtils.print;
import static com.sun.btrace.BTraceUtils.printArray;
/*