Skip to content

Instantly share code, notes, and snippets.

@gerep
gerep / coh-piah.py
Last active January 21, 2022 20:21
import re
def le_assinatura():
'''A funcao le os valores dos tracos linguisticos do modelo e devolve uma assinatura a ser comparada com os textos fornecidos'''
print("Bem-vindo ao detector automático de COH-PIAH.")
wal = float(input("Entre o tamanho medio de palavra:"))
ttr = float(input("Entre a relação Type-Token:"))
hlr = float(input("Entre a Razão Hapax Legomana:"))
sal = float(input("Entre o tamanho médio de sentença:"))
@gerep
gerep / binary_search.py
Last active January 21, 2022 14:42
Binary search
def binary_search(target, arr):
low = 0
high = len(arr) - 1 # it starts with index 0
while low <= high:
mid = (low + high) // 2 # it represents the index of the middle element
if arr[mid] < target:
low = mid + 1
else:
@gerep
gerep / bubble_sort.py
Created January 21, 2022 14:42
Bubble sort
def bubble_sort(nums):
n = len(nums)
swap = True # required to start the while loop
while swap:
swap = False # always defaults to False
for i in range(1, n):
if nums[i-1] > nums[i]:
nums[i-1], nums[i] = nums[i], nums[i-1]
swap = True
@gerep
gerep / compact.go
Last active June 29, 2021 18:32
Compacting json data removing unused spaces: https://golang.org/pkg/encoding/json/#Compact
package main
import (
"bytes"
"encoding/json"
"fmt"
)
func main() {
data := `{ "spacedValue": "spaced value" }`
package main
import (
"context"
"fmt"
"net/http"
"time"
)
func main() {
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
)
@gerep
gerep / sed.sh
Created May 9, 2018 20:13
Using `sed` to replace string inside a file
sed -i '/old text/ s//new text/g' gigantic_file.txt
package main
import (
"fmt"
"math/rand"
"reflect"
"time"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@gerep
gerep / load.go
Last active April 20, 2018 20:08
for x := 0; x < 1000; x++ {
wg.Add(1)
go func() {
x := client.EvalSha(redisSha, []string{}, j)
if x.Err() == redis.Nil {
fmt.Println("No return")
} else if err != nil {
panic(err)
} else {
r, _ := x.Result()
package main
import (
"context"
"log"
"sync"
"time"
)
var wg sync.WaitGroup