Skip to content

Instantly share code, notes, and snippets.

View bergpb's full-sized avatar
🏠
Working from home

Lindemberg Barbosa bergpb

🏠
Working from home
View GitHub Profile
@bergpb
bergpb / dolarhj-parse.go
Created June 1, 2020 03:18
Example to parse a string with Go
package main
import (
"fmt"
"strings"
)
var data string = `<p>O dólar hoje tá R$ 5,40<br/>O Bitcoin hoje tá R$ 51347,38</p><p></p><p>O dólar australiano hoje tá R$ 3,57<br/>O dólar canadense hoje tá R$ 3,92<br/>O dólar neozelandês hoje tá R$ 3,42<br/>O euro hoje tá R$ 5,98<br/>O franco suíço hoje tá R$ 5,60<br/>O real hoje tá 19,90 ienes<br/>A libra hoje tá R$ 6,66<br/>O novo sol hoje tá R$ 1,57<br/>O grama do ouro hoje tá R$ 295,83<br/>O peso argentino hoje tá R$ 0,07<br/>O real hoje tá 149,54 pesos chilenos<br/>O peso mexicano hoje tá R$ 0,17<br/>O peso uruguaio tá R$ 0,11<br/>O rublo russo hoje tá R$ 0,07<br/>O won sul-coreano hoje tá R$ 0,004366<br/>O yuan hoje tá R$ 0,75</p><p></p><p>O dólar turismo hoje tá R$ 5,59<br/>O euro turismo hoje tá R$ 6,22</p><p></p><p>O Aeternity hoje tá R$ 0,68<br/>A ARK hoje tá R$ 1,15<br/>O Basic Attention Token hoje tá R$ 1,12<br/>O Bitcoin Cash hoje tá R$ 1280,50<br/>O Bitcoin Diamond hoje tá R$ 3,05<br/>O Bitcoin Gold hoje tá R$ 49,13<br/>O Bitcoin SV hoje tá R$ 1020
@bergpb
bergpb / exception.py
Last active May 20, 2020 13:57
Catching exceptions in python
a = 1
b = 'a'
try:
a / b
except Exception as e:
print(f"Exception of type {type(e)} as ocurred: {e}")
@bergpb
bergpb / whatsappweb.user.js
Last active May 22, 2020 21:37
Tampermonkey script to turn on dark mode in whatsappweb based on current time
// ==UserScript==
// @name dark_mode_whatsappweb
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Activate dark mode in https://web.whatsapp.com/
// @author https://github.com/bergpb
// @match https://web.whatsapp.com
// @grant none
// ==/UserScript==
@bergpb
bergpb / vernan_cipher_complete.py
Last active April 28, 2020 02:45
Cifra de Vernan em Python, entrada de texto pelo usuário.
import random
text = input('Entre com o texto a ser cifrado (ou aperte enter para texto padrão):')
if text == '':
text = "O rato roeu a roupa do rei de roma"
def xor(x: str, y: str) -> str:
@bergpb
bergpb / vernan_cipher.py
Created April 24, 2020 22:29
Cifra de Vernan em Python
msg = "0 0 1 0 1 1 0 1 0 1 1 1"
pad = "1 0 0 1 1 1 0 0 1 0 1 1"
def str_to_list(itens: str) -> list:
"""Converte string para lista"""
return [int(i) for i in itens.split(" ")]
def list_to_str(itens: list) -> str:
@bergpb
bergpb / how-to-use-pelican.md
Created April 22, 2020 15:16 — forked from JosefJezek/how-to-use-pelican.md
How to use Pelican on GitHub Pages
@bergpb
bergpb / sum-months.py
Last active April 16, 2020 00:14
Sum months in python, justpython.
import sys
month = sys.argv[1]
add = sys.argv[1]
def add_month(month, add):
next = month + add
if next >= 13:
return 1 if next-12 == 0 else next-12
return next
@bergpb
bergpb / state.py
Last active April 11, 2020 22:19
Gerenciamento de Estados com Python
# https://www.youtube.com/watch?v=QXorM9jsBNo
import time
class Main:
def __init__(self) -> None:
self.state = False
class Tv:
@bergpb
bergpb / secrets.md
Last active November 1, 2020 20:48
Generate secret key in python 3.6

Generate secret key in python +3.6

python -c "import secrets; print(secrets.token_hex(32))"
@bergpb
bergpb / lines_in_file_into_list.py
Created March 28, 2020 04:31
Read a file line by line and put content into a list.
#file.txt
#1 2 3
#4 5 6
#7 8 9
with open('file.txt') as file:
content = file.readlines()
numbers = [line.strip().split(' ') for line in content]
print(numbers)