Skip to content

Instantly share code, notes, and snippets.

View oitee's full-sized avatar

Otee oitee

View GitHub Profile
sudo docker run -it clojure:latest bash
@oitee
oitee / kv_store.js
Last active December 12, 2021 13:41
Database server that stores key-value pairs
export default class KVStore {
#data;
constructor() {
this.#data = new Map();
}
/**
* Given a key, returns its value
* @param {any} key
* @returns {any}
//======================================================================================
// List of each condition
//======================================================================================
/**
* Given a list of digits, returns true
* if the first and second digits equal to 24
* @param {Array} digits
* @returns Boolean
*/
@oitee
oitee / twirl_c4.puml
Created January 12, 2022 13:18
New Twirl Architecture
@startuml
title New Twirl Architecture
top to bottom direction
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4.puml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Context.puml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml
Person(User, "User", "Someone who wants to shorten links")
import * as nodeWorker from "worker_threads";
import * as db from "../src/db_connection.js";
import * as model from "../src/model.js";
db.poolStart();
let entityX = "X";
await model.insertEntity(entityX, "user");
const timeSlotX = {};
timeSlotX.from = Math.floor(
@oitee
oitee / power_set_using_tail_recursion.js
Created April 4, 2022 13:05
A JS implementation of powerSet, using tail recursion
//[...] =>[[], []]
// [] => [[]]
// [1] => [[], [1]]
// [1, 2] => [[], [1]] + [2] + [1, 2]
// [1, 2, 3] => [[], [1], [2], [1, 2]] + [3] + [1, 3] + [ 1, 2] + [1, 2, 3]
function powerSet(arr) {
if (arr.length === 0) {
(ns scratch.read-csv
(:require [clojure.string :as string]))
(defn find-val [s key]
(let [s-coll (string/split s key)
val-str (first (string/split (last s-coll) #"[,}]"))
val-cleaned (string/replace val-str #"[\"\\\:]" "")]
val-cleaned))
(defn extract-all-vals [s]
(defn middleware-fn
[handler-fn]
(fn [request]
;; operations on the request:
;; to create a `new-request`
;; or to simply log etc
(let [new-response (handler-fn new-request)]
;; operations on the `new-response`:
;; to create a `new-and-modified-response`
;; or to simply log etc
;; curl -d 'id="1234"' -X POST 'http://localhost:65535/?name=otee'
(defn handler-that-needs-keyword-params
[{params :params}]
;; the following will return this response map:
;; {:body "Hello otee your ID is: 1234" ...}
(ring.util.response/response "Hello" (:name params) " your ID is: " (:id params)))
(defn handler-that-supports-multiple-routes
[{:keys [uri request-method] :as request}]
request
(cond
(and (= uri "/contact")
(= request-method :get))
{:status 200
:headers {}
:body "Contact us at [email protected]"}