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" | |
"sort" | |
) | |
// Our custom struct to sort. | |
type Data struct { | |
Name string |
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 ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
) | |
func main() { |
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 RoundPrec(x float64, prec int) float64 { | |
if math.IsNaN(x) || math.IsInf(x, 0) { | |
return x | |
} | |
sign := 1.0 | |
if x < 0 { |
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" | |
"os/exec" | |
) | |
// Start a new terminal/bash session in specified path. | |
func session(path string) { | |
os.Chdir(path) |
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
#!/bin/bash | |
EMAIL="your@email.com" | |
LEGOROOT="/path/to/lego" | |
function renew { | |
domain="$1" | |
path="$2" | |
$LEGOROOT/lego --key-type rsa4096 --accept-tos --path "$LEGOROOT/.lego" --email "$EMAIL" \ |
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 leven | |
import "github.com/arbovm/levenshtein" | |
func calcScore(a, b string) float64 { | |
score := levenshtein.Distance(a, b) | |
lena := len(a) | |
lenb := len(b) | |
var bigger float64 |
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
const WRITE_TIME = 10 * time.Second | |
const PING_TIME = 60 * time.Second | |
const PONG_TIME = PING_TIME + WRITE_TIME | |
func pingPong(conn *websocket.Conn) { | |
ticker := time.NewTicker(PING_TIME) | |
defer func() { | |
ticker.Stop() | |
conn.Close() |
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
#!/bin/bash | |
# Generate a new private key of size 4096 (with no pass phrase) | |
openssl genrsa -out server-key.pem 4096 | |
# Generate a self-signed cert using the key (valid for 10 years) | |
openssl req -new -x509 -key server-key.pem -out server-cert.pem -days 3650 | |
# Inspect the new cert | |
openssl x509 -in server-cert.pem -noout -text |
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
// Source: https://github.com/mattn/go-sqlite3/pull/116 | |
if err.(sqlite3.Error).Code == sqlite3.ErrConstraint { | |
// clumsily compare err.Error() against strings to figure out what the heck happened... | |
} | |
// Additionally, the following is now possible: | |
if err.(sqlite3.Error).ExtendedCode == sqlite3.ErrConstraintUnique { | |
// oh! my unique constraint failed? |
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" | |
"io" | |
"os" | |
"golang.org/x/crypto/ssh/terminal" | |
) |
OlderNewer