Skip to content

Instantly share code, notes, and snippets.

Avatar

Devvyn P M devvyn

View GitHub Profile
View Fizzbuzz_dryness_vs_readability.py
# 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 / philips-hue-lets-play.ipynb
Last active Jan 9, 2018
Philips Hue API - let's play
View philips-hue-lets-play.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@devvyn
devvyn / matias-like one-handed qwerty for karabiner.xml
Created Jan 31, 2017 — 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.
View matias-like one-handed qwerty for karabiner.xml
<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>
View fortune-cowsay-lolcat-loop.sh
#!/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 / skutree.py
Created Feb 22, 2015
code sketch: grab a CSV file with a column called "OTV SKU#" and split the characters in all the values into a character tree
View skutree.py
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 / CsvFileModel.py
Last active Sep 9, 2017
Super easy CSV file reader class with column accessors (magic __getattr__ for named columns)
View CsvFileModel.py
# 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')