Skip to content

Instantly share code, notes, and snippets.

View usametov's full-sized avatar

Ulan Sametov usametov

  • Asta Nova Enterprise Solutions
View GitHub Profile
@usametov
usametov / recursive_splitter.clj
Created July 16, 2023 06:06
clojure implementation of LangChain's recursive splitter
(ns astanova.recursive-splitter
"implementation of LangChain's recursive code splitter"
(:require [clojure.string :as s]))
(defonce java-splitters [#"class " #"public " #"protected "
#"private " #"static " #"if"
#"for" #"while" #"switch"
#"case" #"\r\n" #"\t\t"])
(defonce js-splitters [#"function " #"const " #"let "
@usametov
usametov / cosine-similarity.clj
Last active July 8, 2023 03:19
cosine-similarity
(:require [tech.v3.datatype.functional :as func])
(defn cosine-similarity
[v1 v2]
(/ (func/dot-product v1 v2)
(Math/sqrt (* (func/magnitude-squared v1) (func/magnitude-squared v2)))))
;; Maybe, we don't really need to divide by magnitudes product.
;; it looks like embeddings coming from openai are already normalized.
@usametov
usametov / audio_recorder.html
Last active June 13, 2023 02:58
Simple audio recording demo
<!DOCYTPE html>
<html>
<head>
<title>Simple audio recording demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<input type="button" class="btn" value="click and hold to record" />
<script type="text/javascript">
@usametov
usametov / gist:ec6c42de3424a4fc595202d9846bd7d6
Created June 11, 2023 01:41 — forked from scottdw/gist:26e2491e53ebc28649f5
Discrete fourier transform clojure and jtransforms
(ns scottdw.feip.core
(:import [java.awt Image]
[java.awt.image BufferedImage]
[org.imgscalr Scalr]
[org.jtransforms.fft DoubleFFT_2D RealFFTUtils_2D])
(:require [mikera.image.core :as img]
[mikera.image.colours :as ic]
[clojure.core.matrix :as mat]))
(defn gen-p-img []
@usametov
usametov / search-client.clj
Last active July 6, 2023 17:28
babashka search
#!/usr/bin/env bb
(require '[babashka.process :refer [shell process exec]])
(require '[clojure.string :as s])
(require '[cheshire.core :as json])
(import 'java.time.format.DateTimeFormatter
'java.time.LocalDateTime)
(defn search
[q offset]
(->
@usametov
usametov / sparql-client.clj
Created June 4, 2023 17:27
babashka bio2rdf client
#!/usr/bin/env bb
(require '[babashka.curl :as curl])
(require '[clojure.string :as s])
(require '[cheshire.core :as json])
(defn query-variant-drug-links
[rsid]
(->
(curl/get
@usametov
usametov / prophet1.py
Last active June 4, 2023 19:44
prophet
import pandas as pd
import matplotlib.pyplot as plt
from fbprophet import Prophet
from datetime import datetime
import psycopg2
from sqlalchemy import create_engine
#Read the Parquet file
#df = pd.read_parquet('./BTCUSD-dec12-may21-volume-bars.parquet')
@usametov
usametov / clj-playground.clj
Created January 30, 2023 16:26
clj-playground
(ns astanova.clj-playground
(:require [clojure.tools.deps.alpha.repl :refer [add-libs]]))
(comment
;; alternatevly, we can require add-libs in comment
;; (require '[clojure.tools.deps.alpha.repl :refer [add-libs]])
(add-libs '{hiccup/hiccup {:mvn/version "2.0.0-alpha2"}})
(require '[hiccup.core :as hiccup])
@usametov
usametov / newton-method.clj
Last active October 16, 2022 18:12
newton method and secant method
(defn newt [x0 f df n] (take n (iterate #(- % (double (/ (f %) (df %)))) x0)))
;;call it like this:
;;(newt 1 #(- (* % %) 2.0) #(* 2.0 %) 10.0)
;; secant method
(defn secant
[x0 x1 f n]
(letfn [(fn_ [x_n-1 x_n-2 f_]
(let [x_n (- x_n-1 (/ (* (f_ x_n-1) (- x_n-1 x_n-2))
@usametov
usametov / get-pubmed.clj
Last active July 7, 2022 11:16 — forked from borkdude/scrape_tables.clj
get list of pubmed baseline files
(ns scrape
(:require [babashka.pods :as pods]
[clojure.walk :as walk]))
(pods/load-pod 'retrogradeorbit/bootleg "0.1.9")
(require '[babashka.curl :as curl])
(def pubmed-html (:body (curl/get "https://ftp.ncbi.nlm.nih.gov/pubmed/baseline/")))