Skip to content

Instantly share code, notes, and snippets.

View kachayev's full-sized avatar
🇺🇦
Fighting for freedom

Oleksii Kachaiev kachayev

🇺🇦
Fighting for freedom
View GitHub Profile
#!/bin/sh
set -e
sudo -s
apt-get update
apt-get install openjdk-6-jre openjdk-6-jdk mailtools git nginx build-essential -y
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
apt-get update
apt-get install jenkins -y
# python 2+
from itertools import takewhile, ifilter, izip, tee, starmap, chain
def uniq_substrings(origin):
suffixes = chain([""], sorted(tails(origin)))
return sum(starmap(suffix, pairwise(suffixes)))
def pairwise(iterable):
a, b = tee(iterable)
next(b, None)
# python 2.7+
from itertools import dropwhile, tee, izip
def repeatfunc(f, zero):
curr = zero
while 1:
yield curr
curr = f(curr)
def pairwise(origin):
@kachayev
kachayev / let.py
Created April 3, 2013 15:43
Can you guess how it's possible? (yes, this is python)
>>> (let (a=2, b=4) (a + b))
6
>>> (let (x=20, y=40, z=1) (x*y*z))
800
# python 2.7+
class Node(object):
def __init__(self, value, left, right):
self.value = value
self.left = left
self.right = right
def __iter__(self):
yield self.value
$ mkdir p1
$ cd p1/
$ rebar create-app appid=hotdo
$ ls
$ mkdir deps
$ touch rebar.config
$ # feeling rebar config file
$ wget -O rebar.config https://gist.github.com/kachayev/5657307/raw/fb9b0cd0d62e053efe54774bf2033e6e651c6622/hotdo.rebar.config
$ rebar get-deps
$ tree -L 2
## More infromation about SkipList data structure one can find:
## on Wikipedia http://en.wikipedia.org/wiki/Skip_list
## on Stackoverflow http://stackoverflow.com/questions/256511/skip-list-vs-binary-tree
from math import log
from random import randint, random
class SkipNode(object):
__slots__ = "value", "next"
@kachayev
kachayev / closest.py
Last active December 18, 2015 18:29
Simple visualization for finding closest points algorithm (2D variant)
import Tkinter as tk
import time
from operator import itemgetter
from math import sqrt
from random import randint
from Queue import Queue
from threading import Thread
def vdist(q, (x1,y1), (x2,y2)):
@kachayev
kachayev / pairing_heap.erl
Created July 9, 2013 15:30
Pairing heap data structure implementation in Erlang
%% Pairing Heap implementation
%% more information on wiki:
%% http://en.wikipedia.org/wiki/Pairing_heap
%% pq :: {pq, heap(), int()}
%% heap :: nil | {Item, [heap()]}
%% =============================
%% API
%% =============================
@kachayev
kachayev / LCA.py
Created July 17, 2013 19:04
Solve LCA taks with binary path method
## Solve LCA taks with binary path method
## Complexity is <O(NlogN), O(logN)>
tree = {
0: [1,2],
1: [3,4,5],
2: [6,7,8,9],
3: [10,11,12,13],
4: [14,15],
5: [16,17,18,19,20],