Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"sync"
)
func main() {
var wg sync.WaitGroup
cb := NewCB(5)
package main
import (
"fmt"
"math/rand"
"reflect"
"testing/quick"
)
type Point struct {
package main
import "fmt"
var bits [256]int
func init() {
for i := range bits {
bits[i] = bits[i>>1] + i&0x1
}
@caelifer
caelifer / merger.go
Last active November 20, 2015 18:03
// Implementation of merge task from http://raganwald.com/2015/11/03/a-coding-problem.html
package main
import (
"fmt"
"sort"
)
func main() {
package main
import (
"log"
"math/rand"
"sync"
"time"
)
func init() {
package main
import "fmt"
func nextPermutation(x byte) byte {
a := x & -x
b := x + a
c := b ^ x
a <<= 2
c /= a
@caelifer
caelifer / large_constants.go
Last active February 29, 2016 17:54
How to deal with large constants which overflow basic types
package main
import (
"fmt"
"math/big"
)
const (
KB = 1000
MB = 1000 * KB
package main
import "fmt"
type F1 func(int) int
type F2 func(int, int) int
func apply(f F2, n int) F1 {
return func(x int) int {
return f(n, x)
package main
import (
"log"
"math/rand"
"sync"
"time"
)
func init() {
// Comment on https://www.reddit.com/r/golang/comments/3zgaxf/happy_new_year_gofragmentsnet_2_new_examples
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
)