Skip to content

Instantly share code, notes, and snippets.

View mvmaasakkers's full-sized avatar

Martijn van Maasakkers mvmaasakkers

View GitHub Profile
@mvmaasakkers
mvmaasakkers / gist:7335471
Last active December 27, 2015 13:48
Fix for content-disposition issues on multipart forms via php://input (for instance PUT requests)
<?php
function getPostfieldsFromInput() {
$ct = $_SERVER['CONTENT_TYPE'];
$position = stripos($ct, "multipart/form-data;");
$input = file_get_contents("php://input");
$postVars = array();
if($position !== false) {
$exp = explode("boundary=", $ct);
@mvmaasakkers
mvmaasakkers / simplemongoiteration.go
Created February 19, 2014 09:01
Simple iteration of mongo documents
// This is an example program that iterates over all
// items in a mongodb collection in a memory safe way
package main
import (
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"fmt"
)
@mvmaasakkers
mvmaasakkers / goget.sh
Last active August 29, 2015 14:01
This script go get's package from a private repo. This is currently not possible with go get itself, but the workaround is pretty easy
# Usage: goget.sh [package]
# Example: goget.sh bitbucket.org/username/repo
# This script relies on keys being set correctly and $GOPATH being available
mkdir -p $GOPATH/src/$1
git clone git://$1 $GOPATH/src/$1
go get $1
@mvmaasakkers
mvmaasakkers / init_test.go
Last active November 8, 2016 06:40
init_test.go TestMain
// This file is part of https://github.com/mvmaasakkers/gohttptestmongodb/
// Server holds the dbtest DBServer
var Server dbtest.DBServer
// TestMain wraps all tests with the needed initialized mock DB and fixtures
func TestMain(m *testing.M) {
// The tempdir is created so MongoDB has a location to store its files.
// Contents are wiped once the server stops
tempDir, _ := ioutil.TempDir("", "testing")
Server.SetPath(tempDir)
@mvmaasakkers
mvmaasakkers / init_test.go
Last active November 8, 2016 06:50
init_test.go Fixtures
// This file is part of https://github.com/mvmaasakkers/gohttptestmongodb/
// Pages fixtures are intentionally setup as map[string]Page so I can easily select them from within the tests
var pages = map[string]Page{
"ding": Page{Slug: "ding", Name: "Ding!", Content: "<i>HTML Awesomeness</i>"},
"dong-ding": Page{Slug: "dong-ding", Name: "Dong! Ding!", Content: "<b>HTML Awesomeness</b>"},
}
// insertFixtures just inserts all pages (and other types) I've defined above.
func insertFixtures() {
for _, page := range pages {
@mvmaasakkers
mvmaasakkers / handlers_test.go
Created November 8, 2016 06:51
handlers_test.go
// This file is part of https://github.com/mvmaasakkers/gohttptestmongodb/
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
"unicode"
195, 221
132, 132
333, 192
75, 354
162, 227
150, 108
46, 40
209, 92
153, 341
83, 128
package main
import (
"bufio"
"flag"
"fmt"
"log"
"math"
"os"
)
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"strconv"
"strings"
)