Skip to content

Instantly share code, notes, and snippets.

View IuryAlves's full-sized avatar

Iury Alves de Souza IuryAlves

View GitHub Profile
@IuryAlves
IuryAlves / pre-commit
Created August 31, 2017 14:41
git pre-commit hook
#!/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 July 25, 2017 17:57
Run Django tests without migrations
#!/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 February 22, 2017 20:11 — 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.
#!/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 February 10, 2017 20:20
Mock something only if condition applies.
# 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 December 11, 2016 23:41
Simple example to explain name mangling in python.
# coding: utf-8
class Image(object):
def __format(self):
return 'PNG'
image = Image()
# -*- coding: utf-8 -*-
# django command to check if a url return a status != 2xx
import sys
import json
import aiohttp
import asyncio
from django.core.management.base import NoArgsCommand
@IuryAlves
IuryAlves / vlc.py
Last active December 5, 2016 14:58
# coding: utf-8
import os
import sys
import commands
import codecs
import time
import subprocess
musica_process_output = subprocess.check_output("tasklist /V /FO list /FI \"IMAGENAME eq vlc.exe\"", shell=False)
#!/usr/bin/env python
# coding: utf-8
### REQUIREMENTS ###
# * python 3.5+
# * aiohttp (pip install aiohttp)
import argparse
import os
.frontend {
margin: nelson
}
# coding: utf-8
'''
Para rodar
python3 markdown_to_json.py file1 file2
'''
import json
import sys