Skip to content

Instantly share code, notes, and snippets.

Avatar

Moacir Moda moacirmoda

View GitHub Profile
View read.py
# abrindo o arquivo para leitura
with open('test.txt') as handle:
# criando uma variável para armazenar a quantidade de linhas
lines = 0
# iterando, linha por linha, no aquivo de leitura
for line in handle:
# incrementando a variável de linhas
View gist:7359777
file = "file.txt"
# ler linha a linha
for line in handle(file):
print line
# lendo o arquivo todo
with open(file) as handle:
data = handle.read()
@moacirmoda
moacirmoda / instructions.md
Created May 3, 2016
Alteração de MySQL para Proethos2
View instructions.md

Abaixo de:

# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!

Inserir as seguintes linhas:

innodb_file_format = Barracuda
innodb_file_per_table = 1
View crawler.py
from bs4 import BeautifulSoup as bs
from datetime import datetime
import requests
import httplib
import socket
import ssl
init = datetime.now()
def connect_patched(self):
View example-that-make-login-with-pygram.py
# https://github.com/moacirmoda/pygram/blob/master/pygram/api.py
from pygram.api import PyGram
users = (
('user1', 'pass1'),
('user2', 'pass2'),
)
apis = []
for username, password in users:
@moacirmoda
moacirmoda / query.sql
Created Apr 5, 2017
Query para extrair informações de partidas do European Soccer Database
View query.sql
select
c.name as country,
l.name as league,
t.team_long_name as home_team,
t2.team_long_name as away_team,
m.*
from "Match" m
inner join Country c ON c.id = m.country_id
inner JOIN League l ON l.id = m.league_id
View print_numbers_async.py
import asyncio
from datetime import datetime
async def get_number(number):
await asyncio.sleep(1)
print("%s - %s" % (datetime.now(), number))
loop = asyncio.get_event_loop()
tasks = []
View print_number_with_requests_async.py
import asyncio
import requests
from datetime import datetime
async def get_number(number):
await asyncio.sleep(1)
print("%s - %s" % (datetime.now(), number))
response = requests.get("https://httpbin.org/get?number=%s" % number)
View print_number_with_requests_parallel.py
import asyncio
import requests
from datetime import datetime
def get_number(number):
print("%s - %s" % (datetime.now(), number))
response = requests.get("https://httpbin.org/get?number=%s" % number)
@moacirmoda
moacirmoda / query.py
Last active Jul 12, 2017
Poder do Peewee
View query.py
emails = FactEmailMovement.select(FactEmailMovement, FactEmail, DimEmailAddress) \
.join(FactEmail) \
.join(FactDebtor) \
.join(DimDocument) \
.switch(FactEmail) \
.join(DimEmailAddress) \
.where(DimDocument.document == '12532825600')
"""
SELECT
You can’t perform that action at this time.