Skip to content

Instantly share code, notes, and snippets.

View cespare's full-sized avatar

Caleb Spare cespare

View GitHub Profile
source "https://rubygems.org"
gem "toml", :git => "git://github.com/jm/toml", :ref => "479353753fc71173e9a8f778a9c3c20a0f92d189"
gem "json"
@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 / Gemfile
Created November 8, 2012 06:07
Repro case for Bundler issue #1083
source :rubygems
gemspec
@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 / pygments_example.go
Created October 1, 2012 23:23
A first hello-world attempt at pygments.go
package main
// #cgo CFLAGS: -I/usr/include/python2.7
// #cgo LDFLAGS: -lpython2.7
// #include <Python.h>
// int pyRunString(const char *s) { return PyRun_SimpleString(s); }
import "C"
import "unsafe"
@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 / gist:3167123
Created July 24, 2012 00:19
Imagemagick (rmagick) benchmark
# Need to install imagemagick first.
# sudo apt-get install libmagickwand on ubuntu.
# Available on homebrew as well.
require "RMagick"
images = Dir["./*.png"]
start_time = Time.now
@cespare
cespare / config.json
Created June 16, 2012 01:08
Reverse routing proxy in Go
[
["/foo", "localhost:8090"],
["/bar", "google.com:80"],
["/", "localhost:3000"]
]
@cespare
cespare / gist:2403743
Created April 17, 2012 05:42
array of partials
# In your app
get "/whatever"
erb :_partial_collection, :layout => false, :locals => { partials => partials } # partials is an array of other partials...
end
# in views/_partial_collection.erb
<% partials.each { |partial| %><%= erb partial, :layout => false %><% } %>
@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")),