This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def enum(*sequential, **named): | |
""" 创建自定义枚举类型,支持两种用法: | |
1. enum('Success', 'Failed') | |
会从0开始给Success,Failed分配0,1两个值 | |
2. enum(on=1, off=0) | |
指定on,off两个枚举的值 | |
创建枚举类之后,可以通过调用 set_alias 方法设置枚举值对应的别名, 然后通过 get_alias 获取某个枚举值对应的别名 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#coding: utf-8 | |
import os | |
import shlex | |
import subprocess | |
import signal | |
import functools | |
import logging | |
import tornado |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export LANG="zh_CN.UTF-8"; | |
export LC_ALL="zh_CN.UTF-8"; | |
LOG_FILE="/tmp/jkiller.log"; | |
JSTACK_FILE="/tmp/jstack.log"; | |
PID="$1"; | |
shift; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adapted from here: https://gist.github.com/489093 | |
# Original credit goes to pplante and copyright notice pasted below | |
# Copyright (c) 2010, Philip Plante of EndlessPaths.com | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FailoverNodeLocator implements NodeLocator { | |
private MemcachedNode[] nodes; | |
public FailoverNodeLocator(List<MemcachedNode> n) { | |
assert n.size() > 1; | |
nodes = n.toArray(new MemcachedNode[n.size()]); | |
} | |
public FailoverNodeLocator(MemcachedNode[] n) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void startClusterServer(String name, int id, int port) { | |
String dataDir = "./zk/" + name; | |
File dataDirectory = new File(dataDir); | |
if (!dataDirectory.exists()) | |
dataDirectory.mkdirs(); | |
File myIdFile = new File(dataDirectory, "myid"); | |
if (!myIdFile.exists()) { | |
IO.write(String.valueOf(id).getBytes(), myIdFile); | |
} | |
Properties prop = new Properties(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Method; | |
import java.nio.ByteBuffer; | |
import java.security.AccessController; | |
import java.security.PrivilegedAction; | |
/** | |
* {@link DirectByteBufferCleaner} | |
* | |
* @author zhongl | |
* @created 2011-1-14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r a0c46f1a4e8b src/main/java/org/jboss/netty/channel/socket/DefaultSocketChannelConfig.java | |
--- a/src/main/java/org/jboss/netty/channel/socket/DefaultSocketChannelConfig.java Thu Jun 02 14:13:48 2011 +0800 | |
+++ b/src/main/java/org/jboss/netty/channel/socket/DefaultSocketChannelConfig.java Thu Jun 02 16:55:06 2011 +0800 | |
@@ -17,6 +17,7 @@ | |
import java.net.Socket; | |
import java.net.SocketException; | |
+import java.util.concurrent.TimeUnit; | |
import org.jboss.netty.channel.ChannelException; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Found on http://www.alternateinterior.com/2007/05/multi-threading-strategies-in-php.html | |
//Modified by http://www.php-code.net | |
//Modified: add executor | |
class Thread { | |
var $pref ; // process reference | |
var $pipes; // stdio | |
var $buffer; // output buffer | |
var $output; | |
var $error; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class Test { | |
public static void main(String[] args) { | |
List<? extends Fruit> list = new ArrayList<Fruit>(); | |
List<? super Apple> list1 = new ArrayList<Apple>(); |
NewerOlder