Skip to content

Instantly share code, notes, and snippets.

λ let nest f n x = if n <= 0 then x else f (nest f (n-1) x)
λ let pow2 x = x^x
λ nest pow2 3 3
<interactive>: out of memory (requested 1048576 bytes)
λ import Data.List
λ let nest f n x = foldl' (\a _->f a) x [1..n]
λ let pow2 x = x^x
λ nest pow2 3 3
<interactive>: out of memory (requested 1048576 bytes)
@m1el
m1el / trees.hs
Created July 14, 2014 10:46
playing with trees
data Tree a = Node a (Tree a) (Tree a) | Nil
deriving Show
treeDown :: (Tree a -> Tree a -> a) -> [a] -> Int -> (Tree a, [a])
treeDown fn [] _ = (Nil, [])
treeDown fn (x:xs) 0 = (Node x Nil Nil, xs)
treeDown fn xs n =
let (left, xs') = treeDown fn xs (n - 1)
(right, rem) = treeDown fn xs' (n - 1)
in (Node (fn left right) left right, rem)
a ~> b = not (a && not b)
truthTable3 fn = do
a <- [False, True]
b <- [False, True]
c <- [False, True]
return $ fn a b c
f8b p q r = not((p && not q) || r) == (r ~> q)
f8c p q r = not (p ~> q) ~> (q ~> r)

#invoker mega-combo

eewrwqrd.f.erd.1f.ewrd.f.

@m1el
m1el / mpt.py
Created August 27, 2014 08:47
playing past twitch broadcasts in mpv
#license=WTFPLv2
#playing past twitch broadcasts in mpv
import sys, os, re
import requests
import json
urlfmt = 'https://api.twitch.tv/api/videos/a{}'
if __name__ == '__main__':
if len(sys.argv) < 2:
print('not enough arguments! pass broadcast url.')
sys.exit(1)
@m1el
m1el / other-logs
Last active August 29, 2015 14:05
parsing logs
m1el@m1el:~/sources/log-parsing$ perl -e 'print "1409139024985\tINFO\t= Call duration 0 seconds\n" for (1..1000000)' > kid.txt
m1el@m1el:~/sources/log-parsing$ perl -MJSON -ne 'print encode_json([split /\t/, $_]), "\n"' < kid.txt > kid.json
m1el@m1el:~/sources/log-parsing$ time perl -ne '@data = split /\t/, $_' < kid.txt
real 0m5.960s
user 0m5.912s
sys 0m0.044s
m1el@m1el:~/sources/log-parsing$ time perl -MJSON -ne 'decode_json($_)' < kid.json
real 0m5.456s
use JSON::XS;
use JSON::PP;
use mjson;
use Benchmark qw(:all);
my $string = "1409139024985\tINFO\t= Call duration 0 seconds";
my $json = '["1409139024985","INFO","= Call duration 0 seconds"]';
my $json2 = '{"time":"1409139024985","type":"INFO","data":"= Call duration 0 seconds\n"}';
cmpthese(100000, {
split => sub {
my @data = split /\t/, $string;
input: SExpression {
std::cout << "Result: ";
};
Part: Symbol | String | Integer {
std::cout << "Part\n";
}
CallArgs: | CallArgs CallArg;
var http = require('http'),
queue = require('queue-async');
var urls = [
'/?0',
'/?1',
'/?2',
'/?3',
'/?4',
'/?5',
@m1el
m1el / ackermann.py
Created September 22, 2014 10:55
non-recursive implementation of Ackermann function
def ack_rec(m, n):
print(m, n)
if m == 0:
return n + 1
elif n == 0:
return ack_rec(m-1, 1)
else:
return ack_rec(m-1, ack_rec(m, n-1))
def ack_norec(m, n):