This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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!"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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]"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//[...] =>[[], []] | |
// [] => [[]] | |
// [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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
NewerOlder