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 |
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
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
# 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
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
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 FDManager: | |
def register_read(self, file_descriptor, callback): | |
# ... | |
def register_write(self, file_descriptor, callback): | |
# ... | |
def register_error(self, file_descriptor, callback): | |
# ... |
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 SendText(IOBase): | |
def __init__(self, fd, text=b"Hello!"): | |
self.fd = fd | |
self.text = text | |
def register(self, fdmanager): | |
fdmanager.register_write(self.fs, self.write) | |
def write(self): | |
os.write(self.fd, self.text) |
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 SendText(IOBase): | |
def __init__(self, fd, text=None): | |
self.fd = fd | |
self.text = text | |
if not self.text: | |
self.text = lambda: b"Hello!" | |
def register(self, fdmanager): | |
fdmanager.register_write(self.fs, self.write) |
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
login_action = Write('LOGIN') >> \ | |
Read('login') >> \ | |
Write(lambda v: 'HELLO %s' % v['login']) |
OlderNewer