Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
#!/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 / 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
@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)