Skip to content

Instantly share code, notes, and snippets.

View ikitommi's full-sized avatar
💭

Tommi Reiman ikitommi

💭
View GitHub Profile
@ikitommi
ikitommi / report1.md
Last active November 16, 2020 07:17
Malli, Clojurists Together Project Update Q3 2020 August 15-31

Clojurists Together Project Update Q3 2020 August 15-31

First goal is to get a stable release of Malli out. This has involved some hammock time, revisiting the design decisions and both designing and implementing features that still could effect the shape of the core apis. And a lot of refactoring. Work is mostly tracked via #116.

Done stuff

Simple Schemas

  • Add utilities for users to easily create simple schemas with property-based validation, including :min and :max ranges for numbers, collections and dates.
  • More built-in schemas: :int, :double, :boolean, :keyword, :symbol, :qualified-keyword, :qualified-symbol and :uuid
{
"swagger": "2.0",
"x-id": [
"reitit.swagger/default"
],
"info": {
"title": "my-api",
"version": "v1",
"description": "with [malli](https://github.com/metosin/malli) and reitit-ring"
},
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore"
},
"paths": {
"/pet": {
"post": {
"tags": [
@ikitommi
ikitommi / user.clj
Last active April 5, 2020 16:38
Documenting malli keys and values
(require '[malli.core :as m])
;; using :and
(def Name
[:and {:documentation "Human name"} string?])
;; adding props to predicate schema
(def Name
[string? {:documentation "Human name"}])
@ikitommi
ikitommi / postgres.clj
Last active April 5, 2020 16:33
Postgres key transformations
(ns postgres)
(require '[clojure.string :as str])
(require '[malli.core :as m])
(require '[malli.transform :as mt])
(defn -transform-keys [f m]
(reduce-kv
(fn [acc k v] (assoc acc (f k) v))
(empty m)
@ikitommi
ikitommi / restaurant-spec.clj
Last active February 22, 2020 17:33
spec select
;; a sample data
(def tappi
{:mydomain/type :restaurant
:mydomain.restaurant/name "Vanha Tappi"
:mydomain.restaurant/tags #{:burgers :beer}
:mydomain.restaurant/stars 4.5
:mydomain.restaurant/address {:mydomain.address/street "Jokipohjantie 18"
:mydomain.address/city "Tampere"}})
(require '[clojure.spec-alpha2 :as s])
@ikitommi
ikitommi / _target.kt
Last active November 7, 2021 09:56
Deep-merge with Kotlin data-classes
import kotlin.reflect.KClass
import kotlin.reflect.KParameter
import kotlin.reflect.KProperty1
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.full.primaryConstructor
data class Address(
val street: String? = null,
val zip: String? = null
)
@ikitommi
ikitommi / malli.scicloj.clj
Last active October 29, 2019 04:09
malli-sciclj
;; clj -Sdeps '{:deps {metosin/malli {:git/url "https://github.com/metosin/malli"
;; :sha "68b9940fcf4671a3fcff7bb4844f7f06b2277a34"}}}'
;
; ███▄ ▄███▓ ▄▄▄ ██▓ ██▓ ██▓
; ▓██▒▀█▀ ██▒▒████▄ ▓██▒ ▓██▒ ▓██▒
; ▓██ ▓██░▒██ ▀█▄ ▒██░ ▒██░ ▒██▒
; ▒██ ▒██ ░██▄▄▄▄██ ▒██░ ▒██░ ░██░
; ▒██▒ ░██▒ ▓█ ▓██▒░██████▒░██████▒░██░
; ░ ▒░ ░ ░ ▒▒ ▓▒█░░ ▒░▓ ░░ ▒░▓ ░░▓
@ikitommi
ikitommi / grumpy.clj
Last active October 23, 2019 04:58
Grumpy routing test with reitit + best-effort auto-ordering (original: https://tonsky.me/blog/pedestal/)
(require '[reitit.core :as r])
(require '[reitit.impl])
(require '[criterium.core :as cc])
(def router
(-> [["/robots.txt" {:get ::get:.robots.txt}]
["/after/:post-id" {:get ::get:.after.:post-id}]
["/static/*path" {:get ::get:.static.*path}]
["/post/:post-id" {:get ::get:.post.:post-id}]
["/sitemap.xml" {:get ::get:.sitemap.xml}]
@ikitommi
ikitommi / malli.clj
Created June 21, 2019 06:07
Malli, Spec, Schema
;;
;; spec2
;;
(require '[clojure.spec-alpha2 :as s])
(s/def ::order
(s/schema {:purchaser string?
:due-date inst?
:line-items (s/coll-of (s/schema {:item-id pos-int?