Skip to content

Instantly share code, notes, and snippets.

@cuixin
cuixin / nginx_proxy_by_query.conf
Last active December 28, 2018 02:23
nginx proxy_pass by query param(query url) example
events {
}
http {
server {
listen 80;
server_name localhost;
location / {
set $host_1 "http://127.0.0.1:8881";
set $host_2 "http://127.0.0.1:8882";
@cuixin
cuixin / wallpaper.sh
Created December 20, 2018 10:34
random desktop wallpaper from unsplash website.
#!/bin/bash
function wallpaper() {
# set -ex
query=$1
if [[ -z $query ]]; then
query="wallpaper"
fi
pic_path="/tmp/wallpaper.jpg"
wget "https://source.unsplash.com/random/1920x1080?$query" -O $pic_path
feh --no-fehbg --image-bg "#000000" --bg-max $pic_path
@cuixin
cuixin / bitset.go
Created November 8, 2018 08:11
dummy bitset in golang
package main
import (
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"strings"
"log"
@cuixin
cuixin / tsr.bash
Created October 22, 2018 10:29
typescript run command(add this function in ur .bashrc or .zshrc)
function tsr() {
tsc $1.ts && node $1.js
}
@cuixin
cuixin / fibonacci.lua
Created July 6, 2018 03:07
lua fibonacci with closure.
local function my_ipairs(t)
local i = 1
return function()
local v = t[i]
if v then
local ii = i
i = i + 1
return ii, v
else
return nil
@cuixin
cuixin / solve_birthday.go
Last active June 4, 2018 07:55
birthday problem solved in golang.
package main
import "fmt"
func main() {
count := 60
diff := float64(1.0)
for i := 0; i <= count; i++ {
diff *= float64((365 - float64(i)) / 365) // would be all different day.
fmt.Printf("times %d, diff [%.2f%%], same [%.2f%%]\n", i, diff*100, (1-diff)*100)
@cuixin
cuixin / print_r_test.lua
Created May 4, 2018 09:21
lua print_r test
x = {
value = 1,
text = "test",
inest = {
aaaa = "1",
eee = {
abc = 1
},
bl = true,
}
@cuixin
cuixin / slice_binary.go
Created April 17, 2018 05:12
Using reflect.SliceHeader to marshal data.
package main
import (
"fmt"
"reflect"
"unsafe"
)
type NestType struct {
S string
@cuixin
cuixin / beanstalkd.sh
Created December 8, 2015 05:31
install beanstalkd on centos
Step 0. Install git
yum install git
Step 1. Clone repository
git clone git://github.com/kr/beanstalkd.git
cd beanstalkd
make
cp beanstalkd /usr/bin/beanstalkd
@cuixin
cuixin / map_perf.go
Created March 12, 2018 11:58
This is demonstrate the golang's gc latency when using map to storing struct or pointer. ref: https://groups.google.com/forum/#!topic/Golang-nuts/baU4PZFyBQQ
package main
import (
"fmt"
"os"
"runtime"
"time"
)
// Results of this program on my machine: (linux amd64, go 1.4):