This file contains hidden or 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" | |
| var ( | |
| tA = [8]byte{1, 2, 4, 8, 16, 32, 64, 128} | |
| tB = [8]byte{254, 253, 251, 247, 239, 223, 191, 127} | |
| ) | |
| func main() { |
This file contains hidden or 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 mu sync.RWMutex | |
| func ScrapeFromURL(ptrn []byte, urls ...string) [][]byte { | |
| mu.Lock() | |
| defer mu.Unlock() | |
| var data [][]byte | |
| for _, url := range urls { | |
| res, err := http.Get(url) | |
| if err != nil { | |
| log.Fatal(err) |
This file contains hidden or 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 | |
| // http://playground.gregpechiro.com/py_-fzzLle | |
| import ( | |
| "container/heap" | |
| "fmt" | |
| "math/rand" | |
| "time" | |
| ) |
This file contains hidden or 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
| string/[]byte casting: | |
| The []byte(s) is not a cast but a conversion. Some conversions are the | |
| same as a cast, like uint(myIntvar), which just reinterprets the bits | |
| in place. Unfortunately that's not the case of string to byte slice | |
| conversion. Byte slices are mutable, strings (string values to be precise) | |
| are not. The outcome is a necessary copy (mem alloc + content transfer) | |
| of the string being made. So yes, it can be costly in some scenarios. *No | |
| encoding transformation is performed. The string (source) bytes are copied | |
| to the slice (destination) bytes as they are. |
This file contains hidden or 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
| // Returns a new slice containing all strings in the slice that satisfy the predicate f. | |
| func Filter(vs []string, f func(string) bool) []string { | |
| vsf := make([]string, 0) | |
| for _, v := range vs { | |
| if f(v) { | |
| vsf = append(vsf, v) | |
| } | |
| } | |
| return vsf | |
| } |
This file contains hidden or 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" | |
| "strings" | |
| ) | |
| type Doc struct { | |
| Off int | |
| Len int |
This file contains hidden or 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
| const SLAB int64 = (1 << 22) // 4MB | |
| type Doc struct { | |
| Off int | |
| Len int | |
| } | |
| type Engine struct { | |
| File *os.File | |
| Docs map[string]*Doc |
This file contains hidden or 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 ( | |
| "container/heap" | |
| "flag" | |
| "fmt" | |
| "math/rand" | |
| "time" | |
| ) |
This file contains hidden or 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 Protected(next http.HandlerFunc) http.HandlerFunc { | |
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){ | |
| c, err := r.Cookie("sid") | |
| if err != nil || c.Value == "" { | |
| http.Redirect(w, r, r.Referer(), 301) | |
| return | |
| } | |
| var ausr AuthUser | |
| err := db.Return("session", c.Value, &ausr) | |
| if err != nil { |
This file contains hidden or 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
| // Copyright 2014 The Go Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style | |
| // license that can be found in the LICENSE file. | |
| package runtime | |
| // This file contains the implementation of Go's map type. | |
| // | |
| // A map is just a hash table. The data is arranged | |
| // into an array of buckets. Each bucket contains up to |