Skip to content

Instantly share code, notes, and snippets.

View campoy's full-sized avatar

Francesc Campoy campoy

View GitHub Profile
@campoy
campoy / parallel.go
Last active August 29, 2015 13:56
Mandelbrot snippets from github.com/campoy/mandelbrot, for a post on blog.campoy.cat
func fillImg(m *img) {
// init a WaitGroup with the number of pixels of the image
var wg sync.WaitGroup
wg.Add(m.h * m.w)
for i, row := range m.m {
for j := range row {
// Every pixel is computed in a different goroutine
// and the counter is decreased once it's done.
go func(i, j int) {
@campoy
campoy / main.go
Last active August 29, 2015 13:57
package main
import "github.com/campoy/cooltool/server"
func main() {
server.Run()
}
@campoy
campoy / notfound.html
Last active August 29, 2015 14:03
A small web server with a customized 404 page showed in two different ways, wrapping the ResponseWriter or wrapping the Handler
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>404 - not found</title>
<style>
* {
padding: 0;
margin: 0;
package main
import "fmt"
func main() {
fmt.Println("this is a test for Medium")
}
@campoy
campoy / main.go
Last active December 16, 2015 19:10
Small sample app on using goauth2
// Short example showing how to get an oauth2 token using a .pem key and how the token should be added
// to the http requests.
package main
import (
"fmt"
"io/ioutil"
"net/http"
"code.google.com/p/goauth2/oauth/jwt"
@campoy
campoy / wat.js
Created September 13, 2013 17:28
What do you think this will log?
var foo = 1;
func bar() {
if (!foo) {
var foo = 10;
}
console.log(foo);
}
bar();
@campoy
campoy / commands.go
Last active December 28, 2015 05:59
Running concurrently a list of commands
package main
type Command interface {
Run() error
}
func RunAll(cmds []Command) error {
for _, cmd := range cmds {
err := cmd.Run()
if err != nil {
@campoy
campoy / after.go
Created December 6, 2013 01:39
Goimports example
package main
import (
"fmt"
"math"
"code.google.com/p/go.tools/present"
)
var doc present.Doc
@campoy
campoy / gotourtodo.md
Last active January 2, 2016 01:29
TODO list for the new go tour

TODO

Features:

  • Page navigation with Right/left instead of Page Up/down (@mattetti)
  • Allow navigation from the editor (egon)
  • Responsive design
  • Keep the sliders on place after changing page/module (cookies?)

Bugs:

@campoy
campoy / app.go
Created November 18, 2016 23:48
Go Echo Server on Flex with Endpoints
// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
// Sample endpoints demonstrates a Cloud Endpoints API.
package main
import (
"encoding/json"
"fmt"