Skip to content

Instantly share code, notes, and snippets.

@tidwall
tidwall / bboxbounds.go
Created January 11, 2018 20:30
Calculate the bounds of geo circle
package bboxbounds
import "math"
func BBoxBounds(lat, lon, meters float64) (latMin, lonMin, latMax, lonMax float64) {
// see http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#Latitude
lat = lat * (math.Pi / 180)
lon = lon * (math.Pi / 180)
r := meters / 6371e3 // angular radius
@tidwall
tidwall / tile38-location-hist.lua
Created July 27, 2018 23:18
Tile38 save short history of the last 10 locations for a given point
-- add the point
tile38.call("SET", ARGV[1], ARGV[2], "POINT", ARGV[3], ARGV[4])
-- get the previous history
local oldhist = tile38.call("GET", ARGV[1] .. ":history", ARGV[2])
if oldhist == nil then
oldhist = ""
end
-- parse the last 9 lines
@tidwall
tidwall / clientserver.go
Last active April 20, 2022 21:59
Simple Client Server using tidwall/sds
package main
import (
"errors"
"log"
"net"
"os"
"time"
"github.com/tidwall/sds"
@tidwall
tidwall / json_test.go
Last active April 19, 2022 22:23
Benchmark encoding json strings in Go (gjson, jsoniter, encoding/json)
package main
import (
"encoding/json"
"testing"
jsoniter "github.com/json-iterator/go"
"github.com/tidwall/gjson"
)
@tidwall
tidwall / main.go
Last active February 23, 2022 23:28
Uhaha using leveldb key/value store
package main
import (
"io"
"os"
"github.com/syndtr/goleveldb/leveldb"
"github.com/tidwall/sds"
"github.com/tidwall/uhaha"
)
@tidwall
tidwall / main.go
Last active July 12, 2021 20:36
Test Tile38 for Expiration Drift
// Test Tile38 for Expiration Drift
// Issue #616
package main
import (
"fmt"
"math/rand"
"sync"
"time"
@tidwall
tidwall / quote4.txt
Created September 1, 2020 18:32
quote4
If my cup won't hold but a pint, and yourn holds a quart, wouldn't ye be mean not to let me have my little half-measure full?
- Sojourner Truth
@tidwall
tidwall / quote3.txt
Created September 1, 2020 18:25
quote3
I attribute my success to this: I never gave or took any excuse.
- Florence Nightingale
@tidwall
tidwall / quote2.txt
Created September 1, 2020 18:25
quote2
A wise man can learn more from a foolish question than a fool can learn from a wise answer.
- Bruce Lee
@tidwall
tidwall / quote1.txt
Created September 1, 2020 18:24
quotes1
Love the life you live. Live the life you love.
- Bob Marley