Skip to content

Instantly share code, notes, and snippets.

@borman
borman / juick_backup.py
Last active August 29, 2015 13:55
Backup your public juick blog
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import codecs
import getpass
import glob
import json
import logging
import lxml.etree
@borman
borman / filter_map.cpp
Last active August 29, 2015 14:04
c++ filter_map
#include <iostream>
#include <vector>
#include <type_traits>
#include <boost/optional.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/adaptor/filtered.hpp>
template<typename MapperT>
class filter_mapped_adaptor;
#include <cmath>
#include <cstdint>
#include <random>
#include <iostream>
template<typename Float, int N>
class log_sum {
static_assert(N > 0, "N must be positive");
def unary(symbol, priority):
# XXX: BRAIN DAMAGE HAZARD AHEAD
# Consider prioritize's argument: what's it for?
# Isn't it expected to be a number?
# How dare it work and work correctly?
# Turns out, Python mixed-type comparison semantics are exploited in an
# awkward way. Python specifies that when no other rules apply, e.g. no
# overridden comparison magic-methods on any side, it falls back to
# comparing both sides' type names.
# One could grep CPython sources for `default_3way_compare' function that
#define in(name) freopen(#name ".in", "r", stdin)
#ifdef DEBUG
# define out(name)
# define debug(f, args...) printf("[DEBUG] " f "\n", ##args)
#else
# define out(name) freopen(#name ".out", "w", stdout)
# define debug(...)
#endif
-module(ctree).
-export([merge/2, split/2, add/2, add/3, remove/2, flatten/1, random/1, ordered/1, fromlist/1, remove_list/2, depth/1]).
% null / {Key, Param, Left, Right}
% Объединяет 2 дерева (любой элемент левого меньше любого элемента правого(
merge(null, B) -> B;
merge(A, null) -> A;
merge(A, B) ->
{A_key, A_param, A_left, A_right} = A,
@borman
borman / ctree.erl
Created December 15, 2009 20:33
Реализация декартова дерева на erlang. Версия на записях.
-module(ctree).
-export([merge/2, split/2, add/2, add/3, remove/2, flatten/1, random/1, ordered/1, fromlist/1, remove_list/2, depth/1]).
% null / {Key, Param, Left, Right}
-record(cnode, {key, param, left, right}).
%% Объединяет 2 дерева (любой элемент левого меньше любого элемента правого)
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <time.h>
#include <sys/types.h>
using namespace std;
@borman
borman / control-inversion.lua
Created April 10, 2012 17:15
Control flow inversion (async push -> sync pull) via coroutines
-- Coroutine wrappers
function expect (token)
local this = coroutine.running()
return coroutine.yield(token, this)
end
function start (stream)
return coroutine.create(stream)
end
@borman
borman / a.hs
Created April 15, 2012 20:03
Code Jam 2012 Qualification
import qualified Data.Map as M
subst = [('a','y'),('b','n'),
('c','f'),('d','i'),
('e','c'),('f','w'),
('g','l'),('h','b'),
('i','k'),('j','u'),
('k','o'),('l','m'),
('m','x'),('n','s'),
('o','e'),('p','v'),