Skip to content

Instantly share code, notes, and snippets.

View daemonl's full-sized avatar

Damien Whitten daemonl

View GitHub Profile
@daemonl
daemonl / go#70.go
Last active December 16, 2015 17:40
Solution to go tutorial #70
package main
import (
"fmt"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)
@daemonl
daemonl / libpoint.go
Last active March 10, 2016 23:52
CGO and FFI - Struct
package main
/*
struct point {
int x;
int y;
};
*/
import "C"
@daemonl
daemonl / broken.rs
Created March 13, 2016 03:17
Broken Rust Thing
extern crate iron;
extern crate rustc_serialize;
extern crate router;
use iron::prelude::*;
use iron::status;
use router::Router;
use std::sync::{Arc, Mutex};
use rustc_serialize::json;
@daemonl
daemonl / dependency-struct-closure.go
Last active April 4, 2018 02:01
Go Dependency Injection
type UserHandlerDependencies struct {
UserDatastore
UserEnricher
}
func BuildUserHandler(deps UserHandlerDependencies) http.Handler {
return http.HandlerFunc(rw http.ResponseWriter, req *http.Request) {
// Parse Request
user, err := deps.GetUser(username)
enriched := deps.EnrichUser(user)
"14b38e6b-1c85-480e-9f88-fb431fc137d5"
"43ae147e-c791-4ab1-83a7-6e8ee38190be"
"58b586d8-5885-47c5-861f-fa2b612a37ab"
"61a1bbea-b541-4cea-b155-d6e283b66299"
"63cfc56c-b961-47d0-a2bd-711e516cdce4"
"66c5ed9a-d4bc-41c8-8638-257a0b828c0e"
"799958c2-e764-4216-bbb1-eebaff881ae8"
"92cdbf8d-9d92-494b-a040-bf1ff69b31a1"
"a17bbc11-c982-4b60-832b-c6520dcc1760"
"ca5c2522-ca58-4e55-b242-853371e3bc00"