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
| #! /usr/bin/env python | |
| import redis | |
| import random | |
| import pylibmc | |
| import sys | |
| r = redis.Redis(host = 'localhost', port = 6389) | |
| mc = pylibmc.Client(['localhost:11222']) |
| # remember to patch first | |
| from gevent import monkey | |
| monkey.patch_all() | |
| import gevent | |
| from uuid import uuid4 | |
| from cassandra.cqlengine.connection import setup | |
| from cassandra.cqlengine.columns import * |
| def dicty(d, key=None): | |
| """removes empty string and None values from a nested dict, if key, then prints all values within the dict""" | |
| if key: | |
| for k, v in d.items(): | |
| if k.lower() == key.lower(): | |
| print "{}: {}".format(k, v) | |
| if isinstance(v, dict): | |
| dicty(v, key) | |
| if isinstance(v, list): | |
| for x in v: |
| //Practically all this code comes from https://github.com/alangrafu/radar-chart-d3 | |
| //I only made some additions and aesthetic adjustments to make the chart look better | |
| //(of course, that is only my point of view) | |
| //Such as a better placement of the titles at each line end, | |
| //adding numbers that reflect what each circular level stands for | |
| //Not placing the last level and slight differences in color | |
| // | |
| //For a bit of extra information check the blog about it: | |
| //http://nbremer.blogspot.nl/2013/09/making-d3-radar-chart-look-bit-better.html |
| #!/usr/bin/env python | |
| # Example for RC timing reading for Raspberry Pi | |
| # Must be used with GPIO 0.3.1a or later - earlier verions | |
| # are not fast enough! | |
| import RPi.GPIO as GPIO, time, os | |
| DEBUG = 1 | |
| GPIO.setmode(GPIO.BCM) |
| #!/bin/sh | |
| branch=`git symbolic-ref --short HEAD` | |
| # allow user input within pre-commit hook | |
| exec < /dev/tty | |
| if [ $branch == "master" ]; then | |
| echo "Commit to master [yes|no]?" | |
| read yesno | |
| if [ "$yesno" == "yes" ]; then |
| def reindex_orgs(org_ids): | |
| from seed.services import es_search_query | |
| from elasticsearch import Elasticsearch | |
| s = es_search_query() | |
| s = s.filter('terms', building_snapshot__super_organization=org_ids) | |
| from seed.services import elasticsearch_client | |
| es = elasticsearch_client() | |
| es.delete_by_query(index=settings.ES_INDEX, doc_type='canonical_building', body=s.to_dict()) | |
| from seed.utils.seed_elasticsearch import canon_serializer | |
| import itertools |
Building Energy strives to help businesses and governments understand where energy usage occurs, and how to improve energy efficiency. Let’s look at some real-world data in a similar field; check out World Bank Data on Carbon Emissions. Click "Download Data" and select the format you want to work with, (CSV might be simplest).
Let’s build a simple application to read in this data from the commandline and sort the rows by a function applied across the columns of said rows.
We should be able to answer the following questions: