Skip to content

Instantly share code, notes, and snippets.

Avatar

Marcio Mazza marciomazza

View GitHub Profile
@marciomazza
marciomazza / commits_from_author.py
Last active Jun 7, 2019
Get commits from an author in a time period
View commits_from_author.py
from datetime import datetime
from git import Repo
def get_commits_from_author(repo_path, author_term, start_date, end_date):
repo = Repo(repo_path)
start_date, end_date = [
datetime.fromisoformat(d).date() for d in (start_date, end_date)
]
View micro_refactorings.py
a == 1 or a == 2 or a == 3 # a == 1 or a == 2 or a == 3 or ... or a == N
a in [1, 2, 3] # a in [1, 2, 3, ..., N]
a if a else b
a or b
# ... list building with appends => list comprehensions
@marciomazza
marciomazza / propostas_pybr12.py
Last active Jul 20, 2016
Scrapping das propostas no site da pybr 12
View propostas_pybr12.py
#!/usr/bin/env python
# requirements:
#
# beautifulsoup4
# requests
# unidecode
from itertools import groupby
View watch_interlegis.py
import getpass
from github import Github
def main():
username = raw_input("User: ")
pw = getpass.getpass('Sua senha: ')
g = Github(username, pw)
me = g.get_user()
@marciomazza
marciomazza / postactivate
Last active Aug 29, 2015
Virtualenv general postactivate hook to trigger sublime projects and more
View postactivate
#!/bin/bash
# This hook is run after every virtualenv is activated.
# (~/.virtualenvs/postactivate)
DOT_PROJECT="${VIRTUAL_ENV}/.project"
if [ -f $DOT_PROJECT ]; then
PROJECT_DIR=`head -n 1 ${DOT_PROJECT} | tr -d '[[:space:]]'`
# GIT status
if [ -d "$PROJECT_DIR/.git" ]; then
git -C $PROJECT_DIR status -sb
@marciomazza
marciomazza / i18n_from_portuguese.py
Last active Aug 29, 2015
Script to aid on a "reverse translation" FROM [a portuguese codebase with no i18n] TO [an english one with i18n]
View i18n_from_portuguese.py
# Script to aid on a "reverse translation":
# * FROM a portuguese codebase with no i18n
# * TO an english one with i18n
#
# Process:
#
# In the cenario wher your have all your code with portuguese strings and no i18n
# (Naturally that applies to other languages as well)
#
# 1. Mark all your translatable portuguese strings with gettext marks _(...)
@marciomazza
marciomazza / django test.sublime-build
Created Jun 13, 2014
Sublime text build for Django manage.py test (and coverage as a variant)
View django test.sublime-build
// Assumes a virtualenv inside ~/.virtualenvs that has the same name as the project
// Assumes manage.py is inside src
{
"working_dir": "${project_path}/src",
"shell_cmd": "~/.virtualenvs/${project_base_name}/bin/python manage.py test",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"syntax": "Packages/User/Unittest Output.tmLanguage",
"quiet": "True",
"variants": [
@marciomazza
marciomazza / Unittest Output.JSON-tmLanguage
Last active Aug 29, 2015
Sublime Text syntax definition for unittest output
View Unittest Output.JSON-tmLanguage
// [PackageDev] target_format: plist, ext: tmLanguage
{ "name": "Unittest Output",
"scopeName": "output.unittest",
"patterns": [
{ "match": "FAIL: ([^ ]+) (.+)",
"name": "unittest.fail",
"captures": {
"1": { "name": "entity.name.function" },
"2": { "name": "support.function" }
}
@marciomazza
marciomazza / gist:7158411
Last active Jan 7, 2019 — forked from alextakitani/gist:6413691
Cedilha em teclado us-internacional, no Ubuntu 13.10 Saucy Salamander
View gist:7158411
1) Editar cada um dos arquivos:
/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache
/usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/gtk.immodules
Procurar uma linha que começa com cedilla e adicione um :en no último parâmetro, assim:
"cedilla" "Cedilla" "gtk20" "/usr/share/locale" "az:ca:co:fr:gv:oc:pt:sq:tr:wa:en"
Ou simplesmente rode:
@marciomazza
marciomazza / highlight_sel_element.py
Created Jul 10, 2012
Highlights a Selenium Webdriver element
View highlight_sel_element.py
def highlight(element):
"""Highlights (blinks) a Webdriver element.
In pure javascript, as suggested by https://github.com/alp82.
"""
driver = element._parent
driver.execute_script("""
element = arguments[0];
original_style = element.getAttribute('style');
element.setAttribute('style', original_style + "; background: yellow; border: 2px solid red;");
setTimeout(function(){