Skip to content

Instantly share code, notes, and snippets.

View bachue's full-sized avatar

Bachue Zhou bachue

View GitHub Profile
@bachue
bachue / test1_ok.go
Last active August 29, 2015 14:05
Golang Interface Match
package main
import (
"fmt"
)
type Handler func(int)
func test(handler Handler) {
handler(1)
@bachue
bachue / check_duplicates.rb
Created September 6, 2014 09:58
文件去重复
require 'digest/md5'
Dir['**/*'].
select {|f| File.file? f }.
group_by {|f| Digest::MD5.hexdigest(File.binread(f)).tap {|md5| STDERR.puts "#{f}: #{md5}" } }.
reject {|_, list| list.size == 1 }.
each {|_, v| puts "---\n#{v.join("\n")}" }
@bachue
bachue / install_linux_manpages.sh
Last active August 29, 2015 14:08
Script to install Linux manpage to Mac OS X
#/bin/bash
cd `mktemp -dt tmp`
git clone http://git.kernel.org/pub/scm/docs/man-pages/man-pages
cd man-pages
for f in man?/**/*.?; do mv -v $f `dirname $f`/linux.`basename $f`; done
sudo make install
cd ..
rm -rf man-pages
@bachue
bachue / sshtunnel.sh
Last active August 29, 2015 14:10
An utility to create ssh tunnel
sshtunnel() {
OPTIND=1
PROGRAM=$0
# Common default parameters
PROXY_USER=`whoami`
PROXY_SSH_PORT=22
MONITOR_PORT=18524
PROXY_PORT=8080
@bachue
bachue / download.rb
Created January 25, 2015 05:23
OpenLanguage english tutorials downloader
require 'httparty' # `gem install httparty`
require 'cgi'
require 'digest/md5'
require 'nokogiri' # `gem install nokogiri`
require 'pathname'
require 'set'
ROOT = Pathname File.expand_path(__dir__)
DOWNLOAD_PATH = ROOT.join 'Downloads'
@bachue
bachue / rw_lock_test.c
Created December 16, 2015 16:10
Test POSIX thread rwlock
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
#define ERROR_PRINTF(fmt, args...) { \
fprintf(stderr, fmt, args); \
@bachue
bachue / proc_file_read_test.c
Created December 17, 2015 06:30
As you can see, when you read file in /proc, any error could happen. E.g. When you read the status from a process, you may get ESRCH
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <linux/limits.h>
#define ERROR_PRINTF(fmt, args...) {\
fprintf(stderr, fmt, args); \
@bachue
bachue / download_14_lectures.rb
Created February 6, 2017 07:01
下载数值分析的视频
require 'rest_client'
require 'nokogiri'
HOST = 'http://moocs.nccu.edu.tw'.freeze
html = Nokogiri::HTML(RestClient.get(HOST + '/course/14/section/lecture').body)
html.css('li.lecture>.main>.title>a.link').each do |lecture|
href = lecture.attr('href')
title = lecture.css('.value').first.attr('title')
page = Nokogiri::HTML(RestClient.get(HOST + href).body)
@bachue
bachue / failed_test.c
Last active October 16, 2017 01:57
根据 http://blog.shengbin.me/posts/gcc-attribute-aligned-and-packed ,写了个测试用例,执行在 x86_64 上。理论上应该输出 80000 才对,实际执行的时候只有在 gcc 使用 -O1 及其以上优化时,才能成功。
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <pthread.h>
void *add_counter(void* c) {
int i;
for (i = 0; i < 10000; i++) {
(*(int*)c)++;
}

Rust by actix-web

Server Software:
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /
Document Length:        11 bytes