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 / .gitignore
Last active September 21, 2017 17:32
Principais arquivos a serem ignorados pelo git
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@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 / sprite-retina.scss
Created December 20, 2013 18:00
Usando sprite para dispositivos retina.
// Sprite normal tem 100px x 200px -
// O Sprite retina é exatamente o dobro do normal: 200px x 400px
.sprite {
background-image: url(sprite.png);
background-repeat: no-repeat;
text-indent: -9999em;
display: block;
float: left;
}