Skip to content

Instantly share code, notes, and snippets.

View rauhs's full-sized avatar

Andre W. rauhs

  • Bavaria, Germany
View GitHub Profile
SHELL=/bin/bash
NGINX:=$(abspath software/nginx/sbin/nginx)
CONF:=$(abspath conf/nginx.conf)
OPENRESTY_V:=1.9.15.1
OPENRESTY_F:=openresty-$(OPENRESTY_V)
OPENRESTY_RUN_DIR:=$(PWD)/openresty
.PHONY: def_target run reload stop auto-reload
public class Issue1351
{
private readonly ITestOutputHelper output;
public Issue1351(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
@rauhs
rauhs / humanize-schema-errors.clj
Last active May 27, 2023 05:29
Translate prismatic's schema.core errors to a human readable form. Use this for presenting validation errors to users. Don't use this for programming errors like a missing map key etc.
(ns x.y
(:use [plumbing.core]) ;; Just for the map-vals
(:require [clojure.walk :refer [postwalk prewalk prewalk-demo postwalk-demo]]
[clojure.core.match :refer [match]]
[schema.utils :refer [named-error-explain validation-error-explain]]
[schema.core :as s])
(:import (schema.utils NamedError ValidationError)))
;; Partially FROM:
;; https://github.com/puppetlabs/clj-schema-tools
(ns ansible.core
(:require [clojure.java.shell :as sh]
[clojure.string :as str]
[cheshire.core :as cheshire]
[clojure.java.io :as io])
(:import (java.io File)
(com.fasterxml.jackson.core JsonGenerator)
(java.util Base64)
(java.security MessageDigest MessageDigest$Delegate)))

Synopsis

Problem: Omegawiki's database layout ( http://www.omegawiki.org/Help:OmegaWiki_database_layout ) is incredibly complex and makes it tough to query the db.

This quick'n'dirty script imports the data into datomic. It aims to fully connect them with refs so that you can walk along the entities just like clojure maps.

Once in Datomic the entire db is in memory and it's very easy to explore the db and also very fast.

@rauhs
rauhs / A.synopsis.md
Last active September 20, 2021 14:22
Configure logback at runtime without XML but using hiccup

Synopsis

So logback uses a configuration framework called Joran. Upon JVM startup it loads the logback.xml file and shoves the XML into the Joran configurator. (See: https://logback.qos.ch/manual/onJoran.html )

This gist does nothing else but:

  1. Take the hiccup, which uses the exact same nodes/attributes as the XML file
  2. Generate XML from it
  3. Shove the entire thing into Joran.
(defmacro afor
"Like for but eagerly builds a JS array.
Usually for react consumption."
[[item coll] & body]
`(reduce (fn [neue# ~item]
(.push neue# (do ~@body))
neue#)
(cljs.core/array) ~coll))
(defmacro arfor
@rauhs
rauhs / Makefile
Last active July 7, 2020 19:44
Compiling clojurescript + figwheel without boot nor leiningen. Using leiningen to manage dependencies. Print file size stats (raw, gzip, brotli) for production builds
CLJ_NREPL_PORT:=22340
FIGWHEEL_PORT:=22345
CLJS_JAR_VERSION:=1.7.48
CLJS_JAR_URL:=https://github.com/clojure/clojurescript/releases/download/r$(CLJS_JAR_VERSION)/cljs.jar
.PHONY: def_target
def_target : null
(defn sort-by-fast
"Returns a sorted sequence of the items in coll, where the sort
order is determined by comparing (keyfn item). Comp can be
boolean-valued comparison funcion, or a -/0/+ valued comparator.
Comp defaults to compare."
([keyfn coll]
(sort-by-fast keyfn compare coll))
([keyfn comp coll]
(let [arr (to-array coll)
;; Hack: access private function:
@rauhs
rauhs / Makefile
Last active March 23, 2020 21:40
################################################################################
# Vars
# $< Dependency (right)
# $@ Target (left)
CLJ_NREPL_PORT:=22340
FIGWHEEL_PORT:=22345
LEIN_NREPL_PORT:=22350
CLJ_NREPL_PORT_TRY:=22355