Skip to content

Instantly share code, notes, and snippets.

View alecklandgraf's full-sized avatar

Aleck Landgraf alecklandgraf

View GitHub Profile
@alecklandgraf
alecklandgraf / API.md
Created September 29, 2016 23:50 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

<html>
<head>
<title>React StopWatch sample</title>
<meta name="viewport" content="width=device-width">
<script src="http://fb.me/react-0.13.1.js"></script>
<script src="http://fb.me/JSXTransformer-0.13.1.js"></script>
</head>
<body>
<script type="text/jsx">
var StopWatch = React.createClass({
@alecklandgraf
alecklandgraf / gist:1f372ab046bfe25f7606
Created February 11, 2016 20:44 — forked from mikeyk/gist:1329319
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])
@alecklandgraf
alecklandgraf / dicty.py
Last active February 10, 2016 00:37 — forked from anonymous/file1.py
Display values from a deeply nested dict in python
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:
@alecklandgraf
alecklandgraf / bobp-python.md
Created November 12, 2015 18:34 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@alecklandgraf
alecklandgraf / RadarChart.js
Last active September 2, 2015 15:57 — forked from nbremer/.block
Building Comparison Demo
//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
@alecklandgraf
alecklandgraf / file1.py
Last active August 29, 2015 14:17 — forked from anonymous/file1.py
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

Python Engineer Take Home Project

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:

  • Sort countries according to the average change in carbon emissions per capita (ascending, descending, etc.).
description "uWSGI server for electris CMS"
start on runlevel [2345] # start on all runlevels.
stop on runlevel [!2345] # stop when shutting down.
respawn # respawn if job crashes or is stopped ungracefully.
env DEPLOYMENT_TARGET=production # set any environment variables you like here.
env DJANGO_SETTINGS_FILE=conf/settings.py # more environment variables if you like.
env PYTHONPATH=/home/ubuntu/apps/my_app:/home/ubuntu/.virtualenv/my_app
try:
import xlrd
def XLSDictReader(f, sheet_index=0):
data = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
book = xlrd.open_workbook(file_contents=data)
sheet = book.sheet_by_index(sheet_index)
def item(i, j):
return (sheet.cell_value(0,j), sheet.cell_value(i,j))