Skip to content

Instantly share code, notes, and snippets.

from urllib.request import quote
import urllib3
from lxml import etree
http = urllib3.PoolManager()
def getFriends(uname):
r = http.request('GET', 'http://juick.com/%s/friends' % quote(uname))
t = etree.HTML(r.data)
friends = t.xpath('/html/body/div[@id="wrapper"]/div[@id="content"]/p/a[@class="p16"]/text()')
@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'),
@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
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <time.h>
#include <sys/types.h>
using namespace std;
@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 дерева (любой элемент левого меньше любого элемента правого)
-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,
#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