Skip to content

Instantly share code, notes, and snippets.

@afiodorov
afiodorov / .zshrc
Last active May 1, 2024 20:37
.zshrc snippets
function find_and_activate_venv() {
current_dir=$PWD
while [ "$current_dir" != "/" ]; do
if [ -d "$current_dir/.venv" ]; then
source "$current_dir/.venv/bin/activate"
return
fi
current_dir=$(dirname "$current_dir")
done
@afiodorov
afiodorov / main.py
Created April 5, 2024 14:15
jq_filters
#!/usr/bin/env python3
import argparse
import json
import sys
def jq_filters(d, path=None, text_limit=None):
"""
Returns all jq filters for the json.
"""
@afiodorov
afiodorov / lambda.py
Last active December 25, 2023 08:32
telegram_bot_aws_lambda
import os
import json
import logging
from urllib import request
from datetime import datetime, timezone
from dataclasses import dataclass
import boto3
from boto3.dynamodb.conditions import Key
@afiodorov
afiodorov / 17.py
Last active December 17, 2023 14:26
advent of code 2023 day 17 a* algo
import pandas as pd
from queue import PriorityQueue
from dataclasses import dataclass
from functools import cache
grid = pd.read_csv("./data/17.txt", names=[0], dtype='str').apply(lambda x: pd.Series(list(x[0])), axis=1).astype(int)
directions = [(0, 1), (1, 0), (-1, 0), (0, -1)]
@dataclass(frozen=True, order=True)
class NodeState:
@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:
@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
#!/usr/bin/env python3
import psutil
import time
if __name__ == "__main__":
while True:
procs = []
for proc in psutil.process_iter():
#!/usr/bin/env python3
import os
import openai
import argparse
import sys
openai.api_key = os.getenv("OPENAI_API_KEY")
@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
@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