Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
/***************************************************************************** | |
* QuantCup 1: Price-Time Matching Engine | |
* | |
* Submitted by: voyager | |
* | |
* Design Overview: | |
* In this implementation, the limit order book is represented using | |
* a flat linear array (pricePoints), indexed by the numeric price value. | |
* Each entry in this array corresponds to a specific price point and holds | |
* an instance of struct pricePoint. This data structure maintains a list |
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
from random import random | |
def generate_infinite_random_nos(): | |
yield random() | |
yield from generate_infinite_random_nos() | |
#https://eddmann.com/posts/merge-sort-in-scala-using-tail-recursion-and-streams/ |
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 asyncio | |
import random | |
async def handle_echo(reader, writer): | |
while True: | |
data = await reader.readline() | |
message = data.decode() | |
addr = writer.get_extra_info('peername') | |
print(f"Received {message!r} from {addr!r}") | |
message = f'pong{random.randint(0,10)}\n' |
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 asyncio | |
async def client(message): | |
message = message + '\n' + message + '\n' | |
reader, writer = await asyncio.open_connection( | |
'127.0.0.1', 8888) | |
print(f'Send: {message!r}') | |
writer.write(message.encode()) | |
while True: |
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
from aioredis.pubsub import Receiver | |
REDIS_URL = 'localhost' | |
REDIS_PORT = 6379 | |
async def redis_relay(websocket): | |
conn = aioredis.create_connection((REDIS_URL, REDIS_PORT)) | |
receiver = Receiver() | |
connection.execute_pubsub('subscribe', receiver.channel(‘updates’)) | |
while (await receiver.wait_message()): |
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
async def beat1(websocket): | |
while True: | |
await asyncio.sleep(1) | |
await websocket.send('💚') | |
async def beat2(websocket): | |
while True: | |
await asyncio.sleep(2) | |
await websocket.send('💓') | |
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
async def beat1(websocket): | |
while True: | |
await asyncio.sleep(1) | |
await websocket.send('💚') | |
async def beat2(websocket): | |
while True: | |
await asyncio.sleep(2) | |
await websocket.send('💓') |
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 asyncio | |
import websockets | |
async def heartbeat(websocket): | |
while True: | |
await asyncio.sleep(1) | |
await websocket.send('💚') | |
async def ws_handler(websocket, path): |
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 asyncio | |
import websockets | |
async def ws_handler(websocket, path): | |
async for message in websocket: | |
print(message) | |
if message == 'ping': | |
await websocket.send('pong') | |
NewerOlder