Skip to content

Instantly share code, notes, and snippets.

View kindy's full-sized avatar

Kindy Lin kindy

  • Beijing, China
  • 23:07 (UTC +08:00)
  • LinkedIn in/kindy
View GitHub Profile
@kindy
kindy / vimrc
Last active December 22, 2015 06:39
" <buffer-number> <file-name> <modify> <file-type> <encoding> <line><col> <byte-of-file> <char-under-cursor> <pos-of-file>
" #17 ~/.vimrc [+][vim] [utf-8] 2336,1 @59791 0x6E Bot
set statusline=%<#%n\ %f\ %h%m%r%y%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",bom\":\"\")}]\ %-16.(%l,%c%V%)\ @%o\ 0x%B\ %P
" use :grep to search
set grepprg=ack\ --nocolor\ --nogroup
set grepformat=%f:%l:%m
" use <C-j> and <C-k> to navigate in search result
nm <c-j> :cn<CR>
nm <c-k> :cp<CR>
/* lisp.c: high-speed LISP interpreter */
/* src: http://www.cs.auckland.ac.nz/~chaitin/lisp.c */
/*
The storage required by this interpreter is 8 * 4 = 32 bytes times
the symbolic constant SIZE, which is 32 * 1,000,000 =
32 megabytes. To run this interpreter in small machines,
reduce the #define SIZE 1000000 below.
To compile, type
cc -O -olisp lisp.c
/*
http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
public static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
@kindy
kindy / ngx_queue.conf
Created January 10, 2013 13:46
Use proxy_read_timeout to simulate task queue in ngx_openresty
server {
listen 9999;
resolver 8.8.8.8;
location = /add-q {
content_by_lua "
ngx.location.capture('/i-add-q', {
args = {
uri = '/run-q'
@kindy
kindy / ngx_http_upstream_check.conf
Created December 21, 2012 03:34
demo config for nginx http upstream check
upstream cluster {
# simple round-robin
server 127.0.0.1:10002;
server 127.0.0.1:10003;
check interval=1000 rise=2 fall=5 timeout=500 type=http;
check_http_send "GET /status HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
# http://douban.fm/ 边听边寸,这样下次可以本机听了。
# nginx.conf
server {
listen 80;
server_name .douban.com;
root /mp3_douban;
location / {
# default to '~'
xconf {
echo '[~~[';
echo \[~~[''xx;
content_by_lua [~~[
ngx.say'hello!'
]~~];
@kindy
kindy / db.sql
Created December 6, 2012 05:50
ngx_openresty file upload
" mysql中增加一数据库,名为nginx,编码为utf8
" 增加一表,名为 uploadfile 结构为
CREATE TABLE `uploadfile` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`filehash` varchar(50) DEFAULT NULL,
`filename` varchar(100) DEFAULT NULL,
`filelen` varchar(50) DEFAULT NULL,
`contenthash` varchar(80) DEFAULT NULL,
PRIMARY KEY (`id`)
events {
worker_connections 1024;
}
http {
upstream xx {
server 127.0.0.1:8003;
server 127.0.0.1:8003;
}
server {
@kindy
kindy / datetime_to_unix_timestamp.py
Created December 3, 2012 15:26
convert datetime to unix_timestamp
# convert datetime to unix_timestamp
import datetime, time
now = datetime.datetime.now()
ts = time.mktime(time.strptime(now.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S'))