Skip to content

Instantly share code, notes, and snippets.

set -g default-terminal "xterm-256color"
set -g prefix M-f
unbind C-b
bind M-f send-prefix
bind -n M-` last-window
bind -n M-1 select-window -t :=1
bind -n M-2 select-window -t :=2
bind -n M-3 select-window -t :=3
@nicky-zs
nicky-zs / case1-bad.c
Last active September 5, 2018 06:00
The classic memory model problems on Intel x86-64 multi-core systems. Return values of system calls or library calls are NOT CHECKED because they are only demos.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#include <semaphore.h>
pthread_t t1, t2;
sem_t sem_start1, sem_start2, sem_end;
@nicky-zs
nicky-zs / inner_ip_benchmark.c
Last active June 30, 2018 03:06
benchmark of SIMD
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <arpa/inet.h>
typedef int v4si __attribute__ ((vector_size (16)));
// /8 /10 /12 /16
const v4si mask = {0x000000FF, 0x0000C0FF, 0x0000F0FF, 0x0000FFFF};
@nicky-zs
nicky-zs / Base62IdCodec.java
Last active February 1, 2018 10:51
A simple, thread-safe Base62 codec for hiding the real ID and its incresing trend. No dependencies other than JDK are required. It can encode and decode 250k+ IDs per thread per second on [email protected].
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
@nicky-zs
nicky-zs / nginx.conf
Last active August 25, 2017 05:51
A general nginx config file with openresty health check support.
pid /run/nginx/nginx.pid;
lock_file /run/nginx/nginx.lock;
error_log /opt/logs/nginx/error.log error;
pcre_jit on
worker_processes 4;
worker_priority -10;
events {
worker_connections 4096;
@nicky-zs
nicky-zs / inflate_request_body.lua
Created July 17, 2016 02:57
Supporting gzipped request body.
-- lua-zlib is required
local MAX_BODY_SIZE = 16777216
ngx.ctx.max_chunk_size = tonumber(ngx.var.max_chunk_size) or 262144 -- 256KB
ngx.ctx.max_body_size = tonumber(ngx.var.max_body_size) or MAX_BODY_SIZE -- 16MB
function bad_request_response(status, msg)
local message = string.format('{"status": %d, "msg": "%s"}', status, msg)
ngx.status = ngx.HTTP_BAD_REQUEST
@nicky-zs
nicky-zs / ios-app-build.sh
Created November 7, 2014 03:32
This is a bash script running on Mac OS with Xcode, which can automatically build an iOS APP from its source project.
#!/bin/bash
# .ipa path: /tmp/packapp/com.xxx.${sub_domain}/build/com.xxx.${sub_domain}.app.ipa
# required progs:
# wget;
# python2.7 ./substitute.py;
# lockfile;
# imagemagick(convert, identify);
@nicky-zs
nicky-zs / substitute.py
Created July 11, 2014 06:15
A simple python template renderer.
#!/usr/bin/python2.7
import sys
import string
_usage = """
Please redirect stdin to the input file, redirect stdout to the output file.
./subtitute.py ARG1=XXX ARG2=YYY < path_to_input > path_to_output\n
"""
@nicky-zs
nicky-zs / tool.py
Created July 9, 2014 08:21
A modification to python's standard library: json/tool.py, which makes it better print JSON containing non-ascii code.
r"""Command-line tool to validate and pretty-print JSON
Usage::
$ echo '{"json":"obj"}' | python -m json.tool
{
"json": "obj"
}
$ echo '{ 1.2:3.4}' | python -m json.tool
Expecting property name: line 1 column 2 (char 2)
@nicky-zs
nicky-zs / church-nums.ss
Created January 7, 2014 08:57
Church Numerals implementation in scheme.
;; A Church-Numberal is a function, which takes a function f(x)
;; as its argument and returns a new function f'(x).
;; Church-Numerals N applies the function f(x) N times on x.
; predefined Church-Numerals 0 to 9
(define zero (lambda (f) (lambda (x) x)))
(define one (lambda (f) (lambda (x) (f x))))
(define two (lambda (f) (lambda (x) (f (f x)))))
(define three (lambda (f) (lambda (x) (f (f (f x))))))
(define four (lambda (f) (lambda (x) (f (f (f (f x)))))))