This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type myInt int | |
func (i myInt) square() myInt { | |
return i*i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func CriticalDataManager(cmdchan chan CriticalCommand) { | |
queued := new(vector.Vector) | |
critical := 0 | |
for { | |
var rawcmd CriticalCommand | |
if critical == 0 && queued.Len() > 0 { | |
// Process the queued-up commands when we aren't in critical section | |
rawcmd := queued.At(0) | |
queued.Delete(0) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==> ./sub/ctpkg.c <== | |
#include <stdio.h> | |
void PrintIt() { | |
printf("PASS\n"); | |
} | |
==> ./sub/cgotpkg.go <== | |
package tpkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"testing" | |
) | |
func readonly() {} | |
var readwrite = func() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"sync" | |
) | |
// A Token represents resources allocated. It must be given | |
// back to the Manager to free the resource. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wg := new(sync.WaitGroup) | |
for i := 0; i < workers; i++ { | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
for { | |
select { | |
case input, open := <-In: | |
if !open { return } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Header struct { | |
raw [6*2]byte | |
Opcode, Rcode, Z byte | |
ID, QD, NS, AN, AR []byte // 2 bytes each | |
QR, AA, TC, RD, RA bool | |
} | |
func decodeHeader(r io.Reader) *Header, os.Error { | |
h := &Header{} | |
n, err := r.Read(h.raw[:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Hash - Guillermo Estrada | |
(modified to demonstrate Go idioms by Kyle Lemons) | |
Simple utility to obtain the MD5 and/or SHA-1 | |
of a file from the command line. | |
2011 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type neuron struct { | |
coef float64 | |
input chan *stimulus | |
output []chan *stimulus | |
} | |
func newNeuron(coef float64) *neuron { | |
n := &neuron{ | |
coef: coef, | |
input: make(chan *stimulus), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type HandlerData struct { | |
data string | |
//whatever | |
} | |
func main(){ | |
//Create a data struct | |
// add data to struct | |
h := &HandlerData{...} |
OlderNewer