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
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAQEegZ89+oYcWf8le3SxyvSdiQUhkp5SfhUdltf78lxWlUVnHrsfLfRfAX2CnRKndnXjKj0ScaAGq2+duqKVTyVQrqtYvb9xC7kQMwMq2Z0SjPATN1EaKm6FQnLAZsw4Q6uKEuXVCEQ0s7bbz3z8f6YXG3sAno8cciuLDTiMjtu/O/71yfrRmG29vs5kvl/k1lX9OfquWlHIOhjREO3y0BNN9K6WjnCgAdEsJZdJ+PPTFq/2ciWqrVxi29ooGZ4lhmUDAzJnSD4btHjuh33FnuDGi7IfHbX9jOUsxRyDG+huwh3hSP/gV4Va1jdBqijswha9uWAwioA0HyLMgrmqD rkovacs@Richard-Kovacs-MBP.local |
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 PostItHandler(w http.ResponseWriter, req *http.Request) { | |
w.Write([]byte("ok")) | |
} | |
func RegisterHandler() { | |
signature, _ := ioutil.ReadFile("/path/of/public/key") | |
r := mux.NewRouter() | |
r.Handle("/postit", Wrap(PostItHandler, signature)).Methods("POST") | |
http.Handle("/", r) |
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 | |
func main() { | |
c := make(chan bool) | |
go func() { c <- true }() | |
println(<-c) | |
} |
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
appendChan := make(chan int, CONSUMERS) // chanel, amin a generálás eredményei jönek | |
cons := func() { | |
for { | |
e := <-appendChan // kiolvassuk a következő generált értéket | |
for i := 0; i < 500; i++ { // még 500szor probálkozunk nagyobbat generálni | |
e = int(math.Min(float64(e), float64(rand.Int()))) | |
} | |
mtx.Lock() // irásra zárolunk majd hozzáfűzzük az eredméyekhez |
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
var itsLast, notLast int32 // statisztika eredménye | |
countChan := make(chan int, COUNTERS) // chanel, amin a számláló várja az értékeket | |
counter := func() { | |
for { | |
e := <-countChan // kiolvassuk a következő értéket | |
mtx.RLock() // olvasásra zárolunk és kiolvassuk az eredmenyből az utolsó elemet | |
last := results[len(results)-1] | |
mtx.RUnlock() |
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" | |
"math" | |
"math/rand" | |
"sync" | |
"sync/atomic" | |
"time" | |
) |
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
var start int64 // kezdés időbélyege | |
once := new(sync.Once) // ez garantálja, hogy csak egyszer adjunk értéket az időbélyegnek | |
poolChan := make(chan bool, PRODUCERS) | |
prod := func(wg *sync.WaitGroup) { | |
defer wg.Done() | |
once.Do(func() { start = time.Now().UnixNano() }) // ertéket adunk | |
e := rand.Int() // generálunk 1000 véletlenszámot | |
for i := 0; i < 999; 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
poolChan := make(chan bool, PRODUCERS) // egyidőben futó generátorok nyilvántartása | |
prod := func() { | |
// ... | |
<-poolChan // kiolvasunk egy értéket | |
} | |
for i := 0; i < MAX; i++ { // megfelelő számban elindítjuk a generálót | |
poolChan <- true // beteszünk egy értéket | |
go prod() // elinditjuk a goroutint |
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
prod := func(wg *sync.WaitGroup) { | |
defer wg.Done() // a futás végeztével nyugtázunk | |
// ... | |
} | |
wg := new(sync.WaitGroup) // új WaitGroup | |
wg.Add(MAX) // beállítjuk hány nyugtázást várunk | |
for i := 0; i < MAX; i++ { | |
// ... | |
go prod(wg) |
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
var done bool | |
for !done { // várunk amíg az összeset megszámolja a számláló | |
done = atomic.LoadInt32(&itsLast)+atomic.LoadInt32(¬Last) == MAX | |
} | |
fmt.Printf("time spent: %dms\n", (time.Now().UnixNano()-start)/1000000) | |
fmt.Printf("last:not ratio: %d:%d\n", itsLast, notLast) |
OlderNewer