Skip to content

Instantly share code, notes, and snippets.

@lmas
lmas / rerun.sh
Last active March 25, 2021 21:10
rerun - Simple script to rerun a command when files in the current directory has been modified
#!/bin/bash
COMMAND=$@
DIR=$PWD
function block_for_change {
inotifywait -q -q -r -e modify $DIR
}
function kill_command {
@lmas
lmas / random.go
Last active July 8, 2016 21:14
Go Random - Utility functions for math/rand
// Return a random int between min and max.
func RandRange(min, max int) int {
return rand.Intn(max-min+1) + min
}
// Return a random float between 0.0 and max.
func RandRangeFloat(max float64) float64{
return rand.Float64() * max
}
@lmas
lmas / sort_struct.go
Last active January 13, 2016 17:17
Sort a Go struct based on a string value.
package main
import (
"fmt"
"sort"
)
// Our custom struct to sort.
type Data struct {
Name string
@lmas
lmas / stdin.go
Created January 18, 2016 21:43
stding.go - Read a Go string from STDIN
package main
import (
"bufio"
"fmt"
"io"
"os"
)
func main() {
@lmas
lmas / windows1252-decoder.go
Created February 20, 2016 19:04
Decode Windows-1252 encoded strings.
package main
import (
"fmt"
"io/ioutil"
"strings"
"golang.org/x/text/encoding/charmap"
)
@lmas
lmas / round.go
Created February 23, 2016 20:34
round.go - Round a float64 in Go
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 {
@lmas
lmas / cli_session.go
Created March 5, 2016 22:42
Start multiple terminal/bash session in the same path.
package main
import (
"os"
"os/exec"
)
// Start a new terminal/bash session in specified path.
func session(path string) {
os.Chdir(path)
#!/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" \
ssl_certificate /etc/nginx/ssl/DOMAIN.crt;
ssl_certificate_key /etc/nginx/ssl/DOMAIN.key;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
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