Skip to content

Instantly share code, notes, and snippets.

View ninenine's full-sized avatar

Davis Wainaina ninenine

View GitHub Profile
@ninenine
ninenine / chat.py
Created May 1, 2024 20:37
UDP chat in python
import socket
import threading
from typing import List, Tuple
class ChatApp:
def __init__(self, port: int = 5555):
self.clients: List[Tuple[str, int]] = [] # Store client addresses
self.client_socket: socket.socket = None
self.server_socket: socket.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@ninenine
ninenine / black_scholes.py
Created February 29, 2024 19:04
Option Pricing with the Black–Scholes Model and Python
import asyncio
import logging
from typing import Literal
import yfinance as yf
import numpy as np
from scipy.stats import norm
import coloredlogs
from concurrent.futures import ThreadPoolExecutor
# Define a custom logging format
@ninenine
ninenine / MaybeMonadFlow.md
Last active February 9, 2024 11:17
A simple monad-like structure, focusing on the essence of monads.

Maybe Monad Flow in C

This Mermaid diagram illustrates the flow of a simple "Maybe" monad implementation in C.

flowchart TB
    start([Start]) --> createJust{Is it Just?}
    createJust -- Yes --> justValue[("Just (Value 🍰)")]
    createJust -- No --> nothingValue[("Nothing (😞)")]
@ninenine
ninenine / xkcd.py
Last active January 14, 2018 20:22
xkcd Async Downloader
import asyncio
import pathlib
import os
import logging
import aiohttp
import uvloop
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
@ninenine
ninenine / README.md
Created March 11, 2017 05:27
2017 03-10 All daily_driver_report

README is empty

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ninenine
ninenine / pr5_1900_2012.csv
Last active March 4, 2017 00:22
pr5_1900_2012.csv
Rainfall Year Month
17.24612 1901 1
43.78793 1901 2
67.1556 1901 3
155.89095 1901 4
72.05905 1901 5
23.200863 1901 6
25.02026 1901 7
14.9340515 1901 8
23.014225 1901 9
@ninenine
ninenine / bash_word_cloud.py
Last active February 20, 2017 09:57
Bash History Word Cloud
#!/usr/bin/env python
import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
data = pd.read_table('~/.bash_history', header = None, names=["CMD"])
exclude_words = []
exclude_words.extend(STOPWORDS)
@ninenine
ninenine / download_paper.py
Last active February 20, 2018 05:26
Download Kenyan Daily Nation and Business Daily
#!/usr/bin/env python
import urllib2
from datetime import date
def main():
today = date.today()
suffix = getDateSuffix(today)
fdate = "%s %s%s %s" % (today.strftime('%b'),today.strftime('%d').lstrip('0'),suffix,today.strftime('%Y'))
print("Downloading Daily Nation...")
@ninenine
ninenine / README.md
Created August 18, 2014 12:30
kcsetop

README is empty