Skip to content

Instantly share code, notes, and snippets.

View smallnest's full-sized avatar

smallnest smallnest

View GitHub Profile
// First: go get github.com/golang/glog
// Then : go test -v -vmodule=*=3 -logtostderr netgrace_test.go
// This test package shows how to gracefully shutdown a net.Listener.
package netgrace
import (
"bufio"
"fmt"
"github.com/golang/glog"
@smallnest
smallnest / link.txt
Created March 22, 2019 08:40
Examples using the Docker Engine SDKs and Docker API
package auth
import (
"net/http"
"net/url"
"strings"
"time"
"colobu.com/tr/common/data"
"colobu.com/tr/common/db"
@smallnest
smallnest / go-os-arch.md
Created February 27, 2019 03:58 — forked from asukakenji/0-go-os-arch.md
Go (Golang) GOOS and GOARCH

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.8.3 darwin/amd64.

A list of valid GOOS values

(Bold = supported by go out of the box, ie. without the help of a C compiler, etc.)

  • android
  • darwin
@smallnest
smallnest / LowPrioritySystem_linux.go
Created February 16, 2019 00:58 — forked from jpramirez/LowPrioritySystem_linux.go
Fast & Furious (And extremely dirty) way to low the priority value of a process for windows and linux
package components
import "syscall"
func setpriority() {
syscall.Setpriority(syscall.PRIO_PGRP, 0, 9)
}
### IMPROVE SYSTEM MEMORY MANAGEMENT ###
# Increase size of file handles and inode cache
fs.file-max = 2097152
# Do less swapping
vm.swappiness = 10
vm.dirty_ratio = 60
vm.dirty_background_ratio = 2
@smallnest
smallnest / fanout_test.go
Created January 29, 2019 03:57 — forked from crast/fanout_test.go
Benchmarking Reflect Channel Ops
// This is a test where I was trying to isolate how much we lost to `reflect`
// with channel operations in a tight loop.
//
// PREAMBLE
// We do a lot of processing of stream data where ordering with respect to a
// shard indicator like user ID matters. We've done this a few times where we
// implement fanout based on hashing into an slice/array of channels, and it's
// lightning fast but it ends up leaving a lot of boilerplate in your code.
//
// So I started writing a library that would do the non-critical boilerplate
#!/bin/bash -e
protobuf_directories=$(find . -not -path ./.git/ -not -path ./.idea/ -type d -name "pb")
googleapis_path=$(go list -m -f '{{.Dir}}' github.com/googleapis/googleapis)
while read -r p; do
echo "generating protobuf for $p"
protoc -I. -I$googleapis_path --go_out=plugins=grpc:. $p/*.proto
done <<< "$protobuf_directories"