Skip to content

Instantly share code, notes, and snippets.

View anapaulagomes's full-sized avatar

Ana Paula Gomes anapaulagomes

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / git-pre-commit-hook-django-migrations
Last active July 8, 2019 15:39 — forked from mlorant/git-pre-commit-hook-django
Django - Avoid duplicate in migration names before committing changes in Git
#!/usr/bin/python
"""
Pre-commit hook for git written in Python.
Check if there is any migration number used more than one in each
migrations folder of South or Django >= 1.7.
You can install this pre-hook by executing the command:
ln -s ./git-pre-commit-hook .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
Or by calling the current script or check_migrations_files() in your
own file.
@anapaulagomes
anapaulagomes / gist:78fd7985244fdf75a4118eaad4e657e3
Last active August 7, 2018 08:30
Undoing a git rebase (or other operations like git merge)
$ git reflog my-branch # get the hash of the commit you want to be the HEAD (to be the last one in your git log)
$ git reset --hard a91ab06a5
@anapaulagomes
anapaulagomes / tasks.py
Last active March 13, 2023 12:26
Example of Celery signals
from celery.signals import task_failure, after_task_publish
@app.task(bind=True)
def my_task(self):
print(1/0) # this line will cause an exception
@after_task_publish.connect(sender='mymodule.tasks.my_task')
def task_sent_handler(sender=None, headers=None, body=None, **kwargs):