This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.actors.Actor | |
import scala.actors.Actor._ | |
case object Ping | |
case object Pong | |
case object Stop | |
class Ping(count: Int, pong: Actor) extends Actor { | |
def act() { | |
var pingsLeft = count - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% | |
%% Solve sleeping barber problem in most general case | |
%% Task description on Wikipedia: | |
%% http://en.wikipedia.org/wiki/Sleeping_barber_problem | |
%% | |
%% Additions to classic variant: | |
%% * many barbers | |
%% * many clients generators with random timeouts between clients | |
%% * calculation for total served clients | |
%% * random time for each client to make barber's job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% | |
%% Solve sleeping barber problem in most general case | |
%% Task description on Wikipedia: | |
%% http://en.wikipedia.org/wiki/Sleeping_barber_problem | |
%% | |
%% Additions to classic variant: | |
%% * many barbers | |
%% * many clients generators with random timeouts between clients | |
%% * calculation for total served clients | |
%% * random time for each client to make barber's job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% | |
%% Solve sleeping barber problem in most general case | |
%% Task description on Wikipedia: | |
%% http://en.wikipedia.org/wiki/Sleeping_barber_problem | |
%% | |
%% Additions to classic variant: | |
%% * many barbers | |
%% * many clients generators with random timeouts between clients | |
%% * calculation for total served clients | |
%% * random time for each client to make barber's job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
uniqSubstr :: String -> Int | |
uniqSubstr = sum . (map pair) . pairwise . sort . tails | |
where | |
pairwise l@(_:ht) = zip l ht | |
prefix pre post = length $ takeWhile (uncurry (==)) $ zip pre post | |
pair (pre, post) = length $ drop (prefix pre post) post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> (let (a=2, b=4) (a + b)) | |
6 | |
>>> (let (x=20, y=40, z=1) (x*y*z)) | |
800 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |