Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
"runtime"
"runtime/debug"
@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 / limits.conf
Created September 24, 2014 09:08
resolve Linux "Too many files open" error
#/etc/security/limits.conf
* hard nofile 1024000
* soft nofile 1024000
root hard nofile 1024000
root soft nofile 1024000
@cuixin
cuixin / EvenPower.java
Created June 15, 2012 07:27
是否是2的N次幂
public class Is2Power {
public static void main(String[] args) {
for (int i = 0;i <= 1024; i++) {
if ((i & -i) == i)
System.out.println(Integer.toBinaryString(i) + ", " + Integer.toBinaryString(-i) + " " + i);
}
}
}
@cuixin
cuixin / gist:3395915
Created August 19, 2012 16:23 — forked from swannodette/gist:3213107
sudoku.clj
(defn distincto
"s is a sequence of sequence of vars.
ensure that vars in each particular sequence
take on distinct values."
[s]
(if (seq s)
(let [vars (first s)]
(all
(distinctfd vars)
(distincto (next s))))
@cuixin
cuixin / crc32.clj
Created August 29, 2012 02:18
crc32
(defn- crc32
"Generate a crc32 checksum for the given string"
[token]
(let [hash-bytes
(doto (java.util.zip.CRC32.)
(.reset)
(.update (.getBytes token)))]
(Long/toHexString (.getValue hash-bytes))))
@cuixin
cuixin / python_test.py
Created October 9, 2012 08:36
mypython examples
def mysum(*args):
return sum(args)
def mytimes(*args):
if not args:
return 0
else:
result = 1
for v in args:
result *= v
@cuixin
cuixin / GenRndLetter.go
Created October 27, 2015 10:45
Using golang easier to generate only letters by random.
package main
import (
"crypto/rand"
"fmt"
"io"
)
func newId(size int) string {
k := make([]byte, size)
@cuixin
cuixin / CsvObjTools.java
Last active December 9, 2015 22:08
一个通过csv文件序列化到类实例的工具,因为这个跟json不太一样,是一行行的读取,中间通过tab分割,第一行实际就是类的字段定义。 通过指定一个索引文件来读取,索引文件负责设定类的名称和配置文件的路径。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.slf4j.Logger;