Skip to content

Instantly share code, notes, and snippets.

View oitee's full-sized avatar

Otee oitee

View GitHub Profile
(require '[ring.middleware.params :as rmp]
'[ring.middleware.keyword-params :as rmkp])
(defn handler-that-needs-keyword-params
[{params :params}]
(ring.util.response/response "Hello" (:name params) " your ID is: " (:id params)))
(rmp/wrap-params
(rmkp/wrap-keyword-params handler-that-needs-keyword-params))
;; => new handler function with the combined functionality of
(require '[compojure.route :as route]
'[compojure.core :refer [defroutes GET POST PUT DELETE ANY]]
'[ring.adapter.jetty :refer [run-jetty]]
'[ring.middleware.keyword-params :as rmkp]
'[ring.middleware.params :as rmp])
(defroutes app-routes
(POST "/submit" request (handler-that-needs-params request))
(GET "/submit" request handler-that-needs-params)
(route/not-found (str "404!")))
(require '[compojure.core :refer [defroutes GET]]
'[ring.adapter.jetty :refer [run-jetty]])
(defroutes app
(GET "/" request (str "Hello World! This is your URI: " (:uri request)))
(GET "/:name" [name] (str "Hello, " name)))
(run-jetty app {:port 8080})
(require '[compojure.core :refer [GET]]
'[ring.adapter.jetty :refer [run-jetty]])
(run-jetty
(GET "/" request (str "Hello World! This is your uri: " (:uri
request)))
{:port 8080
:join? false})
(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]"}
;; 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 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
(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]
@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) {
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(