Skip to content

Instantly share code, notes, and snippets.

Avatar
:bowtie:
workin' on some stuff

Francesc Campoy campoy

:bowtie:
workin' on some stuff
View GitHub Profile
@campoy
campoy / qr.go
Created Oct 5, 2017
A simple program to print QR Codes on your terminal
View qr.go
// Copyright 2017 Google Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to writing, software distributed
// under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied.
//
@campoy
campoy / Dockerfile
Created Apr 6, 2018
Kythe in a Docker image
View Dockerfile
FROM debian:jessie-backports as build
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
@campoy
campoy / main.go
Created Feb 12, 2018
gist 1 for episode 28 of justforfunc
View main.go
func mergeRec(chans ...<-chan int) <-chan int {
switch len(chans) {
case 0:
c := make(chan int)
close(c)
return c
case 1:
return chans[0]
default:
m := len(chans) / 2
@campoy
campoy / sum.c
Created Jan 12, 2018
C function called from BigQuery
View sum.c
int sum(int a, int b)
{
return a + b;
}
@campoy
campoy / main.go
Last active Nov 9, 2019
Dgraph: K-Shortest Path with all predicates
View main.go
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"strings"
@campoy
campoy / letitfail.go
Last active Sep 19, 2019
This example shows how to have a set of goroutines running concurrently and processing requests. Panics from goroutines are recovered and the worker is restarted. You can download it and run it directly using `go run letitfail.go`
View letitfail.go
package main
import (
"bufio"
"fmt"
"os"
"time"
)
const numWorkers = 3
@campoy
campoy / main.go
Last active Aug 1, 2019
Estimating size for protobuf in memory
View main.go
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"unsafe"
"github.com/creachadair/misctools/sizeof"
View query.js
{
spielberg as var(func: allofterms(name@en, "steven spielberg")) {
uid
}
cameos(func: uid(spielberg)) @cascade @normalize {
director : name@en
director.film {
film : name@en
starring {
performance.actor @filter(uid(spielberg)) {
@campoy
campoy / batchdb.go
Created Jun 21, 2019
Showing how to batch your writes automatically with WriteBatch
View batchdb.go
package main
import (
"log"
"math/rand"
"sync"
"time"
"github.com/dgraph-io/badger/v2"
)
@campoy
campoy / home.tmpl
Last active Apr 18, 2019
Electron-like html+golang app
View home.tmpl
<html>
<head>
<title>Hello, from Go</title>
</head>
<body>
<h1>Hello</h1>
<p>
This is Go code running, {{.}}
</p>
</body>