Skip to content

Instantly share code, notes, and snippets.

View homedirectory's full-sized avatar

homedirectory

View GitHub Profile
@homedirectory
homedirectory / rag.py
Created May 4, 2024 10:10
LangChain GitLoader example
import getpass
import os
import bs4
from langchain import hub
# from langchain_community.document_loaders import WebBaseLoader
from langchain_chroma import Chroma
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter
Service used for data extraction from unstructured HTML: https://www.kadoa.com
Data source: http://clhs.lisp.se/Body/f_map.htm
Resulting JSON:
[
{
"id": "661a5232c700f85cf0e07c91",
"data": {
@homedirectory
homedirectory / multimodal.py
Created March 30, 2024 12:00
Example of multimodal models from Hugging Face
import gradio as gr
from PIL import Image
import torch
from transformers import AutoProcessor, AutoModelForCausalLM
processor = AutoProcessor.from_pretrained("microsoft/git-base-textvqa")
model = AutoModelForCausalLM.from_pretrained("microsoft/git-base-textvqa", cache_dir='/tmp')
def doit(image1, image2, question):
@homedirectory
homedirectory / SizedList.java
Last active March 29, 2024 16:57
Encoding list length in Java types
/**
* @param <T> the type of elements in the list
*/
public sealed interface SizedList<T, LENGTH extends Nat> {
/**
* The empty list.
*/
final class Nil<T> implements SizedList<T, Zero> {
private static final Nil<?> NIL = new Nil<>();
@homedirectory
homedirectory / index.html
Last active March 23, 2024 11:15
IRC parsing visualisation generated by ChatGPT
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IRC Message Parser</title>
<style>
body {
font-family: Arial, sans-serif;
}
@homedirectory
homedirectory / cheatsheet.md
Last active September 29, 2022 12:31
vimwiki cheatsheet
@homedirectory
homedirectory / bash.md
Created August 17, 2022 10:29
Bash Shortcuts

Bash Shortcuts

visual cheetsheet

Moving

command description
ctrl + a Goto BEGINNING of command line
@homedirectory
homedirectory / hpmor_primes.py
Created July 24, 2022 17:31
HPMOR - Time-Turner prime numbers experiment
# Chapter 17 of HPMOR
# The experiment with prime numbers
# python doesn't support tail recursion, so do this with a while loop
def run(x, y):
while True:
# paper 2 is blank
if x is None and y is None:
x, y = 101, 101
@homedirectory
homedirectory / snip.py
Last active September 8, 2021 15:37
snip long values from HTTP requests - URL parameters, Cookie values, Authorization tokens
MAX_LENGTH = 12
def snip(request):
"""
request - str
"""
snipped_req = ""
lines = list(filter(lambda l: len(l) > 0, request.split('\n')))
(4) Another (and a more universal approach) to get rid of the dependence on $\theta$ in (2) is to estimate $s$ via the sample
standard error and use approximation of $\bar{X}$ via Student t-distribution; see details in Ross textbook on statistics or in the lecture notes
```{r}
for (n in c(100, 1000, 10000)) {
cat("FOR SAMPLE SIZE = ", n, ":\n")
sample_exp = rexp(n*m, lambda) # creating a single sample of exponential distribution
sample_means = colMeans(matrix(sample_exp, nrow=n)) # creating a sample of sample means