Skip to content

Instantly share code, notes, and snippets.

@Arbow
Arbow / DirectByteBufferCleaner.java
Created July 19, 2012 03:22
回收DirectByteBuffer
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
@Arbow
Arbow / gist:3787229
Created September 26, 2012 10:26
Start zookeeper cluster from program
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();
@Arbow
Arbow / FailoverNodeLocator.java
Created November 8, 2012 07:38
Failover locator in spymemcached
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) {
# 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
@Arbow
Arbow / jkiller.sh
Created July 29, 2013 06:00
Print java process cpu top 5 threads stack, from https://github.com/54chen/jkiller/blob/master/jkiller.sh
#!/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;
@Arbow
Arbow / process_util.py
Created November 27, 2013 09:07
在tornado中不阻塞创建子进程的一个工具类
#!/usr/bin/env python
#coding: utf-8
import os
import shlex
import subprocess
import signal
import functools
import logging
import tornado
@Arbow
Arbow / python_enum.py
Last active January 3, 2016 05:19
python enum implement in 2.x
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 获取某个枚举值对应的别名
"""