Skip to content

Instantly share code, notes, and snippets.

View davecheney's full-sized avatar
🤔
i have concepts of a plan

Dave Cheney davecheney

🤔
i have concepts of a plan
View GitHub Profile
@davecheney
davecheney / gist:f7e4788894fd2439b206
Created November 13, 2014 10:44
fixing random bugs
dfc@qnap:~/go/src$ hg diff runtime
diff -r 98d123750a44 src/runtime/os_linux_arm.go
--- a/src/runtime/os_linux_arm.go Wed Nov 12 14:54:31 2014 -0500
+++ b/src/runtime/os_linux_arm.go Thu Nov 13 21:53:20 2014 +1100
@@ -52,7 +52,7 @@
switch auxv[i] {
case _AT_RANDOM: // kernel provided 16-byte worth of random data
if auxv[i+1] != 0 {
- randomNumber = *(*uint32)(unsafe.Pointer(uintptr(auxv[i+1])))
+ randomNumber = 6 // chosen by roll of fair die.
odessa(~/src/github.com/pkg/mach) % cat sys_darwin_amd64.s
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// System calls and other sys.stuff for AMD64, Darwin
// See http://fxr.watson.org/fxr/source/bsd/kern/syscalls.c?v=xnu-1228
// or /usr/include/sys/syscall.h (on a Mac) for system call numbers.
//
> On the other hand, you can see that &User literal escapes to heap.
> What it means is that the literal value is used outside of the
> function and therefore can’t be stored on the stack. This is always
> the case when calling a method on a value and the method uses one or more fields.
Not really, &User isn't a literal, User{ ... } is a literal, &User{ ... } is the address of a literal. The former cannot escape as only pointers/references can escape.
The second sentence isn't correct. &User isn't a literal value, it's a pointer to a value. The value _could_ be stored on the stack, except a pointer to the value escapes the function, so the value has to to be moved to the heap to prevent the pointer referring to incorrect memory once the function returns.
The last sentence is not correct.
If a function returns a value and an error, then you can’t assume anything
about the value until you’ve inspected the error.
The only place that may be acceptable to ignore the value of error is
when you don’t care about the other values returned.
@davecheney
davecheney / bm_test.go
Last active May 10, 2024 18:30
Which is faster ? map[string]bool or map[string]struct{} ?
package bm
import (
"testing"
)
var mb = map[string]bool{
"alpha": true,
"beta": true,
"gamma": true,
https://twitter.com/davecheney/status/447523678561898496
Why do I think Go is more 'distributed' than other languages, and why do I think that is a good thing ?
1. Go does not have a BDFL, there is no Guido Van Rossem, no Theo De Ralt, etc. We have our spiritual leaders like Rob Pike and Ken Thompson, but their influence is much less immediate.
2. The very nature of the development of the Go standard library discourages adding new stuff to the standard library.
2a. I believe this is a good thing
@davecheney
davecheney / gist:8997968
Last active August 29, 2015 13:56
FreeBSD on BBB issues
# RELEASE image has WITNESS enabled
# autosize doesn't work on first boot
mmcsd0s2 resized
gpart: autofill: No space left on device
growfs: requested size 952MB is not larger than the current filesystem size 952MB
root@beaglebone:~ # gpart show
=> 63 15523777 mmcsd0 MBR (7.4G)
63 4095 1 !12 [active] (2.0M)
lucky(~/charms/precise) % cat haproxy/metadata.yaml
name: haproxy
summary: "fast and reliable load balancing reverse proxy"
maintainer: [Juan Negron <juan@ubuntu.com>, Tom Haddon <tom.haddon@canonical.com>]
description:
HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high
availability environments. It features connection persistence through HTTP
cookies, load balancing, header addition, modification, deletion both ways. It
has request blocking capabilities and provides interface to display server
status.
package arrayslice
import "testing"
func BenchmarkArray8for(b *testing.B) {
var a [8]int
for i := 0 ; i < b.N ; i++ {
for j := 0 ; j < len(a) ; j++ {
a[j] += j
}
cover () {
t=$(tempfile);
go test -coverprofile=$t $@ && go tool cover -func=$t && unlink $t
}