Skip to content

Instantly share code, notes, and snippets.

@chenshuo
chenshuo / multiple_thread.sh
Created September 4, 2010 07:13
ping pong test for muduo network library
#!/bin/sh
killall server
timeout=${timeout:-100}
bufsize=16384
for nosessions in 100 1000; do
for nothreads in 1 2 3 4; do
sleep 5
echo "Bufsize: $bufsize Threads: $nothreads Sessions: $nosessions"
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <stdio.h>
class Base
{
public:
virtual void foo()
{
printf("Base::foo\n");
#include <muduo/base/Logging.h>
#include <muduo/net/EventLoop.h>
#include <muduo/net/InetAddress.h>
#include <muduo/net/TcpClient.h>
#include <muduo/net/TcpServer.h>
#include <boost/bind.hpp>
#include <queue>
#include <utility>
@chenshuo
chenshuo / linux_com.h
Created March 12, 2011 10:14
If Linux kernel were exposed as COM interfaces
class Linux_0_01
{
int restart_syscall(); //0
int exit(); //1
int fork(); //2
int read(); //3
int write(); //4
int open(); //5
int close(); //6
int waitpid(); //7
@chenshuo
chenshuo / iprange.cc
Created April 3, 2011 03:27
从一组 IP range --> value 的数据中查找单个 IP
#include <assert.h>
#include <stdint.h>
#include <algorithm>
#include <vector>
using namespace std;
struct IPrange
{
@chenshuo
chenshuo / ten_in_a_row.java
Created April 29, 2011 12:07
prob of 10 in a row, picking 60 out of 228.
public class Main {
public final static int kHoles = 228;
public final static int kBalls = 60;
public static void main(String[] args) {
Random r = new Random();
int[] hist = new int[kBalls + 1];
for (int round = 0; round < 1000*1000*10; ++round) {
boolean[] holes = new boolean[kHoles+1];
int balls = 0;
@chenshuo
chenshuo / nbody.c
Created August 20, 2011 09:17
Data Abstraction in C++
/*
* The Computer Language Benchmarks Game
* http://shootout.alioth.debian.org/
*
* contributed by Christoph Bauer
* modified by bearophile
*/
#include <math.h>
@chenshuo
chenshuo / join.cc
Created December 11, 2011 12:59
Join two sets
#include <algorithm>
#include <iterator>
#include <vector>
#include <boost/unordered_set.hpp>
#include <stdint.h>
#include <stdio.h>
#include <sys/time.h>
using namespace std;
@chenshuo
chenshuo / poj1035.cc
Created January 15, 2012 03:25
poj1035
#include <string>
#include <set>
#include <vector>
#include <iostream>
#include <assert.h>
#include <stdio.h>
using namespace std;
typedef vector<string> Dictionary;
@chenshuo
chenshuo / 2012.cc
Created February 2, 2012 11:39
A puzzle solved with breadth-first search
// FIXME: memory leaks
#include <stdio.h>
#include <deque>
#include <set>
struct Node
{
int value;
Node* parent;