Skip to content

Instantly share code, notes, and snippets.

@mrluanma
mrluanma / flatten.py
Created December 15, 2011 11:07 — forked from andelf/flatten.py
How to flatten a python nested list(tuple)
flatten = lambda lst: reduce(lambda l, i: l + flatten(i) if isinstance(i, (list, tuple)) else l + [i], lst, [])
print flatten([2, [2, [4, 5, [7], [2, [6, 2, 6, [6], 4]], 6]]])
# -> [2, 2, 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
@mrluanma
mrluanma / dnsd.rb
Created December 3, 2011 05:25 — forked from peterc/dnsd.rb
Simple, scrappy TCP DNS server in Ruby (with protocol annotations)
# Simple, scrappy TCP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL