Skip to content

Instantly share code, notes, and snippets.

View anapaulagomes's full-sized avatar

Ana Paula Gomes anapaulagomes

View GitHub Profile
@anapaulagomes
anapaulagomes / gist:93a7b5345452f00d0c2a709c9e4e56c6
Created November 4, 2016 12:40
Group by field and count the occurrences
db.logs.aggregate({$group: {_id: {'exchangeType': '$result.exchangeType'}, soma: {$sum: 1}}})
@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 / git-tricks.md
Last active April 29, 2019 13:31
Git tricks

Git Tricks

Add changes by chunks

git add -p

Squash, edit, delete etc (interactive rebase)

git rebase -i HEAD~5 # last five commits

Rename a branch

@anapaulagomes
anapaulagomes / intellij-tricks.md
Created December 12, 2017 08:59
Intellij Tricks (that I always forget)
@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)
@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 / 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 / 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):
@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
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.