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
| #!/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. |
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
| $ 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 |
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
| 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): |
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}}}) |