Skip to content

Instantly share code, notes, and snippets.

Josh Baker tidwall

Block or report user

Report or block tidwall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tidwall
tidwall / bench_test.go
Created Jan 29, 2020
Benchmark sjson vs Go for simples json updates
View bench_test.go
package bench
import (
"encoding/json"
"testing"
"github.com/tidwall/sjson"
)
var data = []byte(`{
@tidwall
tidwall / ints2bools.go
Last active Mar 26, 2019
@ints2bools gjson modifier
View ints2bools.go
package main
import "github.com/tidwall/gjson"
func init() {
// define the @ints2bools modifier once.
gjson.AddModifier("ints2bools", func(json, _ string) string {
res := gjson.Parse(json)
switch res.Type {
case gjson.Number:
@tidwall
tidwall / main.go
Created Mar 13, 2019
Go 1.12 network slowdown on Darwin
View main.go
package main
import (
"fmt"
"io"
"log"
"net"
"os"
"sync"
"sync/atomic"
@tidwall
tidwall / tile38-location-hist.lua
Created Jul 27, 2018
Tile38 save short history of the last 10 locations for a given point
View tile38-location-hist.lua
-- 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 / go-cover.sh
Created May 27, 2018
Go cover helper with html output
View go-cover.sh
# add this to your ~/.bash_profile or whatnot
go(){
local r
if [[ $@ == "test -cover" ]]; then
r="$(command go test -coverprofile=/tmp/coverage.out)"
if [ "$r" != "" ]; then
printf "%s\n" "$r"
fi
if [[ "$r" == *"100.0%"* ]]; then
@tidwall
tidwall / build.sh
Last active May 26, 2018
Pass custom var strings to gcc
View build.sh
gcc -DgitSHA="$(git rev-parse HEAD)" main.c
View evio_context.go
type myConn struct {
}
func main(){
var events Events
events.Opened = func(id int, info evio.Info) (out []byte, opts evio.Options, ctx interface{}, action evio.Action){
// create a new connection object that is specific to the new connection
// and assign to the context interface. this will be passed through other events.
conn := &myConn{}
ctx = conn
return
@tidwall
tidwall / evio.go
Created Apr 27, 2018
Multi-threaded Evio
View evio.go
package main
import (
"log"
"runtime"
"github.com/tidwall/evio"
)
func main() {
@tidwall
tidwall / EVIO_REUSEPORT.md
Created Mar 18, 2018
Evio with SO_REUSEPORT
View EVIO_REUSEPORT.md

Evio with SO_REUSEPORT

Using the reuseport branch of evio, you can now provide an SO_REUSEPORT address options from the Serve function.

evio.Serve(events, "tcp://0.0.0.0:5000?reuseport=true")

This allows for multiple process/threads/goroutines to share the same address+port.

@tidwall
tidwall / tile38.geojson
Last active Mar 9, 2018
tile38.geojson
View tile38.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.