Skip to content

Instantly share code, notes, and snippets.

View skelterjohn's full-sized avatar

John Asmuth skelterjohn

  • Google
  • New York, New York
View GitHub Profile
package main
import "fmt"
type MySlice []int
func main() {
s := MySlice{1,2,3,4}
for i, v := range s {
fmt.Println(i, v)
loop:
for {
select {
case <-me.stopChan:
break loop
default:
compute()
}
}
{{range .Stuff}}
{{if .(ElementA)}}string:{{.X}} int:{{.Y}}{{end}}
{{if .(ElementB)}}int:{{.X}} string:{{.Y}}{{end}}
{{end}}
func Redirect(wr io.Writer, data interface{}) {
switch data.(type) {
case ElementA:
templateA.Execute(wr, data)
case ElementB:
templateB.Execute(wr, data)
}
}
/*cgopkg.go*/
package cgopkg
//#include <stdlib.h>
//#include "cgopkg.h"
import "C"
import (
"unsafe"
)
func Foo() {
chi := C.CString("hi")
type SorterDefault []MyType
func (s SorterDefault) Len() int { return len(s)}
func (s SorterDefault) Swap(i, j int) { s[i], s[j] = s[j], s[i]}
type Sorter1 struct { SorterDefault }
func (s Sorter1) Less(i, j int) bool { ... }
type Sorter2 struct { SorterDefault }
func write(localFile, remoteFile string) (err error) {
buf := bytes.NewBuffer([]byte{})
mw := multipart.NewWriter(buf)
if err = mw.WriteField("field", value); err != nil {
return
}
@skelterjohn
skelterjohn / gist:3743756
Created September 18, 2012 15:27
Code and example for LimitBuffer
// code for http://gowithconfidence.tumblr.com/post/31797884887/limit-buffers
package main
import (
"bytes"
"errors"
"fmt"
"io"
"sync"
### Keybase proof
I hereby claim:
* I am skelterjohn on github.
* I am skelterjohn (https://keybase.io/skelterjohn) on keybase.
* I have a public key whose fingerprint is C9C7 4C86 285C CDA8 EEE3 D652 32EF D206 7A14 956A
To claim this, I am signing this object:
@skelterjohn
skelterjohn / gist:672fdcfed49aadd14834baff99de6424
Created January 27, 2017 15:09
cooperative scheduling with cpu intensive tasks, GOMAXPROCS=1
package main
import (
"encoding/json"
"fmt"
"runtime"
"strings"
"sync"
)