Skip to content

Instantly share code, notes, and snippets.

@qxj
qxj / cluster.cpp
Last active February 14, 2016 04:46 — forked from jdeng/cluster
clustering by fast search and find of density peak
// generate [0..n-1]
auto seq = [](size_t n) -> std::vector<size_t> {
std::vector<size_t> v(n);
for (size_t i=0; i<n; ++i) v[i] = i;
return v;
};
auto index = seq(n);
// n * n distance matrix
std::vector<D> dists(n * n);
@qxj
qxj / hex.cpp
Created May 28, 2014 07:13
convert binary string to hex expression each other.
#include <stdlib.h>
#include <string>
namespace {
const char kBin2Hex[] = { "0123456789ABCDEF" };
char Hex2Bin(char ch) {
switch(ch) {
case '0': return 0;
case '1': return 1;
@qxj
qxj / cron.sh
Last active June 4, 2016 08:53
墙认证的域名和IP收集,用来避免DNS污染和自定义路由规则。
#!/bin/sh
single_instance() {
LOCKFILE=$1
[ -f $LOCKFILE ] && echo "Another instance is running." && exit 1
trap "{ rm -f $LOCKFILE; exit 0; }" EXIT SIGTERM SIGINT
touch $LOCKFILE
}
single_instance /tmp/fix_vpn.lck
@qxj
qxj / sync-to-picasa.sh
Last active December 20, 2015 18:29
备份本地照片到PicasaWeb存储上。 1. sync-to-vps.sh 中转到vps 2. sync-to-picasa.vps.sh 从vps备份到picasa
#!/bin/sh
# @(#) sync-to-picasa.sh Time-stamp: <Julian Qian 2013-08-08 00:58:30>
# Copyright 2013 Julian Qian
# Author: Julian Qian <[email protected]>
# Version: $Id: sync-to-picasa.sh,v 0.1 2013-08-07 23:51:13 jqian Exp $
#
BACKUP_LIST=(
/store1/Downloads/LuluPhotos/百度云同步盘/来自:iPhone
/store1/Downloads/LuluPhotos/Backup
@qxj
qxj / gen_routes.py
Last active December 19, 2017 03:29
这个脚本用来替代chnrountes,一是chnroutes生成的路由规则太多,二是所有的国外IP全部走VPN还是感觉资源浪费,心理不舒服,最理想的方式还是想翻哪个域名就翻哪个域名才是最合理的。不过该脚本很简陋,只是一次性找出当前待翻域名对应的IP,这些大网站为了负载均衡,很可能IP有变化,或者使用CDN,可能导致找不到被墙的IP,不过暂时看来还是凑合能用的。google, twitter没问题,其他的我也不咋上,没有仔细琢磨。如果发觉一段时间后再次被墙,就再运行一次该脚本重新生成路由即可。
#!/usr/bin/env python
# -*- coding: utf-8; tab-width: 4; -*-
# @(#) gen_route.py Time-stamp: <Julian Qian 2013-06-30 11:32:45>
# Copyright 2013 Julian Qian
# Author: Julian Qian <[email protected]>
# Version: $Id: gen_route.py,v 0.1 2013-06-30 09:50:56 jqian Exp $
#
'''
这个脚本用来替代chrountes,一是chroutes生成的路由规则太多,二是所有的国外IP全部走VPN还是感觉资源浪费,心理不舒服,所以最理想的方式还是想翻哪个域名就翻哪个域名才是最合理的。不过该脚本很简陋,只是一次性找出当前待翻域名对应的IP,这些大网站为了负载均衡,很可能IP有变化,或者使用CDN,可能导致找不到被墙的IP,不过暂时看来还是凑合能用的。google, twitter没问题,其他的我也不咋上,没有仔细琢磨。如果发觉一段时间后再次被墙,就再运行一次该脚本重新生成路由即可。
@qxj
qxj / get_ip.c
Last active December 17, 2015 13:39
Get IP address of local network interface by getifaddrs().
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(int argc, char *argv[])
@qxj
qxj / multiple_timers.cpp
Created May 21, 2013 03:41
boost samples
#include <iostream>
#include <map>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
enum { N = 10 };
@qxj
qxj / test_bdb.cpp
Last active December 16, 2015 22:49
compare performance between CDS and TDS when multiple-read and one-write
// -*- mode: c++ -*-
// @(#) test_bdb.cpp Time-stamp: <Julian Qian 2013-05-07 11:37:26>
// Copyright 2013 Julian Qian
// Author: Julian Qian <[email protected]>
// Version: $Id: test_bdb.cpp,v 0.1 2013-05-02 20:58:38 jqian Exp $
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@qxj
qxj / test_secondary_db.cpp
Created March 24, 2013 03:31
test multiple secondary index of berkeley db g++ -o test_secondary_db test_secondary_db.cpp -g -O2 -Wall -Wextra -ldb
// -*- mode: c++ -*-
// @(#) test_secondary_db.cpp Time-stamp: <Julian Qian 2013-03-23 22:16:12>
// Copyright 2013 Julian Qian
// Author: Julian Qian <[email protected]>
// Version: $Id: test_secondary_db.cpp,v 0.1 2013-03-23 21:31:19 jqian Exp $
//
// test multiple secondary index of berkeley db
// g++ -o test_secondary_db test_secondary_db.cpp -g -O2 -Wall -Wextra -ldb
@qxj
qxj / test_crc32.c
Created August 6, 2012 11:48
crc32 in zlib
/* @(#)test_crc32.cpp
* Time-stamp: < 2011-12-26 11:30:17>
* Copyright 2011
* Version: $Id: test_crc32.c,v 0.0 2011/12/26 03:25:28 jqian Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>