A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
| import io | |
| import weasyprint | |
| from django.template.response import TemplateResponse | |
| class PDFResponse(TemplateResponse): | |
| def __init__(self, *args, **kwargs): |
| syntax on | |
| set number | |
| set relativenumber | |
| highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE |
| class FilterCurrentUserMixin(object): | |
| def get_queryset(self): | |
| queryset = super(FilterCurrentUserMixin, self).get_queryset() | |
| queryset = queryset.filter(user=self.request.user) | |
| return queryset |
| import datetime | |
| import io | |
| import time | |
| import picamera | |
| from PIL import Image, ImageStat, ImageFont, ImageDraw | |
| with picamera.PiCamera() as camera: |
| #!/bin/bash | |
| # de-fuck mysql 5.7 | |
| # This script allow you to log on MySQL as root user without use sudo | |
| # sudo apt install postgresql | |
| # sudo apt purge "mysql-*" | |
| # you know, would be better... | |
| sudo mysql -u root -e "CREATE USER 'root2'@'localhost';" |
| #!/bin/bash | |
| set -x | |
| EMAIL='' | |
| API_KEY='' | |
| ZONE_ID='' | |
| RECORD_ID='' |
| # -*- coding: utf-8 -*- | |
| import mock | |
| import requests | |
| def make_request(): | |
| try: | |
| return requests.get('http://httpbin.org/ip').json()['origin'] |
| # -*- coding: utf-8 -*- | |
| import requests | |
| API_URL = 'https://api.github.com/repos/{owner}/{repo}' | |
| client = requests.Session() | |
| client.auth = ('dvl', 'xx') | |
| client.headers.update({ | |
| 'Accept': 'application/vnd.github.v3+json', |
Linux installation notes (tested under Ubuntu 14.04LTS/12.04LTS), assuming VirtualBox is already installed on host.