Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
#!/usr/bin/python | |
############################################################################### | |
# Produce a collage (grid) of friend profile images from Facebook. | |
# Inspired by Vipin "swvist" Nair @ https://gist.github.com/2692786 | |
############################################################################### | |
# Copyright (c) 2012 Madzen | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
""" | |
A really stupid python template language inspired by coffeekup, markaby. | |
Do not use this code, it will ruin your day. A byproduct of insomnia. | |
TL;DR | |
----- | |
This module defines a template language that allows us to do: | |
d = Doc() |
function get_avatar_from_service(service, userid, size) { | |
// this return the url that redirects to the according user image/avatar/profile picture | |
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback | |
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px ) | |
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word ) | |
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px ) | |
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word ) | |
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px ) | |
// everything else will go to the fallback | |
// google and gravatar scale the avatar to any site, others will guided to the next best version |
import bisect | |
class NFA(object): | |
EPSILON = object() | |
ANY = object() | |
def __init__(self, start_state): | |
self.transitions = {} | |
self.final_states = set() | |
self._start_state = start_state |