Skip to content

Instantly share code, notes, and snippets.

View alecklandgraf's full-sized avatar

Aleck Landgraf alecklandgraf

View GitHub Profile
@alecklandgraf
alecklandgraf / pre-commit
Created June 15, 2015 18:26
git pre-commit hook to prevent committing to master
#!/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
#!/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)
@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 / 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 / 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:
# 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 *
@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 / good.py
Last active July 7, 2022 08:02
Python, the good parts
# string format with kwargs
user = {
'first_name': 'John',
'last_name': 'Doe',
'email': '[email protected]',
}
user_bio = '{first_name} is registered with email: {email}'.format(**user)
# string format with an object
class User(object):
@alecklandgraf
alecklandgraf / routes.clj
Created February 18, 2016 05:09
home-page
(defn home-page [request]
(let [flash (:flash request)]
(layout/render
"home.html"
(merge {:messages (db/get-messages)}
(select-keys flash [:name :message :errors])))) )
# This creates some bad audit_types
class AuditLog(models.Model):
LOG = 'lo',
NOTE = 'no',
AUDIT_CHOICES = (
(LOG, 'log'),
(NOTE, 'note',
)
audit_type = models.CharField(choices=audit_CHOICES)