Skip to content

Instantly share code, notes, and snippets.

View rkennesson's full-sized avatar
:octocat:
I may be slow to respond.

Richard Kennesson rkennesson

:octocat:
I may be slow to respond.
View GitHub Profile
@rkennesson
rkennesson / corecloze.py
Last active August 29, 2015 14:07 — forked from dlip/corecloze.py
import re
debug = False
file = None
if debug:
file = open('test.txt', 'r')
else:
file = open('core10k.txt', 'r')
#Parse 2014 MN Capital budget - https://www.revisor.mn.gov/laws/?year=2014&type=0&doctype=Chapter&id=294
#Store the summary in a DataFrame for eventual manipulation
from __future__ import print_function
import os.path
from collections import defaultdict
import string
import requests
from bs4 import BeautifulSoup
import pandas as pd
import matplotlib.pyplot as plt
@rkennesson
rkennesson / isnumber.py
Created January 13, 2015 01:16
check if input is a number
#http://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-number-in-python
def is_number(s):
try:
n=str(float(s))
if n == "nan" or n=="inf" or n=="-inf" : return False
except ValueError:
try:
complex(s) # for complex
except ValueError:

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@rkennesson
rkennesson / Bash - reload bashrc
Last active August 29, 2015 14:14
Reload the .bashrc file after making a change without logging off
source ~/.bashrc
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetCapsLockState, AlwaysOff
fallback_prevention := 0
caps := 0
;global toggle for caps-modifier (= Capslock key)
@rkennesson
rkennesson / comments
Last active August 29, 2015 14:14 — forked from 1328/comments
from random import randrange
class Player(object):
def __init__(self, who = 'you'):
self.score = 0
self.who = who
def choose(self):
'''let's not make choice an instance variable, since it varies on each
; Autohotkey Capslock Remapping Script
; Danik
; More info at http://danikgames.com/blog/?p=714
; danikgames.com
;
; Functionality:
; - Deactivates capslock for normal (accidental) use.
; - Hold Capslock and drag anywhere in a window to move it (not just the title bar).
; - Access the following functions when pressing Capslock:
; Cursor keys - J, K, L, I
@rkennesson
rkennesson / .gitconfig
Last active August 29, 2015 14:24 — forked from sanguis/.gitconfig
[color]
ui = on
[core]
whitespace= fix,-indent-with-non-tab,-indent-with-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[alias]
df = !git diff --no-prefix && git diff --staged --no-prefix
clear = reset --hard
st = status
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative