Skip to content

Instantly share code, notes, and snippets.

@codeck
codeck / gist:2761692
Created May 21, 2012 10:23
factorial() lambda recursive version
(funcall
(lambda (fn n)
(funcall fn n fn))
(lambda (n this)
(cond ((> n 0)
(* n (funcall this (- n 1) this)))
(t 1)))
10)
@codeck
codeck / gist:5727458
Created June 7, 2013 06:45
about debian multi arch (32bit@amd64)
dpkg --add-architecture i386
apt-get update
apt-get install libstdc++6:i386
#!/bin/sh
GITHOST=scm@192.168.100.221
GITPATH=gitroot
cd ~/${GITPATH}_backup
ls -F . | grep / > /tmp/.gitmissing1
eval ssh -n $GITHOST ls -F ${GITPATH}/. | grep / > /tmp/.gitmissing2
diff /tmp/.gitmissing1 /tmp/.gitmissing2 | egrep '^>' |
while read x f; do
git clone --bare --mirror ${GITHOST}:${GITPATH}/$f $f
@codeck
codeck / backuppg.sh
Created October 29, 2013 03:02
backup pg db
PGHOST=root@remotehost
eval "ssh ${PGHOST} pg_dump -Fc webdb" > webdb-`date +%F.%H%M`.dump
@codeck
codeck / jgit auth
Created December 17, 2013 12:12
call jgitenv.setup() before any jgit call
object jgitenv {
def setup() {
val jschConfigSessionFactory = new JschConfigSessionFactory() {
override def createDefaultJSch(fs:FS) = {
val jsch = new JSch();
try {
jsch.addIdentity("..\\id_rsa"); //_.pub must exist
jsch.setKnownHosts("..\\known_hosts");
} catch {
@codeck
codeck / gist:8192348
Created December 31, 2013 03:50
peek specific field from a protobuf message by field numbers
private[this] def peakNested(fid:Int, pbs:CodedInputStream):Option[CodedInputStream] = {
val (_, res) = Iterator.continually(pbs.readTag()).span{tag =>
(tag != 0) && (WireFormat.getTagFieldNumber(tag) != fid) && pbs.skipField(tag)
}
val lastid = WireFormat.getTagFieldNumber(res.next)
if (lastid == fid) Some(pbs)
else None
}
def recursivePeek[T](ids:Seq[Int], extract: (CodedInputStream=>T), pbs:CodedInputStream):Option[T] = {
ids match {
@codeck
codeck / it.scala
Last active January 2, 2016 13:38 — forked from Centaur/it.scala
val arg1 = Iterator(2, 3, 4, 8, 9, 12, 14, 17)
val arg2 = Iterator(1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 17)
//??(arg1, arg2)=> Iterator((2, 4), (8, 9), (12, 12),(14, 17))
case class CeRange(start:Int, end:Option[Int]) {
def passed(br: Int) = {
end.map(br < _).getOrElse(true)
}
}
def timeit[T](f:()=>T)(count:Int=1) = {
val st = System.nanoTime()
var ti = 0
var accu = collection.mutable.ListBuffer.empty[T]
while (ti < count) {
f() +=: accu
ti=ti+1
}
val ed = System.nanoTime()
println(s"${(ed-st)/1000000} ms")
@codeck
codeck / tcpflow.lua
Last active August 29, 2015 14:00
whireshark script to show how sack make throughput jitter
-- run by
-- "C:\Program Files\Wireshark\tshark" -Q -r ftp.pcapng -X lua_script:tcpflow.lua
local server = "1.1.1.1"
local tap = Listener.new("tcp", "ip.addr == "..server)
function gen_acc(seq)
local datas = {}
local sum = 0
local last_sum = 0
@codeck
codeck / ledger_head.sh
Created May 2, 2014 02:29
bash command to monitor rippled ledger fetching progresss
#/bin/bash
#
#command to monitor a rippled stared by `./rippled --fg --net` with "full ledger_history" config
#
while [ 1 ];
do ./rippled -q server_info|grep "complete_ledger"|egrep -o '[[:digit:]]*'|head -n1|xargs -I{} ./rippled -q ledger {} |grep close_time_human;
sleep 5;
done