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
| from graphene_django.filter import DjangoFilterConnectionField | |
| from graphql.utils.ast_to_dict import ast_to_dict | |
| def collect_fields(node): | |
| non_fields = ["edges", "node"] | |
| fields = [] | |
| for leaf in node: | |
| if leaf.get('kind', None) == "Field" and not leaf["name"]["value"] in non_fields: | |
| fields.append(leaf["name"]["value"]) |
| #!/bin/bash | |
| # Stop all containers | |
| containers=`docker ps -a -q` | |
| if [ -n "$containers" ] ; then | |
| docker stop $containers | |
| fi | |
| # Delete all containers | |
| containers=`docker ps -a -q` | |
| if [ -n "$containers" ]; then | |
| docker rm -f -v $containers |
| #!/usr/bin/env python | |
| import os, sys | |
| sys.path.append(os.getcwd()) | |
| import logging | |
| import rq | |
| MAX_FAILURES = 3 |
| import com.amazonaws.AmazonClientException; | |
| import com.amazonaws.AmazonServiceException; | |
| import com.amazonaws.AmazonWebServiceRequest; | |
| import com.amazonaws.ResponseMetadata; | |
| import com.amazonaws.regions.Region; | |
| import com.amazonaws.services.sqs.AmazonSQS; | |
| import com.amazonaws.services.sqs.model.*; | |
| import com.google.common.hash.Hashing; | |
| import java.util.*; |
| #!/usr/bin/env python | |
| """ | |
| How to use it: | |
| 1. Just `kill -2 PROCESS_ID` or `kill -15 PROCESS_ID` , The Tornado Web Server Will shutdown after process all the request. | |
| 2. When you run it behind Nginx, it can graceful reboot your production server. | |
| 3. Nice Print in http://weibo.com/1682780325/zgkb7g8k7 | |
| """ |
| # -*- mode: ruby -*- | |
| # vi: set ft=ruby : | |
| # David Lutz's Multi VM Vagrantfile | |
| # inspired from Mark Barger's https://gist.github.com/2404910 | |
| boxes = [ | |
| { :name => :web, :role => 'web_dev', :ip => '192.168.33.1', :ssh_port => 2201, :http_fwd => 9980, :cpus =>4, :shares => true }, | |
| { :name => :data, :role => 'data_dev', :ip => '192.168.33.2', :ssh_port => 2202, :mysql_fwd => 9936, :cpus =>4 }, | |
| { :name => :railsapp, :role => 'railsapp_dev', :ip => '192.168.33.3', :ssh_port => 2203, :http_fwd => 9990, :cpus =>1} | |
| ] |
| #!/bin/bash | |
| VENV=$1 | |
| if [ -z $VENV ]; then | |
| echo "usage: runinenv [virtualenv_path] CMDS" | |
| exit 1 | |
| fi | |
| . ${VENV}/bin/activate | |
| shift 1 | |
| echo "Executing $@ in ${VENV}" | |
| exec "$@" |
| """Utilities for managing database sessions.""" | |
| from __future__ import with_statement | |
| import contextlib | |
| import functools | |
| @contextlib.contextmanager | |
| def temp_session(session_cls, **kwargs): | |
| """Quick and dirty context manager that provides a temporary Session object | |
| to the nested block. The session is always closed at the end of the block. |