Skip to content

Instantly share code, notes, and snippets.

@mcellis33
mcellis33 / chancache.go
Created September 8, 2015 22:35
Channel Cache
package main
import (
"fmt"
"os"
"time"
)
func main() {
input := make(chan int)
@mcellis33
mcellis33 / callinfo.go
Created July 1, 2015 22:13
Func Call Information
import (
"path"
"runtime"
"strings"
)
type callInfo struct {
PackageName string
FileName string
FuncName string
@mcellis33
mcellis33 / numconv.go
Created May 8, 2015 17:25
Number Conversions
package numconv
import "math"
const (
// The maximum float64 value that is less than math.MaxInt64. This was
// computed with math.Nextafter(float64(math.MaxInt64), 0)).
Float64MaxInt64 float64 = 9.223372036854775e+18
// The minimum float64 value that is greater than math.MinInt64. This was
@mcellis33
mcellis33 / int64tofloat64.go
Last active August 29, 2015 14:20
interesting float64 -> int64 conversion behavior
package main
import (
"fmt"
"math"
)
func main() {
for i := 0; i < 67; i++ {
fmt.Println(i)
@mcellis33
mcellis33 / ismountpoint.go
Created April 3, 2015 16:49
Mount Point Test
// IsMountPoint returns whether or not the file at the given path is currently
// being used as a mount point. If the dev number of the file is not equal to
// that of its parent, then the file is a mount point.
func IsMountPoint(path string) (bool, error) {
fileInfo, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
@mcellis33
mcellis33 / keybase.md
Created March 20, 2015 06:04
keybase.md

Keybase proof

I hereby claim:

  • I am mcellis33 on github.
  • I am mellis (https://keybase.io/mellis) on keybase.
  • I have a public key whose fingerprint is C355 68F9 FA81 141A 1443 2DA6 7CEB 02D7 F513 F891

To claim this, I am signing this object:

@mcellis33
mcellis33 / timeequal.go
Created February 27, 2015 02:19
Time Equality
package main
import (
"fmt"
"time"
)
func main() {
try0()
try1()
@mcellis33
mcellis33 / stack.go
Created January 28, 2015 22:57
Go Stack Dump
func stack(all bool) string {
stackbuf := make([]byte, 8192)
for {
length := runtime.Stack(stackbuf, all)
if length < len(stackbuf) {
return string(stackbuf[:length])
}
stackbuf = make([]byte, 2*len(stackbuf))
}
}
@mcellis33
mcellis33 / docker-registry.service
Last active August 29, 2015 14:10
docker registry unit file
[Unit]
Description=Docker Registry
Documentation=https://github.com/docker/docker-registry/tree/0.8
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/bin/docker run \
-e MIRROR_SOURCE=https://registry-1.docker.io \
-e MIRROR_SOURCE_INDEX=https://index.docker.io \
@mcellis33
mcellis33 / crand.go
Created November 21, 2014 00:25
Cryptographically Random math/rand
import (
cryptorand "crypto/rand"
"math/big"
mathrand "math/rand"
)
// This exposes the convenience methods of the math/rand package,
// but with the cryptographic randomness of the crypto/rand package.
var crand = NewCryptoRand()