Skip to content

Instantly share code, notes, and snippets.

View campoy's full-sized avatar

Francesc Campoy campoy

View GitHub Profile
@campoy
campoy / main.go
Created February 12, 2018 17:32
gist 2 for episode 28 of justforfunc
func BenchmarkFoo(b *testing.B) {
for i := 0; i < b.N; i++ {
// perform the operation we're analyzing
}
}
@campoy
campoy / paper.txt
Last active February 5, 2018 23:18
Article
\documentclass[conference,10pt]{IEEEtran}
\usepackage[utf8]{inputenc}
\ifCLASSINFOpdf
\usepackage[pdftex]{graphicx}
\else
\usepackage[dvips]{graphicx}
\fi
\usepackage{algpseudocode}
\usepackage{amsmath}
\usepackage{color}
i, v, ok := reflect.Select(cases)
if !ok {
cases = append(cases[:i], cases[i+1:]...)
continue
}
out <- v.Interface().(int)
var cases []reflect.SelectCase
for _, c := range chans {
cases = append(cases, reflect.SelectCase{
Dir: reflect.SelectRecv,
Chan: reflect.ValueOf(c),
})
}
i, v, ok := reflect.Select(cases)
if !ok {
cases = append(cases[:i], cases[i+1:]...)
continue
}
out <- v.Interface().(int)
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()
func merge(cs ...<-chan int) <-chan int {
out := make(chan int)
for _, c := range cs {
go func(c <-chan int) {
for v := range c {
out <- v
}
}(c)
}
func main() {
a := asChan(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
b := asChan(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)
c := asChan(20, 21, 22, 23, 24, 25, 26, 27, 28, 29)
for v := range merge(a, b, c) {
fmt.Println(v)
}
}
func merge(cs ...<-chan int) <-chan int {
out := make(chan int)
for _, c := range cs {
go func() {
for v := range c {
out <- v
}
}()
}
@campoy
campoy / Dockerfile
Created January 27, 2018 18:55
Building kythe in a Docker image
FROM debian:jessie-backports
RUN apt-get update && apt-get install -y \
asciidoc asciidoctor source-highlight graphviz \
gcc libssl-dev uuid-dev libncurses-dev libcurl4-openssl-dev flex clang-3.5 bison \
parallel
RUN apt-get install -y -t jessie-backports openjdk-8-jdk
# install golang
RUN apt-get install -y curl