Skip to content

Instantly share code, notes, and snippets.

View hiredman's full-sized avatar

Kevin Downey hiredman

View GitHub Profile
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
SERVER=
CLIENT_NAME=
CLIENT_ID=
CLIENT_SECRET=
AUTH_CODE=
ACCESS_TOKEN=
#!/bin/sh
#_(
true; exec clj -J-Xmx256M -J-XX:-OmitStackTraceInFastThrow -Sdeps "`sed -n -e '/;;(DEPS$/,/;;DEPS)$/p' $0`" -M -i $0 -e '(user/main)'
)
(ns user
#?(:cljs (:require-macros [user :as m]))
(:require
#?@(:clj ([cljs.build.api :as cljs]
(import '(java.util ArrayList
List)
'(java.util.concurrent.locks ReentrantLock)
'(java.util.concurrent.atomic AtomicReference
AtomicReferenceArray))
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
;; TODO: should you be able to sync multiple times on the same event
@hiredman
hiredman / cml.clj
Last active October 13, 2022 20:22
(defmacro let-macro
([bindings body]
(let [names (map first bindings)]
`(let-macro ~(eval `(letfn ~bindings ~(into {} (map (fn [n] [(list 'quote n) n])) names)))
~identity
~body)))
([bindings k body]
(cond (and (seq? body)
(symbol? (first body))
(contains? bindings (first body)))
cat > /tmp/storeid.lisp <<EOF
#!/usr/bin/sbcl --script
(loop
(let* ((parts (list ""))
(_ (loop for c across (read-line) do
(cond
((equal c #\Space)
(setf parts (cons "" parts)))
('t
(defn generate-state-machine [init-state inputs states state transition? accum]
(gen/sized
(fn [size]
(if (zero? size)
(let [prev (into {} (for [[a b] (partion-all 2 1 (sort inputs))] [b a]))]
((fn f [events]
(gen/gen-pure
(rose/make-rose
events
(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)))
(let [addr (java.net.UnixDomainSocketAddress/of "/tmp/222")
sc (doto (java.nio.channels.ServerSocketChannel/open java.net.StandardProtocolFamily/UNIX)
(.bind addr))]
(while true
(let [c (.accept sc)]
(future
(let [in (java.nio.channels.Channels/newInputStream c)
out (java.nio.channels.Channels/newOutputStream c)]
(binding [*in* (clojure.lang.LineNumberingPushbackReader.
(clojure.java.io/reader in))
(defn async-iteration [from-process
to-process
output-channel
& {:keys [values-selector some? init]
:or {values-selector vector
some? some?}}]
(async/go
(async/>! to-process init)
(loop [value (async/<! from-process)]
(if (some? value)
;; single file web app
;; run the following to start the process
;; clj -J-Xmx500M -J-XX:-OmitStackTraceInFastThrow -J-Dclojure.server.repl="{:port 9457 :accept clojure.core.server/repl}" -Sdeps '{:deps {net.sourceforge.htmlunit/htmlunit {:mvn/version "2.53.0"} org.clojure/data.json {:mvn/version "2.4.0"} com.github.seancorfield/next.jdbc {:mvn/version "1.2.731"} org.postgresql/postgresql {:mvn/version "42.2.24"} org.clojure/clojurescript {:mvn/version "1.10.879"} io.undertow/undertow-core {:mvn/version "2.2.12.Final"} reagent/reagent {:mvn/version "1.1.0"} cljsjs/react {:mvn/version "17.0.2-0"} cljsjs/react-dom {:mvn/version "17.0.2-0"} com.cognitect/transit-clj {:mvn/version "1.0.324"} com.cognitect/transit-cljs {:mvn/version "0.8.269"}}}' -M -i src/packages.cljc -e '(packages/main)'
(ns packages
#?(:cljs (:require-macros [packages :as m]))
(:require
#?@(:clj ([clojure.data.json :as json]
[next.jdbc :as jdbc]
[cljs.build.api :as cljs]