Skip to content

Instantly share code, notes, and snippets.

View anapaulagomes's full-sized avatar

Ana Paula Gomes anapaulagomes

View GitHub Profile
@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 / 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 / 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 / intellij-tricks.md
Created December 12, 2017 08:59
Intellij Tricks (that I always forget)
@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 / 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 / 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 / gist:53db7ec2f3d31f5c9fb613ca1c737544
Created May 26, 2016 18:28
Filtra por finais de semana e agrupa por horas
db.checkins.aggregate([
{'$project':{
'dia_da_semana': {'$dayOfWeek': '$data'},
'usuario.cidades.residencia.pais': 1,
'h':{'$hour':'$data'},
'base.cidade': 1,
'base.nome': 1,
'base.classe': 1
}
},
db.checkins.aggregate(
{ "$match": {"base.cidade": "newyork", "local.nome": "Starbucks"}},
{ "$project": { "h":{"$hour":"$data"} } },
{ "$group":{ "_id": { "hour":"$h"}, "total":{ "$sum": 1} } }, {$sort: {"_id.hour": 1}})
@anapaulagomes
anapaulagomes / gist:cccabef3fe44a49b37252401c7df56e7
Created May 9, 2016 17:50
Busca com o uso da cláusula OU (lista de valores desejados)
db.checkins.find({'base.nome': 'copa2014', 'base.cidade': { $in: ['london', 'tokyo', 'rio', 'newyork']}})