Skip to content

Instantly share code, notes, and snippets.

@tidwall
tidwall / coreperf.go
Last active January 7, 2018 22:57
go performance for multi core machines
package main
import (
"flag"
"fmt"
"math/rand"
"runtime"
"sync"
"sync/atomic"
"time"
@tidwall
tidwall / echo-server.go
Created November 2, 2017 12:31
Echo server on port 5000
package main
import "net"
func main() {
ln, err := net.Listen("tcp", ":5000")
if err != nil {
panic(err)
}
defer ln.Close()
@tidwall
tidwall / gjson-parent-from-child-array.go
Last active September 16, 2017 21:55
get parent from child array path
package main
import (
"fmt"
"github.com/tidwall/gjson"
)
func main() {
json := `
@tidwall
tidwall / tile38-reverse-lookup.md
Created September 11, 2017 19:16
Tile38 reverse lookup

Standard points

SET poi 1 POINT 34.849 -111.9287
SET poi 2 POINT 32.893 -111.6650
SET poi 3 POINT 36.123 -110.3027
SET poi 4 POINT 35.746 -108.0175
SET poi 5 POINT 33.431 -107.0947
          
@tidwall
tidwall / keepitup.sh
Created August 29, 2017 01:49
100% code coverage. Keep that shit up!
go() { if [[ $@ == "test -cover" ]]; then r="$(command go test -cover)"; if \
[ "$r" != "" ]; then printf "%s\n" "$r"; fi; if [[ "$r" == *"100.0%"* ]]; then \
printf "🎉 \e[1mYou're pretty fucking awesome. Keep that shit up!\e[0m 🎉\n"; \
fi; else command go "$@"; fi }
@tidwall
tidwall / pretty-geojson.go
Last active June 8, 2017 17:34
Pretty format GeoJSON Features
package main
import (
"github.com/tidwall/gjson"
"github.com/tidwall/pretty"
)
var json = []byte(`
{
"type": "Feature",
@tidwall
tidwall / geobin.md
Last active March 18, 2017 21:17
Geobin format

Geobin File Format

Geobin File Format

This format covers the latest GeoJSON at https://tools.ietf.org/html/rfc7946.

It does not support foreign members, and only support 2D and 3D objects.

The entire binary should exist inside a container which already knows it's
size, for example a key value store where the value is the geobin bytes.
@tidwall
tidwall / main.go
Created February 9, 2017 20:00
Delete multiple items with S|GJSON
package main
import (
"fmt"
"log"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
@tidwall
tidwall / help_test.go
Created January 16, 2017 14:37
Golang Testing Helpers
func testOrDie(t testing.TB, fn func() error) {
if err := fn(); err != nil {
testFatal(t, 1, err)
}
}
func testFatalf(t testing.TB, skip int, format string, args ...interface{}) {
if _, file, line, ok := runtime.Caller(skip + 1); ok {
msg := fmt.Sprintf(format, args...)
t.Fatalf("\r\t%s:%d: %s", filepath.Base(file), line, msg)
@tidwall
tidwall / example.js
Last active June 14, 2018 20:32
Connect to a live geofence in Tile38 using Node.js
openFence(9851, "localhost",
["NEARBY", "fleet", "FENCE", "POINT", "33", "-115", "1000"],
function(message){
console.log(message)
},
function(err){
console.log(err)
},
function(){
console.log("closed")