Skip to content

Instantly share code, notes, and snippets.

View jonathaningram's full-sized avatar

Jonathan Ingram jonathaningram

View GitHub Profile
@jonathaningram
jonathaningram / postmortem-on-garbage-jobs-posted-on-we-love-go.md
Last active May 28, 2019 08:11
Postmortem on garbage jobs posted on We Love Go

Postmortem on garbage jobs posted on We Love Go

The incident

Around 2019-05-27 04:12 UTC+10, 5 garbage job ads were posted on We Love Go’s website (https://welovegolang.com) and subsequently on its Twitter account (https://mobile.twitter.com/welovegolang).

One job ad in particular contained hateful language and I apologise to all of We Love Go’s users and Twitter followers for allowing it to occur.

Thank you to a few members of the We Love Go community for bringing the garbage jobs to my attention. I was also aware of them due to the notification email that I receive for each and every job that is posted.

@jonathaningram
jonathaningram / foo.js
Created November 26, 2017 21:36
A potential convention for exporting things from a JS module whose only purpose is to be unit-tested (i.e. not meant to be used publicly)
export const baz = () => {};
const bar = () => {};
bar.exportTest = true;
export bar;
@jonathaningram
jonathaningram / gofmt-is-not-opinionated-enough.md
Last active January 22, 2019 17:03
Go Experience Report regarding gofmt not being opinionated enough

Problem

Code reviews containing Go code have unnecessary and ongoing debates about style because gofmt is not opinionated enough.

gofmt does not do enough formatting and particularly it does not take the line length into account.

Comparing gofmt with prettier, in code reviews for a Javascript codebase, there are rarely debates about style-related issues because prettier is very opinionated.

Example: different ways to format method arguments

@jonathaningram
jonathaningram / README.md
Created April 25, 2017 22:13
Visual Studio Code formats Go HTML templates and causes the handlebar snytax to become invalid

In actual.html you can see that at line 6 some predicates have been pushed onto a new line which is not a valid Go html/template (causes error template: master:6: unclosed action).

I guess the Code HTML formatter is just treating the handlebars as a plain text node and honouring the max line length, but is it possible for the formatter to see that it's inside handlebars and not touch it?

@jonathaningram
jonathaningram / taskqueue_json_task.go
Created May 11, 2016 05:57
You can create an App Engine POST task with a JSON body as well as a form-encoded one. You just need to set the Payload and Content-Type.
package main
import (
"encoding/json"
"net/http"
"google.golang.org/appengine/taskqueue"
)
// NewJSONPostTask creates a Task that will POST to a path with the given body
@jonathaningram
jonathaningram / README.md
Created February 9, 2016 05:26
Google App Engine http.FileServer writes "Last-Modified:Thu, 01 Jan 1970 00:00:00 GMT" header

To see what happens with the std lib version,

go build && ./yourbin

Go to http://localhost:8080/ (make sure you force refresh if done in browser) and notice that the response header is OK:

Last-Modified:Tue, 09 Feb 2016 05:08:20 GMT
@jonathaningram
jonathaningram / README.md
Created November 18, 2015 03:23
Discrepancy between GAE Go SDK in dev and prod with regards to os.Getenv and env_variables

Deploy it for prod:

$ goapp deploy . 

Go to http://gae-test-1133.appspot.com/ (or replace with ) and notice that only one the runtime HELLO is the correct value: prefetched: "", runtime: "hello world"

Now run it in dev:

Question: could the child/overlay/aboutPage get the default content from the master with something like {{parent}} or {{master}}?

E.g.

const (
    layout  = `<title>{{block "metaTitle" .}}golang.org{{end}}</title><body>{{block "content"}}{{end}}</body>`
    aboutPage = `{{define "metaTitle"}}Read all about Go - {{parent}}{{end}} {{define "content"}}About page content{{end}}`
)
@jonathaningram
jonathaningram / handlers.go
Created July 1, 2015 04:33
Example "injecting" services into a HTTP handler using gorilla.pat and negroni
package web
func contactHandler(
res http.ResponseWriter,
req *http.Request,
csrf csrf.TokenManager,
nodeRepository node.Repository,
) {
}
@jonathaningram
jonathaningram / react-to-html-webpack-plugin-index.js
Last active August 29, 2015 14:23
Updating react-to-html-webpack-plugin to allow hashed JS assets to be resolved in the HTML template
var React = require('react');
var evaluate = require('eval');
// srcPath renamed to src since it can either be a filename or a chunk name
function ReactToHtmlWebpackPlugin(destPath, src, options) {
this.src = src;
this.destPath = destPath;
this.options = typeof options === 'object' ? options : {};
}