Skip to content

Instantly share code, notes, and snippets.

View tef's full-sized avatar
💭
Please don't try to contact me over GitHub.

tef tef

💭
Please don't try to contact me over GitHub.
View GitHub Profile
@tef
tef / gist:3688768
Created September 10, 2012 03:50 — forked from dstufft/gist:3688762
import collections
def flatten(input):
stack = list(reversed(input))
while stack:
top = stack.pop()
if isinstance(top, collections.Iterable):
stack.extend(list(reversed(top)))
else:
yield top
@tef
tef / gist:3688778
Created September 10, 2012 03:52 — forked from dstufft/gist:3688725
import collections
def flatten(input, seen=None):
for item in input:
if isinstance(item, collections.Iterable):
for sub in flatten(item):
yield sub
else:
yield item
def flatten(source):
stack = source[::-1]
while stack:
top = stack.pop()
if hasattr(top, '__iter__'):
stack.extend(reversed(top))
else:
yield top
print list(flatten([1,[2,3,[4,5,[6],7],8,[9,[10,11],[12],[[13]],[[[14,15]]],16]]]))
@tef
tef / flatten.py
Created January 5, 2013 05:53 — forked from anonymous/flatten.py
import collections
import itertools
def flattened(i):
i = iter(i)
while True:
first = i.next()
if isinstance(first, collections.Iterable):
i = itertools.chain(first, i)
else:
# coding=utf-8
import sys
normal = u' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~'
wide = u' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!゛#$%&()*+、ー。/:;〈=〉?@[\\]^_‘{|}~'
widemap = dict((ord(n), w) for n,w in zip(normal, wide))
while True:
line = sys.stdin.readline()
if not line:
@tef
tef / python_ruby.py.rb
Last active December 17, 2015 13:29
python/ruby quine. changes comment to indicate what it last ran as.
# Python or Ruby
l,p,q=(""and"# Ruby"+10 .chr or"# Python"+chr(10)),'l,p,q=(""and"# Ruby"+10 .chr or"# Python"+chr(10))','print((""and"#{print l;c=39.chr;puts p+44.chr+c+p+c+44.chr+c+q+c;puts q}"or"{}{},{!r},{!r}{}{}".format(l,p,p,q,chr(10),q)))'
print((""and"#{print l;c=39.chr;puts p+44.chr+c+p+c+44.chr+c+q+c;puts q}"or"{}{},{!r},{!r}{}{}".format(l,p,p,q,chr(10),q)))
from turtle import *
def curve(depth, length, angle):
if depth == 0:
if angle > 0:
pencolor('green')
else:
pencolor('blue')
forward(length)
@tef
tef / ersatz.bibimbap.rst
Last active December 21, 2015 02:19
try not to poison yourself with this weird old tip

ersatz bibimbap

bibimbap as i make it is basically

  • rice
  • sitr fried vegetables
  • some meat in tasty spices
  • gochujang (this is fermented soy bean paste with paprika)
  • a fried egg
@tef
tef / diff.md
Last active February 14, 2018 05:49
best diff ever
-                 Z    A 
-             Y            B
-         X                    C
-                        
-      W                           D
-                        
-    V                               E
-
-  U                                   F

I hate markdown

  1. Here is a list. I can do numbered lists.

  2. I can do a list entry followed by two spaces.

    This means this is in the same paragraph

  3. If I want a code block (with syntax highlighting, inside a list, something breaks: