Skip to content

Instantly share code, notes, and snippets.

iury IuryAlves

View GitHub Profile
View multiprocessing_download.py
# coding: utf-8
import requests
from multiprocessing import Process, Pipe
def downloader(url, chunk_size, conn):
downloaded_parts = 0
with open('download', 'wb') as fp:
View download_stream.py
# coding: utf-8
import requests
chunk_size = 1024 * 1024 # 1mb
download_url = 'http://speedtest.ftp.otenet.gr/files/test10Mb.db'
downloaded_parts = 0
with open('download', 'wb') as fp:
response = requests.get(download_url, stream=True)
View main.py
from pprint import pprint
from datetime import datetime
from project_files import *
from git_hub_scrapper import *
from file import *
DOMAIN = 'https://github.com'
def main():
print('[INICIO.{_date:%Y/%m/%d %H:%M:%S}]'.format(_date=datetime.now()))
View depth.py
def get_depth(self):
parent = self.parent
depth = 0
while parent is not None:
parent = parent.parent
depth += 1
return depth
# coloca isso na classe Link
View github_scrapper.py
# coding: utf-8
"""
pip install requests beautifulsoup4
"""
import requests
from bs4 import BeautifulSoup
@IuryAlves
IuryAlves / pre-commit
Created Aug 31, 2017
git pre-commit hook
View pre-commit
#!/usr/bin/env python
# Original at http://tech.yipit.com/2011/11/16/183772396/
# Insert this into .git/hooks/pre-commit
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
@IuryAlves
IuryAlves / django_test_manage.py
Created Jul 25, 2017
Run Django tests without migrations
View django_test_manage.py
#!/usr/bin/env python
import os
import sys
from django.core.management import ManagementUtility
from django_test_runner import is_nosetest
from pycharm_run_utils import import_system_module
from teamcity import teamcity_presence_env_var
@IuryAlves
IuryAlves / compress_s3_images.py
Created Feb 22, 2017 — forked from rigoneri/compress_s3_images.py
Simple python code to compress (jpeg/png) images uploaded to S3. In this use case I want to compress down all images that are over 500 KB down to 80% quality which brings the images down to about 100KB. Feel free to muck with the values.
View compress_s3_images.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from boto.s3.connection import S3Connection
from cStringIO import StringIO
from PIL import Image as pil
AWS_KEY = '[AWS KEY HERE]'
@IuryAlves
IuryAlves / mocking_condition.py
Last active Feb 10, 2017
Mock something only if condition applies.
View mocking_condition.py
# coding: utf-8
import functools
def _mock_condition(condition, *args, **kwargs):
return condition(*args, **kwargs)
def mock_condition(condition):
@IuryAlves
IuryAlves / name_mangling.py
Last active Dec 11, 2016
Simple example to explain name mangling in python.
View name_mangling.py
# coding: utf-8
class Image(object):
def __format(self):
return 'PNG'
image = Image()
You can’t perform that action at this time.