Skip to content

Instantly share code, notes, and snippets.

View anapaulagomes's full-sized avatar

Ana Paula Gomes anapaulagomes

View GitHub Profile
@anapaulagomes
anapaulagomes / intellij-tricks.md
Created December 12, 2017 08:59
Intellij Tricks (that I always forget)
@anapaulagomes
anapaulagomes / newpost.py
Created May 31, 2018 07:41
Friendly command to create new posts on Hugo
"""
Hugo new post
> python newpost.py --title="Regex pra quem não sabe Regex" --lang=pt-br --editor=atom
Same of:
hugo new regex-pra-quem-não-sabe-regex.pt-br.md --editor=atom
"""
import argparse
@anapaulagomes
anapaulagomes / pre-push
Last active June 16, 2018 13:46 — forked from msiemens/pre-commit.sh
My git pre-push hook
#!/bin/bash
echo "Running tests..."
pytest tests/
code=$?
if [ "$code" -eq "0" ]; then
echo
echo
echo "All tests passed. Continuing..."
@anapaulagomes
anapaulagomes / db_helper.py
Created July 6, 2018 09:52
Scaffold for db helper
class DbWorker:
"""Doing the hard work on the DB."""
def __init__(self, queries):
self.queries = queries # old tables
def _connect(self, credentials):
# TODO here only db connection stuff - must return the cursor
# TODO must thrown an exception in error cases
pass
@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 / 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 / stringinterpolation.py
Created February 23, 2018 14:56
String interpolation benchmark
# Taken from: https://cito.github.io/blog/f-strings/
import timeit
format = """
def format(name, age):
return f'He said his name is {name} and he is {age} years old.'
""", """
def format(name, age):
return 'He said his name is %s and he is %s years old.' % (name, age)