https://www.jetbrains.com/help/pycharm/creating-and-applying-live-templates-code-snippets.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Running tests..." | |
pytest tests/ | |
code=$? | |
if [ "$code" -eq "0" ]; then | |
echo | |
echo | |
echo "All tests passed. Continuing..." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.logs.aggregate({$group: {_id: {'exchangeType': '$result.exchangeType'}, soma: {$sum: 1}}}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.checkins.find({'base.nome': 'copa2014', 'base.cidade': { $in: ['london', 'tokyo', 'rio', 'newyork']}}) |