Skip to content

Instantly share code, notes, and snippets.

View cespare's full-sized avatar

Caleb Spare cespare

View GitHub Profile
@cespare
cespare / log.go
Created October 31, 2012 06:51
Golang apache logging
type ApacheLogRecord struct {
http.ResponseWriter
ip string
time time.Time
method, uri, protocol string
status int
responseBytes int64
elapsedTime time.Duration
}
@cespare
cespare / main.go
Created February 20, 2013 03:05
Example of testing Go HTTP servers using httptest.Server.
package main
import (
"log"
"myserver"
"net/http"
)
const addr = "localhost:12345"
@cespare
cespare / learninggo.md
Created September 17, 2018 21:16
My recommended resources for learning Go

Go is a fairly simple language and the best resources for learning it are online.

For a very gentle (if slow) introduction, you can go through the Go tour (you may wish to skip around).

The fastest way to ramp up on Go, though, is probably to read Effective Go end-to-end. This describes most of the language as well as common patterns and best practices.

@cespare
cespare / example.conf
Created September 27, 2014 23:08
example nginx reverse proxy config
server {
listen 80;
server_name mysite.example.com;
access_log /path/to/mysite.example.com.log;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# app server listens on localhost:9876
@cespare
cespare / writeup.md
Created September 27, 2012 11:39
A Simple Webserver Comparison

This is a very simple benchmark comparing the response times of a few different webservers for an extremely simple response: just reply with a snippet of static json. It came up in discussion of a real-life service: in the actual server, a long-running thread/process periodically updates the state from a database, but requests will be served with the data directly from memory. It is imperative, though, that the latencies be extremely low for this service.

This comparison was partly inspired by this blog post.

Method

@cespare
cespare / Vagrantfile
Created April 7, 2013 03:10
My default minimal Vagrantfile. Better than the huge thing 'vagrant init' generates.
Vagrant.configure("2") do |config|
config.vm.box = "quantal64"
config.vm.hostname = "give-this-a-name"
config.vm.box_url = "http://cloud-images.ubuntu.com/quantal/current/quantal-server-cloudimg-vagrant-amd64-disk1.box"
config.vm.provision :shell, :inline =>
"sudo mkdir -p /root/.ssh && sudo cp /home/vagrant/.ssh/authorized_keys /root/.ssh/"
# config.vm.network :forwarded_port, guest: 80, host: 8080
# config.vm.synced_folder "../data", "/vagrant_data"
@cespare
cespare / keybase.md
Created December 6, 2019 06:38
keybase proof of ownership

Keybase proof

I hereby claim:

  • I am cespare on github.
  • I am cespare (https://keybase.io/cespare) on keybase.
  • I have a public key ASATr7eIIdnBECuIIkhvPi8FqTxIoCZ24fljTvGtRs7IeQo

To claim this, I am signing this object:

source "https://rubygems.org"
gem "toml", :git => "git://github.com/jm/toml", :ref => "479353753fc71173e9a8f778a9c3c20a0f92d189"
gem "json"
@cespare
cespare / gist:2402610
Created April 17, 2012 00:45
Coffeescript function with multiple callbacks
foo = (f1, f2) ->
f1()
f2()
# Doesn't work -- syntax error
# foo(-> console.log("hi from f1"), -> console.log("hi from f2"))
# Simplest way I've found to do it -- newlines added for clarity
foo(
(-> console.log("hi from f1")),
@cespare
cespare / log.txt
Last active October 5, 2016 17:01
Log output for https://github.com/golang/go/issues/17341 reproducer
gc 1 @0.153s 0%: 0.067+1.3+0.22 ms clock, 0.20+0.026/1.2/3.4+0.67 ms cpu, 4->4->2 MB, 5 MB goal, 4 P
gc 2 @0.185s 0%: 0.050+2.0+0.064 ms clock, 0.15+0.011/1.9/5.2+0.19 ms cpu, 5->5->4 MB, 6 MB goal, 4 P
gc 3 @0.238s 0%: 0.011+2.8+0.19 ms clock, 0.044+0/2.8/8.4+0.78 ms cpu, 9->9->8 MB, 10 MB goal, 4 P
gc 4 @0.316s 1%: 0.077+4.4+0.22 ms clock, 0.23+1.1/4.3/11+0.67 ms cpu, 15->15->13 MB, 16 MB goal, 4 P
gc 5 @0.424s 1%: 0.009+6.7+0.18 ms clock, 0.039+0/6.6/19+0.75 ms cpu, 27->27->24 MB, 28 MB goal, 4 P
gc 6 @0.611s 1%: 0.011+13+0.20 ms clock, 0.045+0.010/13/39+0.81 ms cpu, 47->47->42 MB, 48 MB goal, 4 P
gc 7 @0.943s 1%: 0.031+21+0.19 ms clock, 0.12+0/21/63+0.78 ms cpu, 83->83->75 MB, 85 MB goal, 4 P
gc 8 @1.527s 1%: 0.043+39+0.084 ms clock, 0.17+0.019/38/113+0.33 ms cpu, 146->146->132 MB, 150 MB goal, 4 P
2016/10/05 09:59:31 NOOP: QPS: 10000
gc 9 @2.554s 2%: 0.056+79+3.2 ms clock, 0.22+44/75/152+13 ms cpu, 259->263->239 MB, 265 MB goal, 4 P