Skip to content

Instantly share code, notes, and snippets.

View clock2.go
// Execution example: TZ=US/Eastern ./clock2 --port 8000
package main
import (
"flag"
"io"
"log"
"net"
"os"
@gerep
gerep / spinner.go
Created Nov 18, 2017
Loading animation for terminal
View spinner.go
func spinner(delay time.Duration) {
for {
for _, r := range `-\|/` {
fmt.Printf("\r%c", r)
time.Sleep(delay)
}
}
}
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@gerep
gerep / append-zeroes.txt
Created Nov 14, 2017
Append zeroes to CPF numbers with < 11 characters on LibreOffice
View append-zeroes.txt
=IF(LEN(A1) < 11,CONCAT(REPT(0,11 - LEN(A1)), A1),A1)
=IF(LEN(A1) < 11,
CONCAT(
REPT(0,11 - LEN(A1)
),
A1),
A1)
@gerep
gerep / oci8.pc
Created Nov 9, 2017
/usr/lib/pkgconfig/oci8.pc
View oci8.pc
prefix=/opt/oracle/instantclient
libdir=${prefix}
includedir=${prefix}/sdk/include/
Name: OCI
Description: Oracle database engine
Version: 11.2
Libs: -L${libdir} -lclntsh
Libs.private:
Cflags: -I${includedir}
View placeholder.go
package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
x := generateMessage("Hello {0}, you have {1} new messages!", "Gerep", "12")
View coh-piah.py
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:"))
View nim.py
def main():
print("Bem-vindo ao jogo do NIM! Escolha:")
print("1 - para jogar uma partida isolada")
print("2 - para jogar um campeonato")
o = input()
if o == "1":
print("Você escolheu partida isolada!")
partida()
elif o == "2":
View maior_primo.py
def maior_primo(n):
cont = 1
maior = 0
while cont <= n:
if primo(cont):
if cont > maior:
maior = cont
cont += 1
return maior
@gerep
gerep / pg-dates.sql
Created Aug 22, 2017
PostgreSQL: yesterday, today, tomorrow
View pg-dates.sql
select TIMESTAMP 'yesterday';
select DATE 'yesterday';
select TIMESTAMP 'today';
select DATE 'today';
select TIMESTAMP 'tomorrow';
select DATE 'tomorrow';
select TIME 'allballs';
select now();
select TIMESTAMP 'now';
select DATE 'now';