Skip to content

Instantly share code, notes, and snippets.

Avatar

Sun Junyi fxsjy

  • Tencent
  • Beijing, China
View GitHub Profile
@fxsjy
fxsjy / gist:3550052
Created Aug 31, 2012
Bakup Weibo to Disk
View gist:3550052
package main
import (
"net/http"
"net/url"
"log"
"io/ioutil"
"regexp"
"fmt"
//"net/http/httputil"
@fxsjy
fxsjy / gist:3377100
Created Aug 17, 2012
Memcached Server Written in Go, only 70 lines of code
View gist:3377100
package main
import (
"net"
"log"
"fmt"
"bufio"
"strings"
"strconv"
"io"
@fxsjy
fxsjy / gist:3293029
Created Aug 8, 2012
QBuffer: A little buffer tool for Node.JS
View gist:3293029
var QBuffer = exports.QBuffer= function(){
this.list = []
this.length = 0
}
QBuffer.prototype.append=function(chunk){
this.list.push(chunk)
this.length += chunk.length
}
@fxsjy
fxsjy / gist:3291755
Last active Jan 9, 2021
Memcached in JavaScript based on Node.JS
View gist:3291755
//author: Sun, Junyi (weibo.com/treapdb)
//usage: node --nouse-idle-notification --expose-gc --max-old-space-size=8192 memcached.js
var config ={
port: 11211,
max_memory: 300 // default 100M bytes
}
var net = require('net');
var LRU = function (max) { // this LRU implementaion is based on https://github.com/chriso/lru
@fxsjy
fxsjy / gist:3244607
Created Aug 3, 2012
Simple Memcached server in Javascript with 100 lines of code
View gist:3244607
/* Simple Memcached in Javascript
* @Author: Sun, Junyi
* @Email: ccnusjy@gmail.com
* @Date: 2012-8-3
*/
var net = require('net');
var store = {}
function handle_header(header,crlf_len){
var tup = header.split(" ")
@fxsjy
fxsjy / gist:3158805
Created Jul 22, 2012
python random read disk
View gist:3158805
import random
import time
size=100000000
t1 = time.time()
f=open('x.db','wb')
f.write('x'*size)
f.close()
print 'write:', time.time()-t1
f=open('x.db','rb')
t2=time.time()
View gist:3009412
var http=require('http')
url =require("url")
var cluster = require('cluster');
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < 20; i++) {
cluster.fork();
}
@fxsjy
fxsjy / gist:2934746
Created Jun 15, 2012
bpnn solve kindergarten problem(numpy)
View gist:2934746
#!/usr/bin/env python
# Problem: http://www.weibo.com/2090476735/ynJtWvN1K
# junyi sun (weibo.com/treapdb)
from numpy import *
def Q(L):
H = [0]*11
H[0] = 1 #bias item
for x in L:
H[x+1]+=1
@fxsjy
fxsjy / gist:2928683
Created Jun 14, 2012
bpnn solve kindergarten problem
View gist:2928683
# Back-Propagation Neural Networks
# another way: solve it as a Regression Problem
# Written in Python. See http://www.python.org/
# Modified by JSun to solve the problem here: http://www.weibo.com/1497035431/ynPEvC78V
# Neil Schemenauer <nas@arctrix.com>
import math
import random
import string
@fxsjy
fxsjy / bpnn_digit.py
Created Jun 14, 2012
bpnn solve kindergarten problem
View bpnn_digit.py
# Back-Propagation Neural Networks
#
# Written in Python. See http://www.python.org/
# Modified by JSun to solve the problem here: http://www.weibo.com/1497035431/ynPEvC78V
# Neil Schemenauer <nas@arctrix.com>
import math
import random
import string