Skip to content

Instantly share code, notes, and snippets.

@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 / 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 <junist@gmail.com>
# 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 / 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 <junist@gmail.com>
# 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 / 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 / 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 / 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);
import io
import avro.schema
import avro.io
import lipsum
import random
from kafka.client import KafkaClient
from kafka.producer import SimpleProducer, KeyedProducer
g = lipsum.Generator()
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon
@qxj
qxj / avro_cli_test.php
Created March 23, 2015 08:03
avro php library benchmark
<?php
require_once('../lib/avro.php');
function create_record() {
$rec = array('member_id' => 1392, 'member_id2' => 999);
for ($i = 0; $i < 20; $i++) {
$rec['field' . $i] = 'test_value' . $i;
}
return $rec;