Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sgobin
sgobin / extra-emails-string.py
Created April 24, 2020 11:57
Extrai emails de uma string
import re
texto = 'aqui vai a string com os meus@emails.com.br"
emails = re.findall(r'[\w\.-]+@[\w\.-]+', texto)
@sgobin
sgobin / python-virtualenv-virtualenvwrapper.sh
Last active July 31, 2019 13:16
Instalar virtualenv virtualenvwrapper python3 usando brew no mac
pip3 install virtualenvwrapper
# Checar onde entá instalado e qual esta sendo usado
which python3
which virtualenvwrapper.sh
#Virtual Env Python
export WORKON_HOME=$HOME/.virtualenvs # Diretorio dos envs
export PROJECT_HOME=$HOME/pyprojects # diretorio dos projetos
export PIP_VIRTUALENV_BASE=$WORKON_HOME
@sgobin
sgobin / find-numbers-who-sum.py
Created July 3, 2019 14:01
Acha quais os números em uma lista que geram a soma de um número.
def subset_sum(numbers, target, partial=[]):
s = sum(partial)
# check if the partial sum is equals to target
if s == target:
print "sum(%s)=%s" % (partial, target)
if s >= target:
return # if we reach the number why bother to continue
for i in range(len(numbers)):
@sgobin
sgobin / speedtest.py
Last active January 19, 2019 17:00
Usando uma raspberry e speedtest.net para medir a velocidade da internet e salvar em uma planilha do Google via IFTTT
import os
import re
import subprocess
import time
import requests
#Usa um Webhook do IFTTT
URL = 'https://maker.ifttt.com/trigger/{NOME DO TRIGGER}/with/key/{CHAVE}'
#speedtest-cli => pip install speedtest-cli
@sgobin
sgobin / file-to-list.py
Created July 31, 2018 14:06
From file to list python / De arquivo txt para uma lista em python
emails = []
arquivos = ['limpo-1.txt','limpo-2.txt','limpo-3.txt','limpo-4.txt','limpo-5.txt']
for arquivo in arquivos:
with open(arquivo,'r') as arqLista:
for linha in arqLista:
emails.append(linha)
@sgobin
sgobin / remove-linhas-vazias.py
Created July 31, 2018 13:22
Remove empty and only spaces lines from a file / Remove linhas vazias de um arquivo
## Limpa linhas em branco dos arquivos
with open('5.txt') as infile, open('limpo-5.txt', 'w') as outfile:
for line in infile:
if not line.strip(): continue # pula linha em branco
outfile.write(line) # escreve linha no novo arquivo
@sgobin
sgobin / check-used-images.py
Created February 15, 2018 19:16
Check for imagens not used or referenced in HTML or CSS files in a site project
# Recursively check for images in a directory and compare with referenced images in CSS and HTML files
# in tha folder, generating two CSV files:
# One with used images and one with not referenced ones
# (does not look into JS files)
import glob
import csv
# Create the list of file names
pasta = "src/" #root of the project source files
@sgobin
sgobin / calcula-grid.py
Created May 26, 2016 19:49
General baseline grid/row calculator. Uses leading, page size and desired rows to generate grid options based on paper size.
#pede numero de rows e leading desejado
rows = int(input("Quantas rows: "))
leading = float(input("Leading em pontos: "))
alturaPapel = float(input('Altura do papel em pol: '))
#Calcula tamanho do papel em pontos
def convAltura(h):
return h*72
#Calcula tamanho total do frame baseado em linhas de texto por row
@sgobin
sgobin / palindromos.py
Created December 22, 2015 19:40
Achar palíndromos em uma lista usando python. Substitua o arquivo em open() com o que você deseja.
#Abrir o arquivo
f = open('pt-BR-utf8', 'r')
#ler uma linha
for line in f:
palavra = line.replace("\n", "")
palavra = palavra.lower()
#inverter a palavra
palavra_reversa = palavra[::-1]
@sgobin
sgobin / extract_emails_from_text.py
Last active December 22, 2015 12:51 — forked from dideler/example.md
A python script for extracting email addresses from text files.You can pass it multiple files. It prints the email addresses to stdout, one address per line.For ease of use, remove the .py extension and place it in your $PATH (e.g. /usr/local/bin/) to run it like a built-in command.
#!/usr/bin/env python
#
# Extracts email addresses from one or more plain text files.
#
# Notes:
# - Does not save to file (pipe the output to a file if you want it saved).
# - Does not check for duplicates (which can easily be done in the terminal).
#
# (c) 2013 Dennis Ideler <ideler.dennis@gmail.com>