Skip to content

Instantly share code, notes, and snippets.

@cuixin
cuixin / swich_erlang.sh
Created September 2, 2013 13:49
erlang switch version shell
#!/bin/sh
TARGET=/usr/local/bin
CURRENT=$PWD
if [ -z "$1" ] ; then
echo "no specify the erlang folder argument"
exit
fi
@cuixin
cuixin / fib.go
Last active December 23, 2015 07:09
fibonacci implements by go, and used closure.
package main
import (
"fmt"
)
func fib(i, j int) func() int {
return func() int {
i, j = j, i+j
return j
@cuixin
cuixin / chan.go
Created September 20, 2013 16:28
close two channels example in golang.
package main
import (
"fmt"
"time"
)
func WaitMany(a, b chan bool) {
for a != nil || b != nil {
select {
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
package main
import (
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
"runtime"
"runtime/debug"
@cuixin
cuixin / des.go
Last active October 30, 2023 06:52
des ecb mode in golang
package main
import (
"bytes"
"crypto/des"
"errors"
)
func PKCS5Padding(ciphertext []byte, blockSize int) []byte {
padding := blockSize - len(ciphertext)%blockSize
@cuixin
cuixin / MersenneTwister.cs
Created August 7, 2014 15:42
Mersenne Twister in c# & golang
using System;
public class MT19937
{
private const ulong N = 312;
private const ulong M = 156;
private const ulong MATRIX_A = 0xB5026F5AA96619E9L;
private const ulong UPPER_MASK = 0xFFFFFFFF80000000;
private const ulong LOWER_MASK = 0X7FFFFFFFUL;
private static ulong [] mt = new ulong[N+1];
@cuixin
cuixin / go.sh
Created September 23, 2014 05:24
golang's gopath enviroment
export GOROOT=/home/steven/go
export GOPATH=/home/steven/work/go-project/
export GOBIN=$GOROOT/bin
export PATH=.:$PATH:$GOBIN
@cuixin
cuixin / goagent
Created September 23, 2014 05:27
goagent service script.
#!/bin/sh
# goagent service by Steven
# put this file in /etc/init.d/goagent
# sudo update-rc.d goagent defaults
start(){
echo "start goagent"
sudo /home/steven/work/github.com/goagent/local/proxy.sh start
exit 0
@cuixin
cuixin / ssdb
Created September 23, 2014 05:29
ssdb service script
#!/bin/sh
# ssdb service by Steven
# put this file in /etc/init.d/ssdb
# sudo update-rc.d ssdb defaults
start(){
echo "start ssdb"
/usr/local/ssdb/ssdb-server -d /usr/local/ssdb/ssdb.conf
exit 0