Skip to content

Instantly share code, notes, and snippets.

@afiodorov
afiodorov / gist:6815066846bc303ec4f8
Last active December 4, 2015 14:26
Reading group on "The Elements of Statistical Learning" for aspiring Data Scientists
Dear all,
We are organising, starting Wednesday on the 2nd of December, a reading group on an introductory book for machine learning.
The book is called "The Elements of Statistical Learning" and is freely available online: http://statweb.stanford.edu/~tibs/ElemStatLearn/.
The book requires some basic background in Linear Algebra and Probability Theory usually covered in maths undergraduate courses.
The reading group will take place every Wednesday between 17:30 - 19:30 in X-Men Origins Seminar Room, Kathleen Lonsdale Building, 5 Gower Place.
#!/bin/bash
awk -F'\t' 'BEGIN {print "<head><meta charset="UTF-8"></head><body><table>"} {print "<tr><td>"$1"</td><td>"$2"</td></tr>"} END {print "</table></body>"}' MySpanish.txt > MySpanish.txt.html
@afiodorov
afiodorov / tictactoe.py
Created June 24, 2019 09:00
Basic tic tac toe
import numpy as np
class Board:
def __init__(self):
self.turn = 0
self.state = np.full((3, 3), "_")
def __str__(self):
r = f"{self.player()}'s turn\n{self.state}'"
if self.winner() is not None:
r += f"\nWinner: {self.winner()}"
# EC, Field are in http://afiodorov.github.io/2019/06/18/elliptic/
from dataclasses import dataclass
from random import randint
@dataclass
class Signature:
sig: int
pp: EC.Point
randomx: int
@afiodorov
afiodorov / main.go
Created February 4, 2020 21:56
Rolling median in go
package main
import (
"fmt"
"math"
"sort"
"time"
)
// Data holds Value & Time when value was observed
@afiodorov
afiodorov / cache.py
Last active January 5, 2024 08:25
cache output of a python function to disk
import pickle
from datetime import datetime, timedelta
from functools import wraps
from hashlib import sha224
from pathlib import Path
from time import time
from typing import Optional
#!/usr/bin/env python3
import os
import openai
import argparse
import sys
openai.api_key = os.getenv("OPENAI_API_KEY")
#!/usr/bin/env python3
import psutil
import time
if __name__ == "__main__":
while True:
procs = []
for proc in psutil.process_iter():
@afiodorov
afiodorov / instruction
Last active October 28, 2023 11:51
Run your own LLM & create an api endpoint for predictions
Docker Image : pytorch/pytorch
Image Runtype : jupyter_direc ssh_direc ssh_proxy
Environment : [["JUPYTER_DIR", "/"], ["-p 41654:41654", "1"]]
pip install torch bitsandbytes sentencepiece "protobuf<=3.20.2" git+https://github.com/huggingface/transformers flask python-dotenv Flask-HTTPAuth accelerate
!mv /opt/conda/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda116.so /opt/conda/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cpu.so
@afiodorov
afiodorov / proxy.py
Created November 29, 2023 22:39
Websocket proxy
import asyncio
import websockets
async def client_to_server(client, server):
async for message in client:
await server.send(message)
async def server_to_client(client, server):
async for message in server: