Skip to content

Instantly share code, notes, and snippets.

View dgrijalva's full-sized avatar

Dave Grijalva dgrijalva

View GitHub Profile
@dgrijalva
dgrijalva / fatal.go
Created April 20, 2016 01:07
The function I copy/paste into every go command line tool
// Like printf, but then it dies
func fatal(msg string, more ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", more...)
os.Exit(1)
}
@dgrijalva
dgrijalva / example_server.go
Created April 28, 2014 23:39
Setting scheme on http and https server
package main
import (
"fmt"
"net/http"
"github.com/fitstar/falcore"
"github.com/fitstar/falcore/filter"
"sync"
)
@dgrijalva
dgrijalva / gist:10915412
Last active August 29, 2015 13:59
keybase claim

Keybase proof

I hereby claim:

  • I am dgrijalva on github.
  • I am dgrijalva (https://keybase.io/dgrijalva) on keybase.
  • I have a public key whose fingerprint is 7725 D335 6856 8840 D2F4 6E40 86C1 1802 3E61 AFCD

To claim this, I am signing this object:

@dgrijalva
dgrijalva / scope_example.go
Created September 11, 2013 00:23
An example of a subtle bug you can run into when using the JSON decoder. Try it both ways. You'll see what's what.
package main
import (
"encoding/json"
"fmt"
)
var A = []byte(`{"foo": "bar"}`)
var B = []byte(`{"bar": "baz"}`)
@dgrijalva
dgrijalva / wait_group.rb
Created July 11, 2013 00:05
Wait Group in ruby using ConditionVariable
require 'thread'
class WaitGroup
def initialize
@count = 0
@done = false
@cond = ConditionVariable.new
@lock = Mutex.new
end
@dgrijalva
dgrijalva / renamer.go
Created April 6, 2013 22:07
Experimenting with code generation using `go/ast`. I wanted to see if it was practical to use compilable go code as a template for project generation. For example: if you wanted to be able to generate a falcore app from a template, what would that look like? If you could keep the template file looking like regular go source code (without templat…
package main
import (
"fmt"
"os"
"strings"
"go/parser"
"go/token"
"go/ast"
"go/printer"
@dgrijalva
dgrijalva / lots.go
Created April 3, 2013 01:33
Testing resulting sizes based on imports
package main
import (
"github.com/fitstar/falcore"
_ "github.com/fitstar/falcore/compression"
_ "github.com/fitstar/falcore/etag"
_ "github.com/fitstar/falcore/upstream"
_ "github.com/fitstar/falcore/static_file"
)
@dgrijalva
dgrijalva / gist:3716580
Created September 13, 2012 18:41
BSON encoding issues with mgo
package main
import (
"launchpad.net/mgo/v2"
"launchpad.net/mgo/v2/bson"
)
type insertType struct {
Foo bson.ObjectId `bson:"foo,omitempty"`
}
@dgrijalva
dgrijalva / echo_shell.go
Created June 26, 2012 20:10
Echo shell. To test edsrzf/fineline
package main
import (
"fmt"
"github.com/edsrzf/fineline"
)
func main(){
lr := fineline.NewLineReader(nil)
@dgrijalva
dgrijalva / gist:1364867
Created November 14, 2011 19:26
Runaway deadlocked goroutines
package main
import (
"fmt"
"runtime"
"time"
)
func main() {
go count()