Skip to content

Instantly share code, notes, and snippets.

View nanoninja's full-sized avatar

Vincent Letourneau nanoninja

View GitHub Profile
@nanoninja
nanoninja / service.go
Created June 16, 2016 07:37
Service Container
package service
import (
"fmt"
"sync"
)
type key int
type Service func() interface{}
// Copyright 2016 The Nanoninja Authors. All rights reserved.
package main
import (
"io"
"log"
"os"
)
@nanoninja
nanoninja / main.go
Last active July 10, 2016 09:55
Go Middleware
// Copyright 2016 Vincent Letourneau.
package main
import (
"fmt"
"net/http"
)
func AuthMiddleware(next http.Handler) http.Handler {
@nanoninja
nanoninja / xml2json.php
Created February 12, 2016 07:56
PHP Encode / Decode data structures
<?php
$dom = simplexml_load_string(
'<root>
<langage>PHP</langage>
<version>7</version>
<parent>
<version>5</version>
</parent>
</root>'
@nanoninja
nanoninja / channel.go
Last active January 28, 2016 14:11
Channel Example
package main
import "fmt"
func main() {
ch := make(chan string)
go func(c chan string) {
ch <- "Hello Gopher"
}(ch)
@nanoninja
nanoninja / ctx_handler.go
Created December 13, 2015 16:24
Go Context Handler
package main
import (
"fmt"
"golang.org/x/net/context"
"log"
"net/http"
"os"
)
@nanoninja
nanoninja / middleware.go
Created December 10, 2015 21:09
Simple HTTP Middleware
package main
import (
"fmt"
"log"
"net/http"
)
func myHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("myHandler\n"))
@nanoninja
nanoninja / barcharts.php
Last active January 28, 2016 11:31
PHP Simple Bar Charts
<?php
// Get random data
function getRandScore($nb = 10) {
$data = array();
for ($i = 0; $i < $nb; $i++) {
$data[] = rand(5, 299);
}
return $data;
}
@nanoninja
nanoninja / box.go
Last active November 26, 2015 22:04
Box of Services
// Copyright 2015 The Nanoninja Authors. All rights reserved.
package box
import "time"
// ServiceFunc registers the service function.
type ServiceFunc func(b *Box) interface{}
type Box struct {
@nanoninja
nanoninja / container.go
Created November 6, 2015 21:14
ServiceContainer
// Copyright 2015 The Nanoninja Authors. All rights reserved.
package container
// ServiceFunc registers the service function.
type ServiceFunc func(c *container) interface{}
type container struct {
name string
services map[string]interface{}