Skip to content

Instantly share code, notes, and snippets.

@ruandao
ruandao / DataSerialisation_ASN.1.go
Created July 27, 2016 03:10
<<Network programming with Go>> Chapter 4 Data serialisation
package main
import (
"encoding/asn1"
"fmt"
"os"
)
func main_ASN_1() {
mdata, err := asn1.Marshal(13)
@ruandao
ruandao / socket_go_DaytimeServer.go
Created July 27, 2016 03:10
<<Network programming with Go>> Chapter 3 Socket-level Programming
package main
import (
"net"
"time"
)
func main_DaytimeServer() {
service := ":1200"
tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
@ruandao
ruandao / Application-Level Protocols_Application-Level Protocols.iml
Created July 27, 2016 11:00
<<Network programming with Go>> Chapter Application-Level Protocols
<?xml version="1.0" encoding="UTF-8"?>
<module type="GO_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Go 1.6.2" jdkType="Go SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="GOPATH &lt;Application-Level Protocols&gt;" level="project" />
</component>
</module>
@ruandao
ruandao / Security_Blowfish.go
Created July 28, 2016 06:39
<<Network programming with Go>> Security
package main
import (
"github.com/crypto/blowfish"
"fmt"
"bytes"
)
func main_Blowfish() {
key := []byte("my key")
@ruandao
ruandao / configureStore.js
Last active September 30, 2016 17:40
redux store file
import { createStore, combineReducers, compose, applyMiddleware } from 'redux';
import ReduxThunk from 'redux-thunk';
import { routerMiddleware } from 'react-router-redux';
import { hashHistory } from 'react-router';
import * as Reducers from '../reducers';
export default function configureStore(initialState) {
const store = createStore(
combineReducers(Reducers),
initialState,
@ruandao
ruandao / exercise-2.12.rkt
Created November 16, 2016 03:20
eopl 2.12
(define (empty-stack)
(lambda (action)
(cond ((eq? action 'top)
(repo-empty-stack-err))
((eq? action 'empty)
#t)
((eq? action 'pop)
(repo-empty-stack-err))
(else (repo-no-support-err)))))
# Requires Python 2.x, flask and pywin32
from flask import Flask
import flask
import win32com.client
import pythoncom
import os, os.path, sys, time
# Flask (Web Server)
ws = Flask(__name__)
@ruandao
ruandao / trace.go
Created July 5, 2018 11:38
用于统计某个函数执行了多久 defer Trace(xxx...)()
// Trace trace
func Trace(name string, param ...interface{}) func() {
if !TraceSwitch {
return func() {}
}
start := time.Now()
log.Println("####Enter", name, param)
return func() {
@ruandao
ruandao / connector.go
Created July 6, 2018 10:05
rpc call err: gob: type not registered for interface: map[string]interface {} 原因是: args 里面一个字段是interface{}, 然后赋值的时候,赋值为map[string]interface{} 结果就跪了一天。。。。
args := BussinessRPC.ProcessMsg{
UserId: cor.userId,
Message: message,
TimeStamp: time.Now().Format("2006-01-02 15:04:05.000"),
}
reply := &BussinessRPC.ProcessMsgReply{}
service := "FreeStyleGame.Process"
conn, err := rpc.Dial("tcp", address)
@ruandao
ruandao / x.go
Created July 6, 2018 10:12
2018/07/06 18:10:51 call err: gob: type not registered for interface: map[string]interface {} panic: call err: gob: type not registered for interface: map[string]interface {} 确定原因是,map赋值给interface{}字段 也就是说,rpc调用不支持interface{}字段咯
package main
import (
"net/rpc"
"log"
"fmt"
)
func failOnErr(err error, s string) {
if err != nil {