View NDjsonTojsonArr.go
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
// NDjsonTojsonArr converts newline-delimited json (indented or minified) | |
// to a json array. Caller should handle cleanup on error. | |
func NDjsonTojsonArr(r io.Reader, w io.WriteCloser) error { | |
w.Write([]byte("[")) | |
var m json.RawMessage | |
dec := json.NewDecoder(r) | |
err := dec.Decode(&m) | |
for { | |
if _, err = w.Write(m); err != nil { |
View gobmarshal.go
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 gobMarshal(v interface{}) ([]byte, error) { | |
var buf bytes.Buffer | |
enc := gob.NewEncoder(&buf) | |
err := enc.Encode(v) | |
return buf.Bytes(), err | |
} | |
func gobUnmarshal(data []byte, v interface{}) error { | |
dec := gob.NewDecoder(bytes.NewReader(data)) | |
return dec.Decode(v) |
View TokenActor_test.go
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 ( | |
"testing" | |
"time" | |
) | |
type TokenRequest struct { | |
Key string | |
Value string |
View rMBP_ed25519.pub
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-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMqrj2Ea7EsGHR5v6I9Trk7K2Y/52uvuMXGUvKBkIUF4 ash@MacBook-Pro |
View optional.go2
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 Optional(type T) struct { | |
p *T | |
} |
View reverse.go
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" | |
"reflect" | |
) | |
func reverse(slice interface{}) interface{} { | |
/* Completely inefficient but syntactically "convenient" */ | |
s := reflect.ValueOf(slice) |
View boyer-mode.go
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 strStr(haystack string, needle string) int { | |
foundpos := -1 | |
if len(needle) < 1 { | |
return 0 | |
} | |
if len(needle) > len(haystack) { | |
return foundpos | |
} | |
/* Find unique char nearest the end of 'needle' to skip with */ |
View sort-characters-by-frequency.go
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
import ( | |
"sort" | |
"strings" | |
) | |
func frequencySort(s string) string { | |
abcfreq := make([]struct { | |
chr rune | |
cnt int | |
}, 128) |
View atou.go
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" | |
"os" | |
"bufio" | |
"strings" | |
) | |
func atofw(in string) (out string) { |
View rot13.go
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 ( | |
"os" | |
"bufio" | |
"fmt" | |
) | |
// double curly brackets to provide arbitrary scoping for variable shadowing. | |
// this is rather disgusting, but cleaner than repeat casts or more vars. |