Skip to content

Instantly share code, notes, and snippets.

View keenhenry's full-sized avatar

Henry Huang keenhenry

  • Veldhoven, Noord Brabant, The Netherlands
View GitHub Profile
@keenhenry
keenhenry / Print Python's Exception objects hierarchy
Created March 5, 2016 15:44
A small script to print out the Exception inheritance hierarchy. Useful for writing exception handling (Python 2.5+)
#!/usr/bin/env python
def classtree(cls, indent=0):
print '.' * indent, cls.__name__
for subcls in cls.__subclasses__():
classtree(subcls, indent + 3)
classtree(BaseException)
@keenhenry
keenhenry / beautiful_idiomatic_python.md
Created February 14, 2016 20:51 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. 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!

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]:
@keenhenry
keenhenry / bobp-python.md
Created November 8, 2015 09:55 — 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
@keenhenry
keenhenry / DisjointSet.java
Created August 22, 2015 10:43
Disjoint Set Data Structure
public class DisjSets
{
public DisjSets( int numElements )
{
s = new int [ numElements ];
for ( int i = 0; i < s.length; ++i )
s[i] = -1;
}
@keenhenry
keenhenry / index.html
Last active August 29, 2015 14:26 — forked from jonnyreeves/index.html
JavaScript Class Structure using requireJS. The following code shows you how to create a Class definition in one JavaScript file and then import it for use in another; coming from an ActionScript 3 background this (and some of JavaScript specific traits)
<!DOCTYPE html>
<html>
<head>
<script data-main="usage" src="http://requirejs.org/docs/release/1.0.8/comments/require.js"></script>
</head>
<body>
<p>Check your JavaScript console for output!</p>
</body>
</head>
@keenhenry
keenhenry / equal_element_array_transformation.py
Last active August 29, 2015 14:18
Equal-element array transformation problem
#!/usr/bin/env python
"""Problem Description:
There is an array consisting of N elements, all the elements are integer numbers (can be positive, zero or negative).
A transformation step is to be applied to the array, which is detailed as follows:
Each element has to be incremented or decremented by 1 in a single step