Skip to content

Instantly share code, notes, and snippets.

@bitxel
bitxel / session.go
Created December 12, 2015 08:29
Bulk call func in stucts
// Come from golang.org/x/crypto/ssh/session.go:353
type F func(*Session)
for _, setupFd := range []F{(*Session).stdin, (*Session).stdout, (*Session).stderr} {
setupFd(s)
}
@bitxel
bitxel / mongodb mapreduce
Created June 26, 2015 15:49
use mongodb mapreduce to update document example
var m = function(){
emit(this._id,this)
}
var r = function(k, value) {
// here is the process of update data
t = value.running_param.targets;
for (var i = 0; i < t.length; i++) {
var tmp = t[i].split("/")[1];
if (tmp.indexOf(".") == -1) {
@bitxel
bitxel / gist:8edf7c17b66949d60121
Last active August 29, 2015 14:22
python alternative switch
#!/usr/bin/env python
# coding=utf-8
def switch(key):
return {
'keya': '123',
'keyb': '456',
'keyc': 'aaa'
}.get(key,'8888')