Skip to content

Instantly share code, notes, and snippets.

@zhouji
zhouji / StupidPi.java
Created January 20, 2012 09:44
Stupid Pi Caculator
package funny;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
/**
*
* @author zhouji
*/
@zhouji
zhouji / rm.sh
Created March 22, 2012 09:49 — forked from zhasm/rm.sh
safe rm command
logger ()
{
time=`TZ="Asia/Shanghai" date +"%Y-%m-%d %T"`;
echo "[$time] $*"
}
filesize ()
{
/bin/ls -alF "$1" | awk '{print $5}'
}
@zhouji
zhouji / gist:2315650
Created April 6, 2012 01:07 — forked from sharrissf/gist:700690
Direct Memory vs On Heap in Java
import java.nio.ByteBuffer;
import java.util.Random;
public class BufferPerformanceComparison {
public final static int MEGA_BYTE = 1024 * 1024;
public final static long GIGA_BYTE = MEGA_BYTE * 1024;
private final ByteBuffer heapByteBuffer;
private final ByteBuffer offHeapByteBuffer;
private final long dataToLoad;
private final int bufferSize;
@zhouji
zhouji / fetch_zanghaihua.groovy
Created April 13, 2012 16:04
A script for download books from motie
// A script for download books from motie
import java.util.regex.Pattern
content= ""
def getIndex(indexURL){
(indexURL.toURL().text =~ /a href="(\/book\/[0-9]+_[0-9]+)" >第/ ).each{ a, b ->
getPage("http://www.motie.com/"+b)
}
}
@zhouji
zhouji / EC_KestrelClient.php
Created November 6, 2012 15:51 — forked from shupp/EC_KestrelClient.php
Kestrel Client Decorator
<?php
/**
* A thin kestrel client that wraps Memcached (libmemcached extension)
*
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2010-2011 Empower Campaigns
*/
class EC_KestrelClient
{
/**
@zhouji
zhouji / .vimrc
Last active October 13, 2015 03:08 — forked from stupend/.vimrc
My Vim config file
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'python.vim'
Bundle 'taglist.vim'
Bundle 'TWiki-Syntax'
@zhouji
zhouji / ration_array.cpp
Created November 22, 2012 10:20
Function to generate char arraies according to the ration defination.
#include <iostream>
#include <string>
using namespace std;
int min_idx(float * ratio, int * idx,int size){
float min_weight = 10000000.0f;
int min_idx = 0;
for( int i = 0 ; i < size ; i++){
float weight = idx[i]/ratio[i];
@zhouji
zhouji / parse.py
Created November 27, 2012 02:06
File parse in python
f=open('/home/zhouji/temp/out5','r')
idx=0
ctn=set()
for line in f:
ss=line.split("\001")
s=ss[0]+ss[1]
idx=idx+1
if not s in ctn :
print line.replace("\001","\\001").replace("\002","\\002").replace("\003","\\003")
ctn.add(s)
@zhouji
zhouji / retry.cc
Created November 29, 2012 07:50
Retry with timeout and counter
int QueueCluster::Send(const char * queueName, const char * data, int timeout){
int rtn = 0;
uint startTime = time(NULL);
int elapsedTime;
int retryCount = 0;
do{
QueueServer * svr = SelectQueueServer();
if( svr != NULL ){
rtn = svr->Send(queueName,data,timeout);
if( rtn == SEND_SUCCESS ){
@zhouji
zhouji / time_spend.cc
Created November 29, 2012 08:48
calculate time spending in C++
int test1(){
cout<< " OK " << endl;
KestrelServer ks("localhost",22133);
int max = 1000000;
struct timeval start, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
int count = 0;