Skip to content

Instantly share code, notes, and snippets.

View RickMoynihan's full-sized avatar

Rick Moynihan RickMoynihan

  • TPXImpact
  • Manchester
View GitHub Profile
@RickMoynihan
RickMoynihan / logmacro.clj
Created March 18, 2021 10:26
Clojure macro to capture log4j2 ThreadContexts
;; Originally dual licensed under EPL 1.0 and AGPL 3.
(import 'org.apache.logging.log4j.ThreadContext)
(defn capture-logging-context []
(into {} (ThreadContext/getContext)))
;; Modified from withdrawn library:
;; https://github.com/malcolmsparks/clj-logging-config/blob/master/src/main/clojure/clj_logging_config/log4j.clj
(defmacro with-logging-context [x & body]
@RickMoynihan
RickMoynihan / iterate_example.clj
Created May 29, 2019 13:36
Produces Excel like column names
(defn column-names-seq
"Given an alphabet string generate a lazy sequences of column names
e.g.
`(column-names-seq \"abcdefghijklmnopqrstuvwxyz\") ;; => (\"a\" \"b\" \"c\" ... \"aa\" \"ab\")`"
[alphabet]
(->> (map str alphabet)
(iterate (fn [chars]
(for [x chars
y alphabet]
(str x y))))
@RickMoynihan
RickMoynihan / prettify-rdf
Last active November 8, 2018 16:46
Prettifies an RDF file by applying prefixes. Can also convert from one format to another
#!/usr/bin/env bash
":";grafter='grafter {:mvn/version "0.11.5"}'
":";cli='org.clojure/tools.cli {:mvn/version "0.3.7"}'
"exec" "clojure" "-Sdeps" "{:deps {$grafter $cli}}" "$0" "$@"
(require '[grafter.rdf :as rdf])
(require '[grafter.rdf.io :as rio])
(require '[clojure.java.io :as io])
@RickMoynihan
RickMoynihan / clojure-scripting
Created August 7, 2018 10:18
Example of using clojure cli tools to write a script that fetches dependencies via tools.deps
#!/usr/bin/env clojure -Sdeps {:deps,{clj-time/clj-time,{:mvn/version,"0.14.4"}}}
(require '[clj-time.core :as t])
(println (t/now))
(println "Received command line arguments " *command-line-args*)
(ns ring-file-upload.core
(:require [ring.adapter.jetty :as jetty])
(:require [ring.middleware.multipart-params :as mp]
[ring.middleware.params :as param]))
(defn handler [request]
{:status 200
:headers {"Content-Type" "text/plain"}
:body (str "REQ: " (prn-str request))})
(require '[grafter.rdf.io :as gio])
(defn every-quad-valid?
"Test coercing quads to sesame statements, raises an exception with
a very useful error message if it fails."
[quads]
(every? gio/IStatement->sesame-statement quads))
(defmulti foo identity)
(defmethod foo :foo [_] :foo)
(defmethod foo :bar [_] :bar)
(derive :foo-child :foo)
(derive :bar-child :bar)
(defn supported-parameter?
(def h (atom (make-hierarchy)))
(defmulti foo identity :hierarchy h)
(defmethod foo :foo [_] :foo)
(defmethod foo :bar [_] :bar)
(swap! h derive :foo-child :foo)
(swap! h derive :bar-child :bar)
node {
checkout scm
stage('Test') {
sh 'pwd'
sh 'pwd > pwd-out'
sh 'lein test'
}
stage('Install') {
(ns specing.uri
(:require [clojure.spec :as s]))
;; crude specing of URI/URL objects - rules are actually more complex & nuanced
;; than this ... just experimenting with clojure.spec rather than adding it for
;; real... though when I do it will probably be in grafter.url / core.rdf
(def domain? string?)