Skip to content

Instantly share code, notes, and snippets.

View ankitml's full-sized avatar
🎯
Focusing

Ankit ankitml

🎯
Focusing
View GitHub Profile
@ankitml
ankitml / presenter.ipynb
Last active May 30, 2021 00:12
Presenter.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ankitml
ankitml / engine.c
Created February 14, 2019 19:35 — forked from druska/engine.c
Quant Cup 1's winning order book implementation
/*****************************************************************************
* 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
@ankitml
ankitml / trampoline.py
Created February 14, 2019 14:54
infinite recursion with generators experiments in python
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/
@ankitml
ankitml / ipctcp_server.py
Created February 14, 2019 14:49
IPC through tcp in python (server)
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'
@ankitml
ankitml / ipctcp_client.py
Created February 14, 2019 14:48
client for ipc communication through tcp port
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:
@ankitml
ankitml / ws5.py
Created February 6, 2019 22:13
Websocet tutorial 5: Redis relay
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()):
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('💓')
@ankitml
ankitml / ws3.py
Created February 6, 2019 21:21
Websockets Tutorial 3 - Two simultaneous heart beats
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('💓')
@ankitml
ankitml / ws2.py
Created February 6, 2019 21:17
Websockets Tutorial 2 - Heart Beat
import asyncio
import websockets
async def heartbeat(websocket):
while True:
await asyncio.sleep(1)
await websocket.send('💚')
async def ws_handler(websocket, path):
@ankitml
ankitml / ws1.py
Last active February 6, 2019 20:02
Websockets Tutorial 1
import asyncio
import websockets
async def ws_handler(websocket, path):
async for message in websocket:
print(message)
if message == 'ping':
await websocket.send('pong')