Skip to content

Instantly share code, notes, and snippets.

View cespare's full-sized avatar

Caleb Spare cespare

View GitHub Profile
@cespare
cespare / results.txt
Created March 20, 2014 19:03
Print out stdlib packages not used within the stdlib.
$ go run unused.go
container/ring
debug/gosym
debug/pe
encoding/ascii85
encoding/csv
expvar
go/build
hash/crc64
hash/fnv

Dump redis rdb files to json. Many limitations, including:

  • Only one DB allowed
  • Only plain key/vals and hashes allowed (no sets, lists, zsets for now)

3x faster than rdbtool for my test dump:

$ time rdb --command json dump.rdb > rdbtool.json 
rdb --command json  > rdbtool.json  264.65s user 0.80s system 99% cpu 4:25.93 total
@cespare
cespare / md.html
Last active August 29, 2015 14:10
rendered markdown exmaple
<h1>Reflex</h1>
<p>Reflex is a small tool to watch a directory and rerun a command when certain files change. It's great for
automatically running compile/lint/test tasks and for reloading your application when the code changes.</p>
<h2>A simple example</h2>
<div class="highlight"><pre># Rerun make whenever a .c file changes
reflex -r &#39;\.c$&#39; make
</pre></div>
@cespare
cespare / foo_test.go
Created January 22, 2015 22:37
Example of excluding tests with build tags
package foo
import "testing"
func TestFoo(t *testing.T) {
t.Log("A")
}
@cespare
cespare / lambda.py
Created April 4, 2011 17:49
Python lambda gotcha
def callback(message):
print(message)
foo = ["a", "b", "c"]
# Environment variables are only captured as references by the lambda:
bar = [lambda: callback(s) for s in foo]
for f in bar:
f() # => c x 3
@cespare
cespare / gist:920767
Created April 14, 2011 22:52
fixed.js
var Foo;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Foo = (function() {
function Foo() {}
Foo.prototype.init = function() {
var lalala = this;
$("#submitButton").click(__bind(function(event) {
// throws an error "HTMLDocument element does not have property onSubmitButtonClicked
return this.onSubmitButtonClicked(event);
}, lalala));
@cespare
cespare / gist:1368825
Created November 16, 2011 00:03
scala default map updating
import scala.collection.mutable.Map
import scala.collection.mutable.Buffer
val foo = Map[Int, Buffer[Int]]() withDefault ((key) => Buffer())
foo(1) = Buffer(1, 2)
foo(1) += 3
foo(1) // => ArrayBuffer(1, 2, 3)
/* This all seems as expected */
@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 / 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: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