Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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;
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