Skip to content

Instantly share code, notes, and snippets.

View raninho's full-sized avatar
🤖
Simulating what is human.

Raniere Medeiros raninho

🤖
Simulating what is human.
View GitHub Profile
@scotta
scotta / strikeamatch.py
Last active August 25, 2021 21:13
Python implementation of the "Strike a match" algorithm presented in the article http://www.catalysoft.com/articles/StrikeAMatch.html
"""Implementation of the "Strike a match" algorithm presented in the article
http://www.catalysoft.com/articles/StrikeAMatch.html by Simon White.
Excerpt from the above URL: The similarity between two strings s1 and s2 is
twice the number of character pairs that are common to both strings divided by
the sum of the number of character pairs in the two strings. Note that the
formula rates completely dissimilar strings with a similarity value of 0, since
the size of the letter-pair intersection in the numerator of the fraction will
be zero. On the other hand, if you compare a (non-empty) string to itself, then
the similarity is 1.
@thomas11
thomas11 / gist:2909362
Created June 11, 2012 09:52
Log memory usage every n seconds in Go #golang
import (
"runtime"
"time"
)
...
go func() {
for {
var m runtime.MemStats
@drewolson
drewolson / reflection.go
Last active August 25, 2024 18:35
Golang Reflection Example
package main
import (
"fmt"
"reflect"
)
type Foo struct {
FirstName string `tag_name:"tag 1"`
LastName string `tag_name:"tag 2"`
@tetsuok
tetsuok / printStruct.go
Created February 13, 2013 07:50
Printing structs; convert structs to JSON format easily.
// Printing structs.
// http://research.swtch.com/gotour
package main
import (
"encoding/json"
"fmt"
"log"
)
@temoto
temoto / aes-cfb-example.go
Created February 27, 2013 22:37
Example of AES (Rijndael) CFB encryption in Go. IMHO, http://golang.org/pkg/crypto/cipher/ could benefit a lot from similar snippet.
package main
import (
"crypto/aes"
"crypto/cipher"
"fmt"
)
func EncryptAESCFB(dst, src, key, iv []byte) error {
aesBlockEncrypter, err := aes.NewCipher([]byte(key))
@mattes
mattes / check.go
Last active October 11, 2024 16:22
Check if file or directory exists in Golang
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
// path/to/whatever does not exist
}
if _, err := os.Stat("/path/to/whatever"); !os.IsNotExist(err) {
// path/to/whatever exists
}
@chewxy
chewxy / getGolangEBNF.py
Created September 3, 2014 03:43
Gets the EBNF of the Golang spec at https://golang.org/ref/spec
from bs4 import BeautifulSoup
import requests
r = requests.get('http://golang.org/ref/spec')
soup = BeautifulSoup(r.text)
bnf = soup.find_all('pre', class_='ebnf')
bnftxt = [x.get_text() for x in bnf]
bnftxt = ''.join(bnftxt)
@honkskillet
honkskillet / byte-sizetuts.md
Last active August 22, 2024 14:19
A series of golang tutorials with youtube videos.
@jamesrr39
jamesrr39 / Golang program stdin stdout interaction.md
Last active July 12, 2023 18:21
Using stdout and stdin from other programs in Golang

Go program interaction

Example of how to use stdout and stdin from other programs in golang

Requires go

Run

go run parentprocess.go