Go Challenge 2 is live!

The Go Challenge for April is now live! As an evaluator, I’ve already solved it. It was fun, and just the right size. Go try it, you’ll have fun!

March 31, 2015 · 1 min · jra

Building Go 1.4 when the linker doesn't know about build-id

Today at work, on a Redhat 5.5 machine, I tried to build Go 1.4. This happened: ` $ cd go1.4/src $ ./all.bash …snip… runtime/cgo /usr/bin/ld: unrecognized option ‘–build-id=none’ /usr/bin/ld: use the –help option for usage information collect2: ld returned 1 exit status ` The solution is to retry without the “–build-id=none” option: diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index ad03239..ca45217 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -2436,13 +2436,21 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi // --build-id=none. So that is what we do, but only on // systems likely to support it, which is to say, systems that // normally use gold or the GNU linker. + retryWithoutBuildId := false switch goos { case "android", "dragonfly", "linux", "netbsd": ldflags = append(ldflags, "-Wl,--build-id=none") + retryWithoutBuildId = true } if err := b.gccld(p, ofile, ldflags, gccObjs); err != nil { - return nil, nil, err + if retryWithoutBuildId { + ldflags = ldflags[0:len(ldflags)-1] + err = b.gccld(p, ofile, ldflags, gccObjs) + } + if err != nil { + return nil, nil, err + } } // NOTE(rsc): The importObj is a 5c/6c/8c object and on Windows Just in case someone else is looking for it… :) ...

March 19, 2015 · 2 min · jra

Go will make you a better programmer

The last line of Dave Cheny’s Gophercon 2015 India keynote is the best: “Go will make you a better programmer.” It’s true. When I am programming Go, I never think, “OK, is this an OK shortcut to take here? Is this a play context? Is this a work context, but I can push off bounds checking on some other layer? Is this just a little local server, and I don’t care about hackers?” ...

March 12, 2015 · 1 min · jra

A Quick Go hack: lines-per-second

Today I wanted to compare how fast two builds were on two different machines. As a rough estimate, I just wanted to see how many lines per second were going into the log file. This is what I came up with: package main import ( "bufio" "fmt" "os" "time" ) func main() { scn := bufio.NewScanner(os.Stdin) lines := 0 go func() { for { fmt.Fprintf(os.Stderr, "%v lps\n", lines) lines = 0 time.Sleep(time.Second) } }() for scn.Scan() { lines++ } } This is a quick hack. It’s not production quality, because there is a data race on lines. I think if I had to fix that race up, I’d choose to use sync/atomic’s ops. This because I’d only need to hit the two places lines is touched concurrently. A channel-based solution would be bigger and messier, not in tune with the minimal nature of this little program. ...

March 4, 2015 · 1 min · jra

The Podcast/Spam nexus

I listen to a lot of podcasts. They virtually are all sponsored by either MailChimp or Emma (some new Mailchimp clone). What I want to know is why spammers (even opt-in, targeted email marketing solutions are spammers as far as I can tell) find that podcasts are listened to by their target market (i.e. other spammers). Hmm. Maybe I should be spamming more…

March 3, 2015 · 1 min · jra

Golang on the Geode processor

If you are trying to use Golang on a PC-Engines Alix board, you need to be careful that all the Go code you are using is compiled while the GO386 environment variable is set to 387. The Geode processor does not support the SSE instructions. If you have Linux directly on the Alix, you’d not run into this because if GO386 is not set, then the compiler auto-detects the right thing. But if you are, for example, running OpenWRT on the device, and you are using cross-compilation to build on another device, you might run into this if some of your Go code (for example, the std lib) was compiled without GO386. ...

March 2, 2015 · 2 min · jra

Type safety saves the day again

Recently, I was writing some code to check the SHA256 of a buffer. Simple, right? All you have to do is take the hash you have, get the hash of the data, and compare them. But then you think, “oh, what a drag, I gotta compare two []byte values for equality, and == doesn’t work on them”. And then you think, “oh, I’ll use reflection!” And now you have two problems. ...

February 16, 2015 · 3 min · jra

AR.Drone 2 camera access

There is lots of information out on the net about how to access the camera in the AR.Drone, but it is all for the original model. In the AR.Drone 2, the cameras have been replaced and upgraded. So settings for v4l that worked to get data out of the camera need to be updated as well. The front camera is on /dev/video1. If you are talking to V4L directly via ioctls and all that jazz, you need to request format V4L2_PIX_FMT_UYVY, width 1280 and height 720. UYVY format uses 2 bytes per pixel, so a full image is 1843200 bytes. fwrite those bytes from the mmap buffer into a file. ...

October 14, 2014 · 2 min · jra

Dual scheme URLs

I just made this blog HTTP and HTTPS, thanks to Cloudflare. But that made me realize that lots and lots of internal links in the HTML output of my Wordpress point back to the HTTP version of the site. Part of the solution to this is to install the HTTP plugin in Wordpress which fixes some of the mess. But some of the URLs in my posts need to be fixed too. ...

October 6, 2014 · 2 min · jra

Cloudflare Universal SSL totally, completely rocks

Cloudflare was already my favorite non-Google internet company because I’m a Golang fan boi and Cloudflare is vocal about their love of Go. So when I heard that Cloudflare was willing to help me, for free, put SSL on my website(which I’ve been meaning to do since like forever), I was ready to go for it. First the rocks. Well, it’s free, for little dinky domains like mine. And that’s a hell of a great way to teach techies like me how their system works. I’d happily sell it to a client who asked me about it. The signup process is fast and easy and interesting. And it works: nella.org via SSL ...

October 6, 2014 · 2 min · jra