Skip to content

Instantly share code, notes, and snippets.

View campoy's full-sized avatar

Francesc Campoy campoy

View GitHub Profile
func merge(a, b <-chan int) <-chan int {
c := make(chan int)
go func() {
adone, bdone := false, false
for !adone || !bdone {
select {
case v, ok := <-a:
if !ok {
adone = true
continue
func main() {
a := asChan(1, 3, 5, 7)
b := asChan(2, 4, 6, 8)
c := merge(a, b)
for v := range c {
fmt.Println(v)
}
}
func merge(a, b <-chan int) <-chan int {
c := make(chan int)
go func() {
for {
select {
case v := <-a:
c <- v
case v := <-b:
c <- v
}
func asChan(vs ...int) <-chan int {
c := make(chan int)
go func() {
for _, v := range vs {
c <- v
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
}
close(c)
}()
return c
@campoy
campoy / sum.c
Created January 12, 2018 21:54
C function called from BigQuery
int sum(int a, int b)
{
return a + b;
}
@campoy
campoy / double.js
Created January 12, 2018 21:35
Trying WASM on BigQuery
function double(x) {
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,
@campoy
campoy / cert.txt
Last active January 10, 2018 18:14
Cert for Google Groups from Cafe la Vie
CONNECTED(00000003)
---
Certificate chain
0 s:/C=US/ST=California/L=San Francisco/O=OpenDNS, Inc./CN=*.opendns.com
i:/CN=Cisco Umbrella Secondary SubCA lax-SG/O=Cisco
-----BEGIN CERTIFICATE-----
MIIDRDCCAiygAwIBAgIEWlYV1DANBgkqhkiG9w0BAQsFADBAMS4wLAYDVQQDDCVD
aXNjbyBVbWJyZWxsYSBTZWNvbmRhcnkgU3ViQ0EgbGF4LVNHMQ4wDAYDVQQKDAVD
aXNjbzAeFw0xODAxMDgxMzMxMTNaFw0xODAxMTMxMzMxMTNaMGoxCzAJBgNVBAYT
AlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNpc2Nv
@campoy
campoy / hiring.md
Created December 20, 2017 18:45
Hiring message

Hi,

First of all thanks for showing interested on my tweet, it's really cool to see so many people interested on working with me at @srcd_!

Please go check https://sourced.tech/careers/ and make sure one of those profiles match your experience and interests. If that's the case then send an email to talent@sourced.tech and feel free to mention my name.

Take into account that we're currently hiring for either Madrid or remotely

case *ast.GenDecl:
if d.Tok != token.VAR {
return v
}
for _, spec := range d.Specs {
if value, ok := spec.(*ast.ValueSpec); ok {
for _, name := range value.Names {
if name.Name == "_" {
continue
}
locals, globals := make(map[string]int), make(map[string]int)
for _, arg := range os.Args[1:] {
f, err := parser.ParseFile(fs, arg, nil, parser.AllErrors)
if err != nil {
log.Printf("could not parse %s: %v", arg, err)
continue
}
v := newVisitor(f)
ast.Walk(v, f)