Skip to content

Instantly share code, notes, and snippets.

View anapaulagomes's full-sized avatar

Ana Paula Gomes anapaulagomes

View GitHub Profile
@anapaulagomes
anapaulagomes / git-pre-commit-hook-django-migrations.sh
Created September 13, 2018 09:30
git-pre-commit-hook-django-migrations for bash
#!/usr/bin/env bash
previous_module=''
previous_filepath=''
previous_prefix=''
status_code="0"
for filepath in $(git ls-files -- $(find . -type f -regex '.*\migrations.*\.py$')); do
module=${filepath%%/*}
if [ "$previous_module" != "$module" ]; then
@anapaulagomes
anapaulagomes / server.py
Created October 7, 2018 20:28
Twython + Flask
from flask import Flask, url_for, session, request, redirect
import os
from cube.app import app, AuthToken
from cube.api import get_twitter_api
import twython
import time
api = get_twitter_api()
@anapaulagomes
anapaulagomes / twitter_oauth1.py
Created October 11, 2018 13:54
Twitter OAuth1
import os
from requests_oauthlib import OAuth1Session
request_token_url = 'https://api.twitter.com/oauth/request_token'
base_authorization_url = 'https://api.twitter.com/oauth/authorize'
access_token_url = 'https://api.twitter.com/oauth/access_token'
oauth = OAuth1Session(os.getenv('CONSUMER_KEY'), client_secret=os.getenv('CONSUMER_SECRET'))
@anapaulagomes
anapaulagomes / gist:7f4f8baa9e932cccd6d50075e5e0fa7b
Last active November 20, 2018 16:40
Github issues to JSON
curl -u your_user:your_personal_token 'https://api.github.com/repos/OwnerHereAttentionItISSensitiveCase/repo-name/issues?labels=flaky-test&state=all' > flaky-tests.json
# it requires the `repo` permission. you can generate your token here: https://github.com/settings/tokens - needed if you have 2FA enabled
@anapaulagomes
anapaulagomes / delete-old-branches-command
Last active February 5, 2019 16:37
Generate list of old branches with command to delete them
git for-each-ref
--sort=-committerdate refs/heads/
--format='git branch -D %(color:yellow)%(refname:short)%(color:reset) # (%(color:green)%(committerdate:relative)%(color:reset))'
@anapaulagomes
anapaulagomes / conftest.py
Created February 27, 2019 10:55
pytest-grilo: your consciousness remembering you to take care of yourself
import random
def choose_action():
actions = [
"It's time to drink water!",
"Have you stretched on the last hour?",
"You should walk around a bit",
]
return random.choice(actions)
@anapaulagomes
anapaulagomes / 1.views.py
Last active March 26, 2019 15:13
Code smell Temporal coupling example
class PrivateClassesView:
def post(self):
# code omitted for readability sake
data = {
'to': ['[email protected]'],
'body': 'blablabla',
'scheduled_for': datetime(2019, 3, 30, 11, 1, 0)
}
if subject:
data['subject'] = subject
@anapaulagomes
anapaulagomes / order_dict.py
Created April 7, 2019 07:45
Order a dict by value
# stolen from https://stackoverflow.com/questions/20944483/python-3-sort-a-dict-by-its-values
[(k, d[k]) for k in sorted(d, key=d.get, reverse=True)]
@anapaulagomes
anapaulagomes / test_example.py
Created May 29, 2019 14:45
Fixture to create files using pytest tmpdir
from pathlib import Path
import pytest
@pytest.fixture
def file_factory(tmpdir):
def _file_factory(path):
full_path = Path(path)
file_name = full_path.name
@anapaulagomes
anapaulagomes / README.md
Last active July 12, 2019 21:00
Mäxchen game