Skip to content

Instantly share code, notes, and snippets.

@airekans
airekans / test_setitimer.cpp
Last active August 29, 2015 14:10
A simple program used to test whether the kernel support setitimer to be enabled for multiple threads by default. This can be used to detect whether gperftools can be used easily
#include <pthread.h>
#include <iostream>
#include <string>
#include <cstdlib>
#include <sys/time.h>
using namespace std;
static int mode = ITIMER_PROF;
@airekans
airekans / heap_merge.cpp
Created November 3, 2014 08:02
Use heap to merge multiple arrays into a single array
void Merge3(const vector<int>& v1, const vector<int>& v2, const vector<int>& v3, vector<int>& v4)
{
typedef pair<size_t, const vector<int>*> HeapElem;
vector<HeapElem> int_heap;
if (!v1.empty())
{
int_heap.push_back(make_pair(0, &v1));
}
if (!v2.empty())
@airekans
airekans / fake_syscall.c
Created October 23, 2014 09:00
Use LD_PRELOAD to test program using syscall
#define _GNU_SOURCE 1
#include <dlfcn.h>
#include <string.h>
#include <stdlib.h>
int open(const char *pathname, int flags)
{
typedef int (*OpenFunc)(const char*, int);
static OpenFunc real_open_func = NULL;
@airekans
airekans / test_killall.py
Created October 13, 2014 14:40
Program used to test killall in gevent
import gevent
threads = []
def killall_but_this():
this_thread = gevent.getcurrent()
for t in threads:
if t is not this_thread:
t.kill(block=False)
@airekans
airekans / client.cpp
Created October 11, 2014 07:59
Programs used to check send buffer size in TCP
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <cstdlib>
#include <fcntl.h>
#include <errno.h>
#include <cstring>
@airekans
airekans / p4unsh.py
Last active August 29, 2015 14:06
Script used to sync files from p4 shelve
#! /usr/bin/env python2.7
import pypipe # use pypipe from https://github.com/airekans/Pypipe
import sys
import os
_BACKUP_CL = 123456
def is_p4_different(p4_path, shelve_cl):
@airekans
airekans / bandwidth.py
Last active August 29, 2015 14:06
A simple python script used to get the bandwidth between 2 hosts.
#! /usr/bin/env python
#
# This script shows the correct result only when the host(client or server)
# is idle(no other network intensive program is running).
# So if you run two client on the same host, the result is wrong.
import socket
import sys
import time
@airekans
airekans / file_owner_cnt.py
Created August 23, 2014 09:08
A MapReduce example: Given a list of (user_name, filename) pair, get a list of (filename, owner_count)
l = [("user_a", "file_a"), ("user_b", "file_b"), ("user_c", "file_b")]
filenames = map(lambda p: p[1], l)
def reduce_func(res, filename):
if filename not in res:
res[filename] = 0
res[filename] += 1
return res
@airekans
airekans / replace_so.sh
Created July 25, 2014 03:20
A simple shell script used to update so file.
#! /bin/bash
if [ $# -lt 2 ]; then
echo Usage: $0 MD5 SO_FILE_NAME
exit 1
fi
file_md5=$1
so_filename=$2
tmp_so=${so_filename}.$RANDOM
@airekans
airekans / test_time.cpp
Created May 25, 2014 08:31
A simple program used to test the performance of gettimeofday.
#include <cstdlib>
#include <sys/time.h>
#include <cerrno>
#include <cstring>
#include <iostream>
using namespace std;
static void my_get_time(timeval* tv)