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
@kachayev
kachayev / gearman-install.sh
Created June 13, 2011 14:53
Shell/bash script for installing gearman server on debian-like linux
sudo bash
cd /usr/local/lib
wget http://launchpad.net/gearmand/trunk/0.18/+download/gearmand-0.18.tar.gz
tar -xvzf gearmand-0.18.tar.gz
cd gearmand-0.18/
apt-get install libboost-program-options-dev uuid-dev libevent-dev build-essential g++
./configure && sudo make && sudo make install
ldconfig
@kachayev
kachayev / shortcut.py
Created August 21, 2011 18:12
How to create amazing script for custom keyboard shortcut with Python
import sys
import os
import time
import errno
import xmlrpclib
import socket
class Package(object):
'''Install python packages with using setup.py install'''
@kachayev
kachayev / tic-tac-toe.py
Created November 22, 2011 23:50
Tornado demo application: TCP server to tic-tac-toe multiplayer game
"""Simple TCP server for playing Tic-Tac-Toe game.
Use Player-to-Player game mode based on naming auth.
No thoughts about distribution or pub/sub mode
(for monitoring or something like this). Just
basic functionality.
"""
import time
import logging
@kachayev
kachayev / go-channels-1-generator.go
Created July 16, 2012 19:42
Channels-driven concurrency with Go
// Channels-driven concurrency with Go
// Code examples from Rob Pike's talk on Google I/O 2012:
// http://www.youtube.com/watch?v=f6kdp27TYZs&feature=youtu.be
//
// Concurrency is the key to designing high performance network services.
// Go's concurrency primitives (goroutines and channels) provide a simple and efficient means
// of expressing concurrent execution. In this talk we see how tricky concurrency
// problems can be solved gracefully with simple Go code.
// (1) Generator: function that returns the channel
@kachayev
kachayev / clojure-channels-1-generator.clj
Last active October 7, 2015 09:57
Channels-driven concurrency with Clojure
;; Channels-driven concurrency with Clojure
;; Clojure variant for code examples from this gist:
;; https://gist.github.com/3124594
;; Primarily taken from Rob Pike's talk on Google I/O 2012:
;; http://www.youtube.com/watch?v=f6kdp27TYZs&feature=youtu.be
;;
;; Concurrency is the key to designing high performance network services.
;; Clojure provides several concurrency primitives, like futures/promises, atom, agent etc.
;; There is no implementation for "Go channels" in core, but we can use
;; 3rd-party library Lamina to do the same things.
@kachayev
kachayev / sleeping-barber-problem.clj
Last active August 21, 2017 23:10
Resolve "Sleeping barber problem" with Clojure
(def open-for-business? (atom true))
(def haircut-count (agent 0))
(def waiting-room (ref []))
(def waiting-room-size 3)
(defn open-shop [duration]
(do (Thread/sleep duration) (swap! open-for-business? not)))
(defn add-customers []
(future
@kachayev
kachayev / fp.py
Created October 30, 2012 20:38
Implement mapping data structure and "classes" using functions and lists
## Author: Alexey Kachayev
## Email: kachayev@gmail.com
## Talk: "Functional programming with Python", UA PyCon 2012
## URL: http://ua.pycon.org/static/talks/kachayev/index.html#/
###############################################
## Imitate dictionary functionality
###############################################
def dict_pair((key, value)):
@kachayev
kachayev / agents_VS_atoms.clj
Last active May 18, 2018 22:34
Clojure synchronous/asynchronous state changes
$ clj
Clojure 1.4.0
user=> ;; atoms - synchronous sharing state changes
user=> (def w (atom 0))
#'user/w
user=> (swap! w inc)
1
user=> @w
1
user=> (swap! w #(* % 100))
@kachayev
kachayev / barber.erl
Last active November 6, 2020 03:44
Solve "Sleeping Barber Problem" with Erlang (more about problem - http://en.wikipedia.org/wiki/Sleeping_barber_problem)
-module(barber).
-export([run/2, barber/1, clients/1, simulator/2]).
-define(CUT_DUTAION, 20).
run(RoomSize, Duration) ->
% create barber
BPid = spawn(?MODULE, barber, [?CUT_DUTAION]),
% run simulartor with barber PID
SPid = spawn(?MODULE, simulator, [BPid, RoomSize]),
@kachayev
kachayev / barber.go
Last active December 11, 2015 17:29
Solve "Sleeping Barber Problem" with Golang (more about problem - http://en.wikipedia.org/wiki/Sleeping_barber_problem)
package main
import (
"fmt"
"time"
"math/rand"
)
const (
CUTTING_TIME = 20