Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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)
package main
import (
"flag"
"github.com/alecthomas/template"
"net/http"
"log"
)
var addr = flag.String("addr", ":1718", "http service addresses")
package main
import "fmt"
func main() {
ch := make(chan int, 2)
ch <- 1
ch <- 2
fmt.Println(<-ch)
fmt.Println(<- ch)
@ruandao
ruandao / 3.51.scm
Created December 21, 2015 07:25
sicp 3.51
(restart 1)
(load "stream.scm")
(define (stream-map proc . argstreams)
(if (stream-null? (car argstreams))
the-empty-stream
(let ((s1 (apply proc (map stream-car argstreams))))
(display s1)
(cons-stream
s1
@ruandao
ruandao / 2.90.rkt
Created December 7, 2015 09:18
2.90
;#lang planet neil/sicp
#lang racket
(require (planet soegaard/sicp:2:1/sicp))
(define wave einstein)
(define (put x) x)
(define (get x) x)
(define (get-coercion x) x)
(define (put-coercion x) x)
(define (square x) (* x x))
@ruandao
ruandao / 2.82.rkt
Last active December 5, 2015 06:50
2.82
;#lang planet neil/sicp
#lang racket
(require (planet soegaard/sicp:2:1/sicp))
(define wave einstein)
(define (put x) x)
(define (get x) x)
(define (get-coercion x) x)
(define (put-coercion x) x)
(define (square x) (* x x))
@ruandao
ruandao / 2.81.rkt
Last active December 5, 2015 02:57
2.81
;#lang planet neil/sicp
#lang racket
(require (planet soegaard/sicp:2:1/sicp))
(define wave einstein)
(define (put x) x)
(define (get x) x)
(define (get-coercion x) x)
(define (put-coercion x) x)
(define (square x) (* x x))
@ruandao
ruandao / 2.80.rkt
Created December 4, 2015 03:35
2.80
;#lang planet neil/sicp
#lang racket
(require (planet soegaard/sicp:2:1/sicp))
(define wave einstein)
(define (put x) x)
(define (get x) x)
(define (square x) (* x x))
;; type-tag, contents, attach-tag
(define (attach-tag tag contents)