Skip to content

Instantly share code, notes, and snippets.

View jacoobes's full-sized avatar
☝️
simplicity is the ultimate sophistication

Jacob Nguyen jacoobes

☝️
simplicity is the ultimate sophistication
View GitHub Profile
@jacoobes
jacoobes / edn.js
Created December 23, 2024 19:24
Incomplete but browser compatible edn parsr
class EDNParser {
constructor(ednString) {
this.edn = ednString;
this.index = 0;
}
parse() {
this.skipWhitespace();
const element = this.readElement();
this.skipWhitespace();
(ns y2024.d5
(:require [clojure.test :as t :refer [deftest]]
[clojure.string :as string]))
(def sample-data-1
"47|53
97|13
97|61
97|47
75|29
@jacoobes
jacoobes / routebuilder.ts
Created August 8, 2024 18:22
routebuilder ( i forgot why i meade this)
import { readdir, stat } from 'fs/promises';
import { basename, join, parse, dirname } from 'path';
import assert from 'assert';
export const fmtFileName = (fileName: string) => parse(fileName).name;
export const getfilename = (path: string) => fmtFileName(basename(path));
@jacoobes
jacoobes / lev.clj
Created June 22, 2024 04:14
Levensthein Distance
(defn lev [a b]
(let [[hda & rsta] a cta (count a)
[hdb & rstb] b ctb (count b)]
(cond (zero? ctb) cta
(zero? cta) ctb
(= hda hdb) (lev rsta rstb)
:else (inc (min (lev rsta b) (lev a rstb) (lev rsta rstb))))))
@jacoobes
jacoobes / extract.clj
Created May 30, 2024 19:29
extra jsdoc from text using babashka
(defn alpha? [ch] (Character/isLetter ch))
(defn >>alpha [in] (apply str (take-while alpha? in)))
(defn >>line [in] (apply str (take-while #(not= % \newline) in)))
(defn str->jsdoc [string]
(when (str/starts-with? string "/**")
(loop [[fst & rest] (subs string 3) sol true;start-of-line
res []]
(when (some? fst)
@jacoobes
jacoobes / main.clj
Created January 17, 2024 05:16
sqlite setup and clojure
; deps.edn
;{:paths ["src"]
;:deps {io.pedestal/pedestal.service {:mvn/version "0.5.9"}
; io.pedestal/pedestal.route {:mvn/version "0.5.9"}
; io.pedestal/pedestal.immutant {:mvn/version "0.5.9"}
; org.slf4j/slf4j-simple {:mvn/version "1.7.32"}
; environ/environ {:mvn/version "1.2.0"}
; org.xerial/sqlite-jdbc {:mvn/version "3.7.2" }
; com.github.seancorfield/next.jdbc {:mvn/version "1.3.909"}
; com.github.seancorfield/honeysql {:mvn/version "2.5.1103"}
function publishedCommandModule(publishOptions: PublishOptions) {
return (
execute : (ctx: Context, args: ['slash', SlashOptions]) => unknown
) => commandModule({
type: CommandType.Slash,
plugins: [
publish(publishOptions)
],
execute
})
@jacoobes
jacoobes / paginator.ts
Last active July 28, 2022 15:58
discord.js paginator < 50 lines
export function Paginate() {
const __embeds = [] as EmbedBuilder[];
let cur = 0;
let traverser: [ButtonBuilder, ButtonBuilder];
let message : Message;
return {
add(...embeds : EmbedBuilder[]) {
__embeds.push(...embeds)
return this;
},
@jacoobes
jacoobes / pubsub.ts
Created July 15, 2022 00:19
pub sub for events
class Channel<T> {
private subscribers : Subscriber<T>[] = [];
private values : T[] = [];
public emit(value : T)
{
this.values.push(value);
}
public notify()
{
for(const sub of this.subscribers)
@jacoobes
jacoobes / parseTxt.ts
Last active April 9, 2022 08:04
Made a small dsl for parsing txt files
//an example txt fiie
const text =
`uuid=00000000-0000-0000-0009-01f2082a2089
lastOnline=1649034318641
registered=1648920816719
joinedTownAt=0
isNPC=false
title=
surname=
friends=