Skip to content

Instantly share code, notes, and snippets.

View campoy's full-sized avatar

Francesc Campoy campoy

View GitHub Profile
@campoy
campoy / pi-fast.go
Last active March 13, 2017 18:10
Computing pi one gcd at a time! Inspired by https://www.youtube.com/watch?v=RZBhSi_PwHU&t=891s
package main
import (
"fmt"
"math"
"math/rand"
"runtime"
"sync"
"time"
)
@campoy
campoy / empty.sh
Created June 27, 2017 23:07
Find all the packages in the standard library that do not expose any symbol
for pkg in $(go list std | grep -v vendor)
do
go build $pkg && if [[ "$(go doc $pkg | grep '^func\|^var\|^type\|^const' | wc -l)" -eq "0" ]]
then
echo $pkg
fi
done
@campoy
campoy / benchmarks_test.go
Created July 10, 2017 22:33
go test -gcflags "-S" generates double definition
package profiling
import "testing"
func div(a, b int) int {
return int(float64(a) / float64(b))
}
var s int
@campoy
campoy / settings.json
Created July 24, 2017 21:11
My vscode settings
{
"window.zoomLevel": 0,
"go.lintOnSave": "package",
"editor.fontFamily": "'Fira Code', Menlo, Monaco, 'Courier New', monospace",
"editor.fontLigatures": false,
"workbench.iconTheme": "vs-seti",
"go.addTags": {
"tags": "json",
"options": "json=omitempty",
"promptForTags": true,
package main
import "fmt"
func main() {
fmt.Println("Hello, world")
}
package main
import (
"fmt"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "usage:\n\t%s [files]\n", os.Args[0])
fs := token.NewFileSet()
for _, arg := range os.Args[1:] {
b, err := ioutil.ReadFile(arg)
if err != nil {
log.Fatal(err)
}
f := fs.AddFile(arg, fs.Base(), len(b))
var s scanner.Scanner
package main
import (
"fmt"
"go/parser"
"go/token"
"log"
)
func main() {
package main
import (
"fmt"
"go/parser"
"go/token"
"log"
)
func main() {
package main
import (
"go/parser"
"go/token"
"log"
"github.com/davecgh/go-spew/spew"
)