Skip to content

Instantly share code, notes, and snippets.

View siddontang's full-sized avatar
🏠
Working from home

siddontang siddontang

🏠
Working from home
  • PingCAP
  • SunnyVale
View GitHub Profile
@siddontang
siddontang / bin_packer.py
Created November 29, 2012 12:56
bin packing by python
#coding=utf8
#[email protected]
import random
import math
class Block(object):
def __init__(self, width, height):
self.width = width
self.height = height
@siddontang
siddontang / roundup.c
Last active October 13, 2015 09:17
round up
const int align = 8;
size_t round_up(size_t bytes)
{
return ((bytes) + align - 1) & ~(align - 1)
}
@siddontang
siddontang / nginx.conf
Last active December 15, 2015 12:29
simple nginx example
worker_processes 1;
events {
use epoll;
}
http {
default_type text/html;
server {
listen 80;
server_name localhost;
@siddontang
siddontang / nginx-helloworld.c
Created March 29, 2013 00:54
a simple nginx module
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
typedef struct {
ngx_str_t output_words;
} ngx_http_hello_world_loc_conf_t;
// To process HelloWorld command arguments
static char* ngx_http_hello_world(ngx_conf_t* cf, ngx_command_t* cmd, void* conf);
@siddontang
siddontang / hmac.lua
Created May 18, 2013 09:24
openresty string hmac implementation
local ffi = require "ffi"
local sha512 = require "resty.sha512"
local aes = require "resty.aes"
local ffi_new = ffi.new
local ffi_str = ffi.string
local C = ffi.C
local setmetatable = setmetatable
local error = error
@siddontang
siddontang / csp.cpp
Last active December 18, 2015 13:48
windows csp, rsa, certificate
#include "rsa.h"
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <wincrypt.h>
#include "base64.h"
#pragma comment(lib, "crypt32.lib")
@siddontang
siddontang / thread_example.c
Created October 7, 2013 15:20
Threads Creation and Execution Example
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void initArray(int* array, int N)
{
int i = 0;
for(i = 0; i < N; i++)
{
array[i] = (int)random();
@siddontang
siddontang / encoding_detect.py
Created October 8, 2013 15:30
string encoding detect
import chardet
BOM_UTF8 = '\xef\xbb\xbf'
def detect(raw):
if raw.startswith(BOM_UTF8):
return 'utf-8-sig'
else:
result = chardet.detect(raw)
return result['encoding']
@siddontang
siddontang / .vimrc
Last active December 25, 2015 01:19
my vim config
set smartindent
set tabstop=4
set shiftwidth=4
"set expandtab
set softtabstop=4
syntax on
filetype plugin on
autocmd FileType * set expandtab
autocmd FileType make set noexpandtab
func Escape(sql string) string {
dest := make([]byte, 0, 2*len(sql))
var escape byte
for i := 0; i < len(sql); i++ {
c := sql[i]
escape = 0
switch c {
case 0: /* Must be escaped for 'mysql' */