Skip to content

Instantly share code, notes, and snippets.

View devvyn's full-sized avatar

Devvyn Murphy devvyn

View GitHub Profile
# readable, but not DRY
def fb1(number):
return ''.join((
('fizz' if (not number % 3) else ''),
('buzz' if (not number % 4) else ''))) or str(number)
# fully DRY, easy to maintain
def fb2(number):
a = {3: 'fizz',
@devvyn
devvyn / CsvFileModel.py
Last active September 9, 2017 17:35
Super easy CSV file reader class with column accessors (magic __getattr__ for named columns)
# coding=utf-8
"""
Convenience wrapper for csv.DictReader showing use of __getattr__ to do magic lookups on the loaded file.
To procedurally implement CsvFileModel, without a new class, pass the target package_name and/or filename to the constructor.
For example:
my_spending_report = CsvFileModel(filename='spendnov1995.tsv', package_name='my_project.data')
my_spending_report = CsvFileModel(filename='spendnov1995.tsv')
#!/bin/bash
commands=(cow{say,think}); while [ "rainbows are delightful" ]; do (fortune | ${commands[$RANDOM % ${#commands[@]}]} -f $(cowsay -l | tail -n+2 | xargs -n 1 | sort -R | head -n 1) | lolcat -a ) && sleep 2; done
@devvyn
devvyn / matias-like one-handed qwerty for karabiner.xml
Created January 31, 2017 19:29 — forked from emory/matias-like one-handed qwerty for karabiner.xml
A Karabiner config to mimic the half-handed QWERTY behavior and layout of the Matias one-handed keyboards.
<root>
<item>
<!-- a brief discussion about this config was originally posted here https://groups.google.com/d/topic/osx-karabiner/4TdHyfImc-k I lifted it and changed the Name -->
<name>Matias Style One-handed Half-QWERTY</name>
<identifier>Half-QWERTY</identifier>
<autogen>
__HoldingKeyToKey__, KeyCode::SPACE, KeyCode::SPACE, KeyCode::VK_NONE, KeyCode::VK_CONFIG_SYNC_KEYDOWNUP_notsave_flip_hands
</autogen>
</item>
@devvyn
devvyn / skutree.py
Created February 22, 2015 20:23
code sketch: grab a CSV file with a column called "OTV SKU#" and split the characters in all the values into a character tree
from CsvFileModel import CsvFileModel # available from https://gist.github.com/devvyn/759f08e3d83e4cf8f7ef
import json
import yaml
import collections
class StringTree(object):
def __init__(self):
c = CsvFileModel('csp.csv')
skus = list(x.strip() for x in c['OTV SKU#'])
@devvyn
devvyn / philips-hue-lets-play.ipynb
Last active September 24, 2021 22:01
Philips Hue API - let's play
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@devvyn
devvyn / -chess-sandbox.ipynb
Last active November 17, 2021 23:20
chess-sandbox.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.