Skip to content

Instantly share code, notes, and snippets.

View nanoninja's full-sized avatar

Vincent Letourneau nanoninja

View GitHub Profile
@nanoninja
nanoninja / RegexRouter.php
Last active May 28, 2022 16:41
Simple Regex Router
class RegexRouter
{
private $routes = array();
public function addRoute($route, callable $service)
{
$route = '#^'.$route.'$#';
$this->routes[$route] = $service;
return $this;
}
@nanoninja
nanoninja / SortingArrayWithWeight.php
Last active August 29, 2015 14:03
Sorting array with weight
// Sorts by weight
$data = array(
array(
'language' => 'PHP',
'weight' => 50,
),
array(
'language' => 'Java',
'weight' => 20,
@nanoninja
nanoninja / array_list.go
Last active August 29, 2015 14:05
ArrayList
package main
type (
ListKey string
ListVal interface{}
)
type ArrayList struct {
list map[ListKey]ListVal
}
@nanoninja
nanoninja / kgen.go
Created February 10, 2015 15:11
KeyGenGo
// https://play.golang.org/p/zu7mtEWy7e
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"os"
@nanoninja
nanoninja / number.go
Created May 24, 2015 10:36
Go Number Type
type Number float64
func (n *Number) Increase() {
*n++
}
func (n *Number) Decrease() {
*n--
}
@nanoninja
nanoninja / sleep.service
Created August 10, 2015 12:17
Sleep SystemD service
[Unit]
Description=Sleep Service
Requires=docker.service
# Dependency ordering
After=docker.service
[Service]
Restart=always
ExecStartPre=-/usr/bin/docker rm %p
@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{}
@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 / 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 / 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"))