Skip to content

Instantly share code, notes, and snippets.

View shaunparker's full-sized avatar

Shaun Parker shaunparker

  • Lohi Labs
  • Denver, CO
View GitHub Profile
(ns guestbook
(:require [cheshire.core :as cheshire]
[hiccup2.core :as hiccup]
[clojure.string :as str]))
(require '[babashka.pods :as pods])
(pods/load-pod "./pod-babashka-postgresql")
(def db {:dbtype "postgresql"
:user "guestbook"
@cldwalker
cldwalker / spike-day-02-03-20.md
Last active December 29, 2023 04:52
GraalVM dive in Clojure at work

Spike

I looked into the state of GraalVM and Clojure and wrote some small work-related scripts.

GraalVM Build Tools

React Native + macOS + Clojurescript

image

Project Catalyst

Since the recent release of Catalina, macOS has shipped with the ability to allow iOS/iPAD apps to run on macOS without any modification via a featureset known as Project Catalyst.

This is exciting, as writing React Native + Clojurescript apps as a target for the desktop is much more compelling than a pure Electron app (imo).

@pjstadig
pjstadig / transducers.md
Last active June 8, 2021 13:22
The secret feature of transducers that no one talks about!

The Pledge

One thing that always made me a little sad about transducers was how map lost its ability to iterate multiple collections in parallel. This is actually my favorite feature of map. For example:

(map + (range 5) (range 5 10))
=> (5 7 9 11 13)

One somewhat practical use of this is if you want to compare two sequences, pairwise, using a comparator. Though I wish that every? took multiple collections, this is an adequate substitute:

@mtnygard
mtnygard / responses.clj
Last active July 16, 2019 20:16
Build Pedestal response maps for every standard HTTP status code.
(defn response
([status body]
{:status status
:headers {}
:body body}))
(defmacro http-status [code sym]
`(def ~sym (partial response ~code)))
(defmacro http-statuses [& pairs]
Run this to launch REPL
rlwrap clj -Srepro -Sdeps '{:deps {speculative {:mvn/version "0.0.3"} expound {:mvn/version "0.7.2"} org.clojure/test.check {:mvn/version "0.9.0"} org.clojure/clojurescript {:mvn/version "1.10.520"}}}' -e "(require '[expound.alpha :as expound] '[cljs.core.specs.alpha]) (set! clojure.spec.alpha/*explain-out* (expound/custom-printer {:print-specs? false :show-valid-values? true :theme :figwheel-theme}))" -m cljs.main -re node
Then run this in REPL
(require '[expound.alpha :as expound] '[cljs.core.specs.alpha] '[speculative.instrument :as i]) (i/instrument) (set! cljs.spec.alpha/*explain-out* (expound/custom-printer {:print-specs? false :show-valid-values? true :theme :figwheel-theme}))
@cgrand
cgrand / heredoc.clj
Last active March 6, 2021 17:16
An ugly hacky heredoc for Clojure
(defn heredoc []
(let [delim (.readLine *in*)]
(->> (repeatedly #(.readLine *in*))
(take-while #(not= delim %))
(interpose \newline)
(apply str))))
; The following lines are read (by the reader) as:
; "Look )(\"\\T\na here doc!\n"
#=(heredoc)"""
@mtnygard
mtnygard / README.md
Last active May 9, 2018 04:38
Create a dependency matrix of Clojure namespaces.

The dependency matrix shows the strength of coupling at a var-by-var level between namespaces.

If you pull the CSV output into a spreadsheet, the numbers in the cells show how many var->var dependencies there are between the namespaces.

If you want to just look at namespace->namespace dependencies (e.g., to create a visualization) then just consider any cell > 0 as a dependency.

@athos
athos / deps.edn
Last active June 21, 2023 00:15
Try on your terminal `clojure -Sdeps '{:deps {hello-clojure/hello-clojure {:git/url "https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202" :git/sha "099bdf7d565b2c35c1df601abf58514cc5276237"}}}' -M -m hello-clojure`
{:paths ["."]
:deps {clansi/clansi {:mvn/version "1.0.0"}}}
@halgari
halgari / gist:f431b2d1094e4ec1e933969969489854
Last active April 16, 2023 04:06
What I want from a Type System
The question was asked why I (as a programmer who prefers dynamic languages) don't consider static types "worth it". Here
is a short list of what I would need from a type system for it to be truely useful to me:
1) Full type inference. I would really prefer to be able to write:
(defn concat-names [person]
(assoc person :full-name (str (:first-name person)
(:second-name person))))
And have the compiler know that whatever type required and produced from this function was acceptible as long as the