This file contains 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
To change a field name in django 1.7+ | |
1. Edit the field name in the model (but remember the old field name: you need it for step 3!) | |
2. Create an empty migration | |
$ python manage.py makemigrations --empty myApp | |
3. Edit the empty migration (it's in the migrations folder in your app folder, and will be the most recent migration) by adding | |
migrations.RenameField('MyModel', 'old_field_name', 'new_field_name'), | |
to the operations list. |
This file contains 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
import os | |
import falcon | |
import jinja2 | |
def load_template(name): | |
path = os.path.join('templates', name) | |
with open(os.path.abspath(path), 'r') as fp: | |
return jinja2.Template(fp.read()) |
Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...
// see: https://github.com/chadoe/docker-cleanup-volumes
$ docker volume rm $(docker volume ls -qf dangling=true)
$ docker volume ls -qf dangling=true | xargs -r docker volume rm
This file contains 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
import tarfile | |
import time | |
from io import BytesIO | |
admin_password = 'xxxxx' | |
#write password to file | |
pw_tarstream = BytesIO() | |
pw_tar = tarfile.TarFile(fileobj=pw_tarstream, mode='w') | |
file_data = admin_password.encode('utf8') |
Syntax: cat <filename> | jq -c '.[] | select( .<key> | contains("<value>"))'
Example: To get json record having _id equal 611
cat my.json | jq -c '.[] | select( ._id | contains(611))'
Remember: if JSON value has no double quotes (eg. for numeric) to do not supply in filter i.e. in contains(611)
This file contains 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 datetime import datetime | |
links = [ | |
'https://g1.globo.com/rj/rio-de-janeiro/noticia/pf-cumpre-mandados-em-mais-um-desdobramento-da-lava-jato-no-rio.ghtml', | |
'https://g1.globo.com/sp/sao-paulo/noticia/ataque-a-tiros-mata-1-e-deixa-2-feridas-em-frente-a-hotel-em-sp-veja-video.ghtml', | |
'https://globoesporte.globo.com/olimpiadas-de-inverno/noticia/nervosa-isadora-williams-sofre-queda-na-final-da-patinacao-e-chora-muito-triste.ghtml', | |
'https://g1.globo.com/agenda-do-dia/noticia/sexta-feira-23-de-fevereiro.ghtml', | |
'https://g1.globo.com/rj/rio-de-janeiro/noticia/general-richard-nunez-sera-o-secretario-de-seguranca-do-rj.ghtml', | |
'https://g1.globo.com/rj/rio-de-janeiro/noticia/comandante-de-instituicao-de-ensino-da-pm-do-rj-e-exonerado-policiais-denunciam-abusos.ghtml', |
Poker hand ranking
Write a function that tells you the best scoring for a given poker hand of 5 cards. For instance:
(score [[3 :diamonds] [3 :hearts] [3 :spades] [5 :hearts] [:king :clubs]])
=> :three-of-a-kind ;; three 3s
Cards are represented as a tuple of rank (number or name if it's a face card) and suit. Face card names are the keywords :ace
, :king
, :queen
, :jack
. Suits are :diamonds
, :spades
, :hearts
, :clubs
.