Skip to content

Instantly share code, notes, and snippets.

View campoy's full-sized avatar

Francesc Campoy campoy

View GitHub Profile
@campoy
campoy / batchdb.go
Created June 21, 2019 19:41
Showing how to batch your writes automatically with WriteBatch
package main
import (
"log"
"math/rand"
"sync"
"time"
"github.com/dgraph-io/badger/v2"
)
@campoy
campoy / styles.css
Created April 6, 2018 21:32
Dark themed Go present (cmd/present/static/styles.css)
@import url('https://fonts.googleapis.com/css?family=Montserrat');
@import url('https://fonts.googleapis.com/css?family=Inconsolata');
@media screen {
/* Framework */
html {
height: 100%;
}
func merge(cs ...<-chan int) <-chan int {
out := make(chan int)
var wg sync.WaitGroup
wg.Add(len(cs))
for _, c := range cs {
go func(c <-chan int) {
for v := range c {
out <- v
}
wg.Done()
@campoy
campoy / main.go
Created February 21, 2018 19:14
Creating a submodule with go-git
package main
import (
"fmt"
"log"
"strings"
"time"
"gopkg.in/src-d/go-billy.v4/memfs"
git "gopkg.in/src-d/go-git.v4"
@campoy
campoy / mandelbrot.go
Created August 27, 2018 14:27
Creating mandelbrot, one pixel at a time
package main
import (
"flag"
"image"
"image/color"
"image/png"
"log"
"os"
)
@campoy
campoy / mandelbrot.go
Created August 27, 2018 14:27
Creating mandelbrot, one pixel at a time
package main
import (
"flag"
"image"
"image/color"
"image/png"
"log"
"os"
)
@campoy
campoy / app.go
Created November 18, 2016 23:43
Go Echo server on App Engine Flex
// 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"
@campoy
campoy / main.go
Created April 19, 2018 18:15
Don't use panics as exceptions.
package main
import (
"log"
"net/http"
)
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
function sum(row, emit) {
const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 });
const env = {
'abortStackOverflow': _ => { throw new Error('overflow'); },
'table': new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }),
'tableBase': 0,
'memory': memory,
'memoryBase': 1024,
'STACKTOP': 0,
'STACK_MAX': memory.buffer.byteLength,
const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 });
const env = {
'abortStackOverflow': _ => { throw new Error('overflow'); },
'table': new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }),
'tableBase': 0,
'memory': memory,
'memoryBase': 1024,
'STACKTOP': 0,
'STACK_MAX': memory.buffer.byteLength,
};