Skip to content

Instantly share code, notes, and snippets.

@3d0c
3d0c / cgo-sample.go
Created June 17, 2016 17:35
cgo samples
package main
/*
#include <string.h>
void write_int(int *len) {
*len = 10;
}
void write_int_array(int *sizes[]) {
@3d0c
3d0c / lcw.go
Created July 11, 2015 18:06
LCW Finder
// Longest compound word finder
//
// Usage: feed stid to the program
// E.g.:
// cat /tmp/123.txt | go run lcw.go
// curl http://norvig.com/ngrams/word.list | go run lcw.go
//
package main
import (
@3d0c
3d0c / gist:b73f80564510d93f6373
Created May 10, 2015 09:29
reverse proxy example
package main
import (
"file-api/oid"
c "file-api/proxy/controllers"
"file-api/proxy/models"
. "file-api/proxy/utils"
"github.com/3d0c/martini-contrib/binding"
"github.com/3d0c/martini-contrib/config"
"github.com/3d0c/martini-contrib/encoder"
@3d0c
3d0c / deploy.sh
Last active August 29, 2015 14:03
Dead Simple Deploy Script
moved to https://github.com/3d0c/deploy.sh
Wow. I've now read the whole book and much of the supporting code. I'm not a fan, and recommend against relying on it. Here's a laundry list of concerns:
* The teaching method the book uses is badly flawed. The book's strategy is to start simple and build to complexity, which makes sense if you're teaching algebra but not if you're teaching heart surgery. The result is that each chapter culminates with the implementation of a system that is grievously insecure. Little warning is given of this, apart from allusions to future chapters improving the system. For instance, Chapter 2 closes with a chat system that uses AES-CBC without an authenticator.
* The book is full of idiosyncratic recommendations. For instance, AES-CBC requires a padding scheme. There is a standard padding scheme. The book purports to present it, but instead of PKCS7, it presents 80h+00h..00h.
* At one point about 1/3rd of the way through the book, it suggests using a SHA256 hash of the plaintext as an authenticator for a message. This r
func main() {
s := []string{"this", "is", "a", "test"}
mapper := func(s string) string {
return "prefix-" + s
}
tap := func(s string) {
fmt.Printf("tap: %s\n", s)
@3d0c
3d0c / session.go
Last active January 2, 2016 19:09
func (iter *Iter) All(result interface{}) error {
resultv := reflect.ValueOf(result)
if resultv.Kind() != reflect.Ptr || (resultv.Elem().Kind() != reflect.Slice && resultv.Elem().Kind() != reflect.Interface) {
panic("result argument must be a slice address")
}
slicev := resultv.Elem()
if resultv.Elem().Kind() == reflect.Interface {
slicev = slicev.Elem().Slice(0, slicev.Elem().Cap())
} else {