Skip to content

Instantly share code, notes, and snippets.

View sznurek's full-sized avatar

Łukasz Dąbek sznurek

View GitHub Profile
@sznurek
sznurek / async.py
Created July 26, 2012 14:59
Third try
def auth(login, password):
return login == "1" and password == "test"
login_action = Write('LOGIN') >> \
Read('login') >> \
Write('PASS') >> \
Read('PASS') >> \
Guard(lambda v: auth(v['login'], v['pass']) >> \
Write('OK')
@sznurek
sznurek / async.py
Created July 26, 2012 14:53
Second try
class Authenticator:
def __init__(self, sock):
self.sock = sock
self.login = None
self.pass = None
self.to_send = "LOGIN"
self.to_read = None
def on_write(self):
if self.to_send == "LOGIN":
@sznurek
sznurek / async.py
Created July 26, 2012 14:47
First try
# methods on_read and on_write was called when select confirmed that socket is ready to read from / write to
STATE_SEND_LOGIN = 1
STATE_RECEIVE_LOGIN = 2
STATE_SEND_PASS = 3
STATE_RECEIVE_PASS = 4
STATE_SEND_OK = 5
class Authenticator:
def __init__(self, sock):
@sznurek
sznurek / worker.py
Created July 26, 2012 14:25
Example worker
import sys
for line in sys.stdin.readlines():
parts = line.split()
uid = int(parts[0])
msg = ' '.join(parts[1:])
print("%d Hello user %d! Message: %s" % (uid, uid, msg))
@sznurek
sznurek / gist:3171575
Created July 24, 2012 18:09
PHP class constants - late binding
<?php
class First {
const X = 1;
const Y = self::X;
}
class Second extends First {
const X = 2;
}
nfather :: Person -> Int -> Maybe Person
nfather p n = do
a <- father p
b <- father a
-- ... repeat n times
father xyz