Skip to content

Instantly share code, notes, and snippets.


rodrigo moraes moraes

  • Brazil
View GitHub Profile
View gist:5454562
File "/[...]/webapp/", line 23, in get
File "/[...]/webapp/sqlalchemy/", line 2784, in create_all
File "/[...]/webapp/sqlalchemy/engine/", line 1487, in _run_visitor
conn._run_visitor(visitorcallable, element, **kwargs)
File "/[...]/webapp/sqlalchemy/engine/", line 1130, in _run_visitor
File "/[...]/webapp/sqlalchemy/sql/", line 111, in traverse_single
return meth(obj, **kw)
View handlers.go
package foo
import (
type MethodHandler map[string]http.Handler
func (h MethodHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if handler, ok := h[req.Method]; ok {
moraes / test.go
Last active Dec 10, 2015
Hello World using gorilla/template
View test.go
package test
import (
func helloHandler(w http.ResponseWriter, r *http.Request) {
set := template.Must(new(template.Set).Parse(`{{define "hello"}}Hello, world!{{end}}`))
moraes / gist:4427246
Created Jan 1, 2013
text/template composition using {{block}} and {{fill}
View gist:4427246
// A base template with the layout skeleton.
// {{block}} actions define placeholders.
{{define "base"}}
<title>{{block "title"}}</title>
{{block "content"}}
moraes / gist:3889909
Created Oct 14, 2012
Distributed software heavy load performance test (higher is better)
View gist:3889909
moraes / AnideaforblocksemanticsinGostexttemplate.rst
Created Jul 9, 2012
An idea for {{block}} semantics in Go's text/template
View AnideaforblocksemanticsinGostexttemplate.rst

{{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}}

View gist:3070686
{template Master}
<p>A header</p>
{call .body}
<p>A footer</p>
{template Hello}
{template body}
<p>Hello, world!</p>
View gist:3070666
{{define "Master"}}
<p>A header</p>
{{template .body}}
<p>A footer</p>
{{define "Hello"}}
{{define "body"}}
Hello, world!
moraes / Mycrazyideatooverdotheconvenienceoftemplateinheritanceusingcomposition.rst
Created Jul 8, 2012
My crazy idea to overdo the convenience of template inheritance using composition
View Mycrazyideatooverdotheconvenienceoftemplateinheritanceusingcomposition.rst

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.

View gist:2909661
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.
You can’t perform that action at this time.