This file contains hidden or 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
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') |
This file contains hidden or 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
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": |
This file contains hidden or 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
# 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): |
This file contains hidden or 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 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)) |
This file contains hidden or 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
<?php | |
class First { | |
const X = 1; | |
const Y = self::X; | |
} | |
class Second extends First { | |
const X = 2; | |
} |
This file contains hidden or 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
nfather :: Person -> Int -> Maybe Person | |
nfather p n = do | |
a <- father p | |
b <- father a | |
-- ... repeat n times | |
father xyz |
NewerOlder