Python Cheatsheets
http://refcardz.dzone.com/refcardz/core-python
http://rgruet.free.fr/
Learn Python in 10 minutes
http://www.stavros.io/tutorials/python/
https://leanpub.com/learn-python
| #!/usr/bin/env bash | |
| # execute via “dot space dot slash” to avoid a subshell. | |
| # for example: ". ./django.sh" instead "./django.sh" | |
| echo "$(tput setaf 1)Creating new virtual environment ...$(tput sgr0)" | |
| python -m venv venv | |
| source venv/bin/activate | |
| echo "$(tput setaf 1)Seting up django project ...$(tput sgr0)" | |
| touch README.md | |
| python -m pip install --upgrade pip |
| #! /bin/bash | |
| yum update -y | |
| yum install -y docker | |
| usermod -a -G docker ec2-user | |
| curl -L https://github.com/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` | sudo tee /usr/local/bin/docker-compose > /dev/null | |
| chmod +x /usr/local/bin/docker-compose | |
| service docker start | |
| chkconfig docker on | |
| rm /etc/localtime |
| docker service logs my_service --follow 2>&1 | grep payload |
| # see http://editorconfig.org | |
| root = true | |
| [*] | |
| indent_style = space | |
| end_of_line = lf | |
| charset = utf-8 | |
| trim_trailing_whitespace = true | |
| insert_final_newline = true |
| from functools import wraps | |
| from flask import request, abort | |
| from lib.logger import logger | |
| def authorize_bearer(bearer): | |
| def authorize(f): | |
| @wraps(f) | |
| def decorated_function(*args, **kws): | |
| if 'Authorization' not in request.headers: |
| import logging | |
| logging.basicConfig( | |
| format='%(asctime)s [%(levelname)s] %(message)s', | |
| level='INFO', | |
| datefmt='%d/%m/%Y %X') | |
| logger = logging.getLogger(__name__) |
| #!/usr/bin/env bash | |
| PATH=/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin | |
| # actual battery level | |
| BATT=`ioreg -c AppleDeviceManagementHIDEventService -r -l | grep -i mouse -A 20 | grep BatteryPercent | cut -d= -f2 | cut -d' ' -f2` | |
| # defaults to warn at 20%; accepts other number as 1st argument (useful for testing) | |
| COMPARE=${1:-20} | |
| if [ -z "$BATT" ]; then |
| import cv2 | |
| import numpy as np | |
| from skimage.measure import compare_ssim as ssim | |
| def mse(imageA, imageB): | |
| # the 'Mean Squared Error' between the two images is the | |
| # sum of the squared difference between the two images; | |
| # NOTE: the two images must have the same dimension | |
| err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2) | |
| err /= float(imageA.shape[0] * imageA.shape[1]) |
Python Cheatsheets
http://refcardz.dzone.com/refcardz/core-python
http://rgruet.free.fr/
Learn Python in 10 minutes
http://www.stavros.io/tutorials/python/
https://leanpub.com/learn-python
| <?php | |
| echo (new \DateTime())->diff(\DateTime::createFromFormat('Y-m-d H:i:s', json_decode((new Guzzle\Http\Client('http://karmacracy.com'))->get('/api/v1/user/gonzalo123')->send()->getBody(), true)['data']['user'][0]['date_signed']))->format('%y') . "year/s old"; |