Skip to content

Instantly share code, notes, and snippets.

@holyjak
holyjak / http-server.bb
Last active September 6, 2024 15:17
Babashka HTTP server for serving static files, similar to `python -m http.server` but more flexible :)
#!/usr/bin/env bb
#_" -*- mode: clojure; -*-"
;; Based on https://github.com/babashka/babashka/blob/master/examples/image_viewer.clj
(ns http-server
(:require [babashka.fs :as fs]
[clojure.java.browse :as browse]
[clojure.string :as str]
[clojure.tools.cli :refer [parse-opts]]
[org.httpkit.server :as server]
@baskeboler
baskeboler / clipboard.clj
Last active April 11, 2021 01:21 — forked from brake/clipboard.clj
Write pretty printed Clojure data structures to the clipboard
(ns clipboard.core
(:require [fipp.edn :as fipp])
(:import (java.awt.datatransfer DataFlavor Transferable StringSelection)
(java.awt Toolkit)
(java.io StringWriter))
(defn get-clipboard
"get system clipboard"
[]
(-> (Toolkit/getDefaultToolkit)
@mfikes
mfikes / keys-vals.md
Last active November 23, 2020 13:27

The following works in Clojure:

(keys (filter (comp odd? val) {:a 1 :b 2 :c 3}))

The docstrings for keys and vals don't indicate that you can do this. Is this accidential or intentional?

I vaguely recall Alex Miller indicating at some point that this capability was deemed useful and is intentionally allowed. Yes, this is an appeal to authority, but nevertheless, it makes a fairly convincing argument.

@czan
czan / convert_to_openapi.clj
Last active August 19, 2022 06:00
Reitit OpenAPI3 hack
(ns ^{:doc "Convert Swagger 2 specs to OpenAPI 3 specs
We're using the standard reitit mechanisms to produce a Swagger spec,
but we'd much rather be using an OpenAPI 3 spec. This namespace does a
conversion for us, until the functionality lands in reitit."}
convert-to-openapi
(:require [camel-snake-kebab.core :refer [->PascalCase]]
[clojure.set :refer [rename-keys]]
[clojure.string :as str]
[clojure.walk :as walk]
@titogarcia
titogarcia / token_refresh_example.clj
Last active February 24, 2023 20:53
Example on how to implement an OAuth token store in Clojure
;; https://gist.github.com/titogarcia/4f09bcc5fa38fbdc1076954b9a99a8fc
(ns token-refresh-example
(:require [clojure.string :refer [ends-with?]]
[clj-http.client :as http])
(:import [java.time Instant]
[java.time.temporal ChronoUnit]))
;;;; Logging implementation for exercising these tests
@edwintye
edwintye / pipeline.gdsl
Last active September 26, 2024 23:58 — forked from ggarcia24/pipeline.gdsl
GDSL supporting pipeline declarative
package main.resources
//The global script scope
def ctx = context(scope: scriptScope())
//What things can be on the script scope
contributor(ctx) {
method(name: 'pipeline', type: 'Object', params: [body: Closure])
property(name: 'params', type: 'org.jenkinsci.plugins.workflow.cps.ParamsVariable')
property(name: 'env', type: 'org.jenkinsci.plugins.workflow.cps.EnvActionImpl.Binder')
@yogthos
yogthos / clojure-beginner.md
Last active April 18, 2025 02:43
Clojure beginner resources

Introductory resources

@ian-moore
ian-moore / dev_server.clj
Created November 27, 2019 20:10
shadow-cljs dev http server with conditional proxy requests
(ns my-shadow-app.dev-server
(:require [clj-http.client :as client]
[clojure.string :as string]
[shadow.http.push-state :as push-state])
(:import [org.apache.http NoHttpResponseException]))
(defn handler
[{:keys [uri http-config body headers request-method] :as request}]
(if-not (string/starts-with? uri "/api")
(push-state/handle request)
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active April 27, 2025 09:14
set -e, -u, -o, -x pipefail explanation
(require '[clojure.string :as s])
(declare print-maze)
;; Maze GENERATION
(defn create-grid [rows cols]
(vec (repeat rows (vec (repeat cols #{})))))
(defn north-of [[row col]] [(dec row) col])
(defn south-of [[row col]] [(inc row) col])