Skip to content

Instantly share code, notes, and snippets.

View ngbeslhang's full-sized avatar

ngb ngbeslhang

View GitHub Profile
floer32 /
Created January 16, 2014 17:20
DotDict is a variation of the classic "Bunch" recipe - just a dictionary, with all the normal dictionary methods, but the attributes are accessible by dot notation. Use this when you just really want to turn some dictionaries (i.e. from JSON) into something like JavaScript objects. Achieved with very little code. See bottom of docstring for Stac…
class DotDict(dict):
""" A dictionary whose attributes are accessible by dot notation.
This is a variation on the classic `Bunch` recipe (which is more limited
and doesn't give you all of dict's methods). It is just like a dictionary,
but its attributes are accessible by dot notation in addition to regular
`dict['attribute']` notation. It also has all of dict's methods.
.. doctest::


Now located at

Why it was moved

Github gists don't support Pull Requests or any notifications, which made it impossible for me to maintain this (surprisingly popular) gist with fixes, respond to comments and so on. In the interest of maintaining the quality of this resource for others, I've moved it to a proper repo. Cheers!

hrldcpr /
Last active November 16, 2023 15:23
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

View regex-weburl.js
// Regular Expression for URL validation
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
// Copyright (c) 2010-2018 Diego Perini (