Skip to content

Instantly share code, notes, and snippets.

View telekid's full-sized avatar
👨‍🚀

Jake telekid

👨‍🚀
View GitHub Profile
@leonoel
leonoel / animation.clj
Created October 8, 2023 13:16
animation in missionary
(ns animation
(:refer-clojure :exclude [cycle])
(:require [missionary.core :as m]))
;; A signal giving the current time in milliseconds.
;; On the browser, you may want to use an RAF-based clock instead.
(def <time
(->> (m/ap
(loop []
(m/amb nil
(defmacro return% [a]
`(fn return-fn# [success# error#]
#(try
(success# ~a)
(catch Throwable t#
(error# t#)))))
(defn bind% [m b]
(fn a [success error]
#(m (fn x [value] ((b value) success error)) error)))

Further Lisp compression tinkering. Basic idea: most languages optimize for sequence structure, which fits for procedural code:

Statement A modifies the environment
Statement B modifies the environment
Statement C uses the modified environment to produce value
...

But a more functional style tends to structure things as a nested recursive tree, with the right-most branch being the heaviest.

@holyjak
holyjak / oidc_client.clj
Last active April 25, 2024 16:39
A stateful CLI tool for getting access token from an OIDC provider
#!/usr/bin/env bb
(ns oidc-client
"Get end-user access token from an OIDC provider, caching the access/refresh token in an encrypted file. Code in https://babashka.org
Usage:
/path/to/oidc_client.clj
When there are no cached, valid tokens, it will open a browser with the OIDC provider login URL and start a HTTPS-enabled
callback server on localhost. Make sure that the resulting redirect_uri is registered with your provider.
(ns com.manigfeald.yield
(:require [clojure.tools.analyzer :as an]
[clojure.tools.analyzer.ast :as ast]
[clojure.tools.analyzer.env :as env]
[clojure.tools.analyzer.jvm :as an-jvm]
[clojure.tools.analyzer.passes :refer [schedule]]
[clojure.tools.analyzer.passes.jvm.annotate-loops
:refer [annotate-loops]]
[clojure.tools.analyzer.passes.jvm.emit-form :as e]
[clojure.tools.analyzer.passes.jvm.warn-on-reflection
@aphyr
aphyr / minikanren.pl
Created October 12, 2020 22:10
Minikanren in Lisp in Prolog
:- use_module(library(pairs)).
:- use_module(library(reif)).
not_in_list(K, L) :-
if_((L = []),
true,
([X | More] = L,
dif(K, X),
not_in_list(K, More))).
@leonoel
leonoel / pump.clj
Last active July 6, 2023 17:13
functional reactive petroleum
;; missionary solution to petrol pump example by Stephen Blackheath and Anthony Jones, ISBN 978-1633430105
;; huanhulan's demo : [live](https://huanhulan.github.io/petrol_pump), [code](https://github.com/huanhulan/petrol_pump)
(ns pump
(:refer-clojure :exclude [first])
(:require [missionary.core :as m])
(:import missionary.Cancelled))
(defn rising
"A transducer that outputs `nil` when the input switches from logical false to logical true."
.ONESHELL:
test: .SHELLFLAGS := -i
test: SHELL := bb
test:
(println :wow)
(require '[clojure.string :as s])
(s/reverse (slurp "./Makefile"))
@borkdude
borkdude / macro.clj
Last active August 19, 2020 12:40
shell macro
(require '[clojure.java.shell :as sh]
'[clojure.string :as str])
(defn format-arg [arg]
(cond
(symbol? arg) (str arg)
(seq? arg) (let [f (first arg)]
(if (and (symbol? f) (= "unquote" (name f)))
(second arg)
arg))
@juskrey
juskrey / auto.clj
Created April 1, 2020 10:48
Clojure FSM sample
(ns sentinel.auto
(:require [taoensso.timbre :as timbre]
[clojure.core.match.date :refer :all]
[clojure.core.match :refer [match]]
[clojure.core.match.regex :refer :all]
[clojure.string :as st]
[clojure.core.async :refer [chan close! buffer go-loop to-chan <! >! >!! <!!] :as async]
[clojure.core.async.impl.protocols :as impl]
[clojure.spec.alpha :as s]
[clojure.core.async :as async]))