Skip to content

Instantly share code, notes, and snippets.

View kwrooijen's full-sized avatar

Kevin van Rooijen kwrooijen

View GitHub Profile
@kwrooijen
kwrooijen / dec->bin.scm
Last active May 22, 2020 11:16
Decimal to Binary conversion options in Scheme
;; Very clean, but is not tail recursive!
(define (dec->bin n)
(cond ((zero? n) '())
(else (cons (remainder n 2)
(dec->bin (quotient n 2))))))
;; Not so clean, but is tail recursive.
(define (dec->bin n)
(letrec ((recc (lambda (acc n)
(cond ((zero? n) acc)
(use-modules (srfi srfi-1)
(rnrs))
(define (transform-at l i val)
(let-values (((left right) (split-at l i)))
(append left (cons val (cdr right)))))
(display (transform-at '(1 2 3) 1 5)) ;=> '(1 5 3)
@kwrooijen
kwrooijen / threading.scm
Last active April 1, 2023 00:52
Clojure's threading macro in scheme
(define-syntax ->
(syntax-rules ()
([_ value]
value)
([_ value snd rest ...]
(cond
[(list? 'snd)
(let ([f (primitive-eval (car 'snd))]
[args (cons value (cdr 'snd))])
(-> (apply f args) rest ...))]
(require 'package)
(require 'ert)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))

Keybase proof

I hereby claim:

  • I am kwrooijen on github.
  • I am kwrooijen (https://keybase.io/kwrooijen) on keybase.
  • I have a public key ASD8wtzccqWjVgW2_O3-nJf4d6kPTyHnufxZ4kRYZ1f_pAo

To claim this, I am signing this object:

(defrecord RefWith [key opts]
ig/RefLike
(ref-key [_] key)
(ref-resolve [_ config resolvef]
(let [[k _] (first (ig/find-derived config key))
config (update config k #(merge % opts))
v (get (ig/init config [k]) k)]
(resolvef k v))))
(defn ref-with [key opts]
(ns dnd.core
(:require
[reagent.core :as r]
[reagent.dom :as d]))
(def default-persons
[{:person/name "Kevin"
:person/age 29
:person/active? true}
{:person/name "Foo"
(deftype YggdrasilAtom [name state]
clojure.lang.IAtom
(reset [this f] (reset! (.-state this) f))
(swap [this a] (swap! (.-state this) a))
(swap [this a b] (swap! (.-state this) a b))
(swap [this a b c] (swap! (.-state this) a b c))
(swap [this a b c d] (swap! (.-state this) a b c d))
(compareAndSet [this a b] (compare-and-set! (.-state this) a b))
(toString [this] (str (.-name this)))
(defmulti exception->map
(fn [^SQLException e]
(.getSQLState e)))
(defn- remove-quotes [s]
(clojure.string/replace s #"\"" ""))
(defn sql-key->keyword [sql-key]
(-> sql-key
(string/replace #"_key$" "")
@kwrooijen
kwrooijen / Render-com-Clojure.Dockerfile
Last active August 19, 2020 20:45
A Dockerfile meant for deploying a Clojure Uberjar to Render.com
FROM clojure:openjdk-8-lein-slim-buster AS build-jar
# Install any dependencies e.g. NPM for Clojurescript
# RUN apt update && apt install npm -y
WORKDIR /usr/src
COPY . .
# Build the uberjar. If you need to prepare certain things for your release
# (e.g. build your Clojurescript with Shadow-cljs) you can add a `:prep-tasks`
# key to the `:uberjar` profile in your `project.clj`. `lein-shell` can also be
# used to execute shell commands such as `npm`.