Sunday, September 8, 2013

Erlang string lambdas


There is an old (hey 2007!) article about different Erlang string lambdas http://debasishg.blogspot.com/2007/11/erlang-string-lambdas.html

Saturday, June 16, 2012

Lambda of saturday. Read a twitter from Erlang console

fun(Word) -> [_,Twts,_,_] = [X || X <- erlang:tuple_to_list(element(1, xmerl_scan:string(element(3, element(2, httpc:request("http://search.twitter.com/search.atom?&q=" ++ Word)))))), erlang:length(X) >= 1], [[io:format("~p~n", [lists:merge([element(5, H) || H <- element(9, E)])]) || E <- element(9, T), element(2,E) =:= content] || T <- Twts, element(2,T) =:= entry] end("Erlang").

Saturday, June 9, 2012

WOW! More lambdas for board

>>>import urllib2,json,os,sys,threading,urlparse;wget=lambda i,th: os.system("wget -c http://2ch.so/%s/%s" % (urlparse.urlparse(th).path.split('/')[1], i));fimg=lambda img: img[0]['image'];down=lambda th: map(lambda img: wget(fimg(img), th) if not os.path.isfile(fimg(img).replace('src/','')) else False, json.load(urllib2.urlopen(th))['thread']);down(sys.argv[1].replace("html", "json"))

$load.py http://url/thread.html

NoSQL into Python


>>>seq = [
{'name': "Tom", 'age': 10},
{'name': "Mark", 'age': 5},
{'name': "Pam", 'age': 7}
]
>>>foo = lambda g, n: filter(None, map(lambda x: x['age'] if x['name'] == n else None, g))
>>>foo(seq, 'Tom')
[10]

Friday, June 8, 2012

Decoding a simple captcha in one line

K = """# #  ###  # #  ###  ###  
# #  #    # #  #    #    
###  ###  ###  ###  ###  
  #  # #    #    #    #  
  #  ###    #  ###  ###  """

find = lambda prepared: map(lambda i: {"['# #', '# #', '###', '  #', '  #']": 4, "['###', '#  ', '###', '  #', '###']": 5, "['###', '#  ', '###', '# #', '###']": 6}[str([prepared[x][i:i+3] for x in range(int(len(prepared[0]) / 5))])], range(0, len(prepared[0]), 5))

10 Python one liners to impress your friends

>>>print map(lambda x: x * 2, range(1,11))

Some lambda on Python
func = lambda vec: reduce(mul, [f(v) for (f,v) in zip([ (lambda a : lambda x: (abs(4 * x - 2) + a) / (1 + a))(a) for a in [0, 0, 0, 9], vec)]

Python lambda-hardcore