Skip to content

Instantly share code, notes, and snippets.

@moraes
moraes / gist:2370781
Created April 12, 2012 20:32
GetPage for App Engine datastore (Go)
package foo
import (
"reflect"
"appengine"
"appengine/datastore"
)
var (
@moraes
moraes / server.go
Created May 2, 2012 16:02 — forked from jaybill/server.go
gorilla sessions issue
package main
import (
"encoding/gob"
"net/http"
"code.google.com/p/gorilla/sessions"
"log"
)
var store = sessions.NewCookieStore([]byte("something-very-secret"))
@moraes
moraes / gist:2647771
Created May 9, 2012 18:33
bash profile for golang
# Go
export GOOS=linux
export GOARCH=amd64
export GOROOT=$HOME/dev/go
export GOBIN=$GOROOT/bin
export GOPATH=$HOME/dev/gopath
export PATH=$PATH:$GOBIN
import webapp2
from webapp2_extras import local
_local = local.Local()
# The deferred handler instantiates webapp2.WSGIApplication in the module
# globals, so when it is imported it ends resetting app globals.
# To avoid this we duplicate the globals part of the WSGIApplication here,
# knowing that only we will instantiate it.
@moraes
moraes / Mycrazyideatooverdotheconvenienceoftemplateinheritanceusingcomposition.rst
Created July 8, 2012 08:33
My crazy idea to overdo the convenience of template inheritance using composition

My crazy idea to overdo the convenience of template inheritance using composition

This idea will be patented soon. Go away, Apple.

TL;DR: Django created template inheritance and people thought it was awesome and everybody copied it. Go doesn't have it, people cried. We got an idea to make people happy again, without changing text/template syntax.

{{define "Master"}}
<p>A header</p>
{{template .body}}
<p>A footer</p>
{{end}}
{{define "Hello"}}
{{define "body"}}
Hello, world!
{{end}}
{template Master}
<p>A header</p>
{call .body}
<p>A footer</p>
{end}
{template Hello}
{template body}
<p>Hello, world!</p>
{end}
@moraes
moraes / AnideaforblocksemanticsinGostexttemplate.rst
Created July 9, 2012 14:08
An idea for {{block}} semantics in Go's text/template

{{block}} in text/template

We can achieve what is known as "template inheritance" in other template engines using the {{block}} tag. A {{block}} is a replaceable fragment inside a template. Here's an example:

{{define "Base"}}

<p>A header</p>

{{block body}}

@moraes
moraes / gist:3889909
Created October 14, 2012 21:42
Distributed software heavy load performance test (higher is better)
Node.js.....73,749
Go.........286,483
@moraes
moraes / gist:4427246
Created January 1, 2013 12:59
text/template composition using {{block}} and {{fill}
// A base template with the layout skeleton.
// {{block}} actions define placeholders.
{{define "base"}}
<html>
<head>
<title>{{block "title"}}</title>
</head>
<body>
{{block "content"}}
</body>