Skip to content

Instantly share code, notes, and snippets.

View timbogit's full-sized avatar

Tim Schmelmer timbogit

View GitHub Profile
@timbogit
timbogit / eigenclasses.rb
Created March 8, 2012 05:19
Musing on the Ruby object model in Ruby 1.8.7 vs. 1.9.3
obj = Object.new
puts "obj is #{obj}"
eigobj = class << obj
self
end
puts "Eigenclass of obj is #{eigobj}"
puts "Superclass of the eigenclass of obj is #{eigobj.superclass}"
eigclassobj = class << obj.class
@timbogit
timbogit / slice_ex.go
Last active December 17, 2015 01:19
Go exercise for "Slices"
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
// allocate 'dy' row slices of []unit8
rows := make([][]uint8, dy)
for i, row := range rows {
// allocate 'dx' uint8 points in each row
row = make([]uint8, dx)
@timbogit
timbogit / maps_ex.go
Created May 7, 2013 04:01
Maps exercise in Go tour
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
res := make(map[string]int)
@timbogit
timbogit / cubic_root_ex.go
Created May 7, 2013 15:13
Cubic Root exercise for Go lang tour
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
z := complex128(1)
for i := 0; i < 100; i++ {
@timbogit
timbogit / http_server_ex.go
Created May 8, 2013 03:49
Go tour HTTP Server exercise
package main
import (
"fmt"
"net/http"
)
type String string
@timbogit
timbogit / bintree_ex.go
Created May 9, 2013 03:28
Go lang tour exercise around Equivalent Binary Trees
package main
import (
"code.google.com/p/go-tour/tree"
"fmt"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
@timbogit
timbogit / for-select.go
Created August 8, 2013 06:10
for-select loop for a feed reader as presented in "Advanced Go Concurrency Patterns" (Sameer Ajmani, Google I/O 2013)
func (s *sub) loop() {
var pending []Item // appended by fetch; consumed by send
var next time.Time // initially January 1, year 0
var err error // set when Fetch fails
for {
var first Item
var updates chan Item
if len(pending) > 0 {
first = pending[0]
@timbogit
timbogit / go_challenge_works.go
Created November 1, 2013 16:46
Working variadic function with interfaces as arguments
package main
import (
"fmt"
)
type TestStruct struct {
int
string
}
@timbogit
timbogit / go_challenge_error.go
Last active December 27, 2015 04:39
Variadic function of interfaces called with a string slice
package main
import (
"fmt"
)
type TestStruct struct {
int
string
}
@timbogit
timbogit / test.json
Created March 12, 2014 23:55
test gist from gist-it app
{"hello": "world"}