Skip to content

Instantly share code, notes, and snippets.

View pkulev's full-sized avatar

Pavel Kulyov pkulev

View GitHub Profile
from datetime import datetime
DEBUG = True
TIMER = True
def logger(func):
import sys
def inner(*args, **kwargs):
sys.stdout.write("[{}] Calling FNAME with args: {} | kwargs: {}\n".format(datetime.now(),
args,
import sys
import curses
from curses import KEY_ENTER
import time
from collections import namedtuple
KEY = "KEY"
K_A = ord("a")
K_D = ord("d")
@pkulev
pkulev / lol.py
Created September 20, 2014 13:23
#!/usr/bin/env python
from __future__ import print_function
import curses
import functools
import sys
class Settings(object):
fun {Prefix L1 L2}
case L1
of H|T then
if H == L2.1 then {Prefix T L2.2}
else false end
[] nil then true
end
end
fun {FindString L1 L2}
% if head is nil then answer
% if head is integer then append it to answer and flatten tail
% if head is list then flatten head and then flatten tail
declare
fun {FlattenList L}
local FlatLoop in
fun {FlatLoop L1 Acc}
case L1
of nil then Acc
declare
fun {Map F L}
case L of nil then nil
[] H|T then {F H} | {Map F T}
end
end
{Browse {Map fun {$ X} X*X end [1 2 3 4]}}
local FillRecord in
fun {FillRecord Features Values Rec}
case Features
of H|T then
case Values.1
of Lab|Feat|Val then
{FillRecord T Values.2
{AdjoinAt Rec H
{Transform Lab|Feat|Val}}}
[] Val then
#include <stdio.h>
#include <stdlib.h>
int pow2(int val)
{
return val * val;
}
int* map(int (*func)(int), int *arr, int len)
{ int *res = malloc(sizeof(int) * len);
>>> def myreduce(func, list, initial):
... def inner(inner_list, acc):
... if not inner_list: return acc
... else: return inner(inner_list[1:], func(acc, inner_list[0]))
... return inner(initial + list, 0)
...
#! /usr/bin/env python
import os
import sys
usage = "USAGE: {0} path".format(sys.argv[0])
if len(sys.argv) != 2:
print usage
sys.exit(1)