Skip to content

Instantly share code, notes, and snippets.

View arichiardi's full-sized avatar

Andrea Richiardi arichiardi

View GitHub Profile
@arichiardi
arichiardi / utils.clj
Last active August 29, 2015 14:04
Some snippet from my Clojure hacks.
(ns com.andrearichiardi.utils
(:require [clojure.java.io :as io]))
(defn make-file-from-resource [name] (io/file (io/resource name)))
(defn to-bit-representation [^java.lang.Double d]
(-> (Double/doubleToRawLongBits d) (java.lang.Long/toBinaryString)))
(defmacro with-private-fns [[ns fns] & tests]
"Refers private fns from ns and runs tests in context."
@arichiardi
arichiardi / clojure_recur_sequences
Created April 13, 2015 11:38
Clojure partition w/ recur
(defn- part-iter
([n step step-coll part-coll i part parts]
(if (seq step-coll)
(if (and (seq part-coll) (< i n))
(recur n step step-coll (rest part-coll) (inc i) (cons (first part-coll) part) parts)
(let [nthrst (drop (int step) step-coll)]
(recur n step nthrst nthrst 0 nil (cons (reverse part) parts))))
(reverse (if (seq part)
(cons (reverse part) parts)
parts))))

Keybase proof

I hereby claim:

  • I am arichiardi on github.
  • I am arichiardi (https://keybase.io/arichiardi) on keybase.
  • I have a public key ASBS7KDW38RUXMhxC2BOsMU5G9me2c2D119-vmmS8onFmwo

To claim this, I am signing this object:

@arichiardi
arichiardi / boot-util.clj
Created January 29, 2016 21:08
Some util function for boot/files
(ns replumb.boot.util
(:require [clojure.java.io :as io]
[clojure.string :as string]
[boot.core :as core]
[boot.pod :as pod]
[boot.util :as util]
[clj-jgit.porcelain :as jgit])
(:import java.io.File
java.nio.file.Files
java.nio.file.attribute.FileAttribute
@arichiardi
arichiardi / profile.boot
Last active July 6, 2016 22:41
Profile.boot for postgres in a docker
(require '[boot.pod :as pod])
(def pod-deps '[[boot/core "2.6.0" :scope "test"]
[adzerk/env "0.3.0" :scope "test"]
[me.raynes/conch "0.8.0" :scope "test"]])
(deftask postgres
[t type VAL str "The build type as string"]
(let [pod (future (pod/make-pod (update-in (get-env) [:dependencies] into pod-deps)))]
(with-pass-thru _
@arichiardi
arichiardi / interop.clj
Last active July 26, 2016 15:33
Interop snippets
(ns
^{:author "Andrea Richiardi"
:doc "Bridge helpers between Clojure and Java."}
com.andrearichiardi.interop
(:require [clojure.reflect :refer [reflect]]
[clojure.string :refer [join]]))
(defn canonical-name
"Return the class' canonical name of an instance, or nil if the input is nil."
[^java.lang.Object instance]
@arichiardi
arichiardi / boot-rebase.clj
Last active September 29, 2016 21:46
Boot rebase task
;; https://github.com/boot-clj/boot/pull/398
(defn filter-tmpfiles
"Filter TmpFiles that match (a least one in) metadata-preds.
Metadata-preds is a set of functions which will receive a TmpFile and
tried not in a specific order. If no predicate in the set returns
true-y, the file is filtered out from the returned TmpFiles.
If invert is specified, the behavior is reversed."
([tmpfiles metadata-preds]
(require 'clojure.repl)
;; macros
;; https://github.com/boot-clj/boot/commit/045d01101d61d947e1efd729e1f73b5690020928
(intern 'clojure.core (with-meta 'doc {:macro true}) @#'clojure.repl/doc)
(intern 'clojure.core (with-meta 'dir {:macro true}) @#'clojure.repl/dir)
(intern 'clojure.core (with-meta 'source {:macro true}) @#'clojure.repl/source)
;; fns
(intern 'clojure.core 'apropos @#'clojure.repl/apropos)
@arichiardi
arichiardi / build.clj
Last active November 11, 2017 15:12
Data oriented defedntask for boot-clj, sample (macro not included)
(def env-web-prod {:resource-paths #{"resources"}
:source-paths #{"src/web" "src/shared"}
:dependencies '[[org.clojure/clojure "1.9.0-alpha14"]
[adzerk/boot-cljs "2.0.0-SNAPSHOT" :scope "test"]
[org.clojure/clojurescript "1.9.456" :scope "test"]
[org.clojure/test.check "0.9.0"] ;; AR - at the moment we need it, see http://dev.clojure.org/jira/browse/CLJS-1792
[adzerk/env "0.4.0"]
[binaryage/oops "0.5.2"]
[cljsjs/d3 "4.3.0-3"]
[cljsjs/intersections "1.0.0-0"]
@arichiardi
arichiardi / dump-npm-deps.sh
Created March 5, 2018 21:12
Dump the Clojure :npm-deps index
clojure -e "(require '[cljs.closure :as cc] '[clojure.pprint :refer [pprint]]) (pprint (cc/index-node-modules-dir $(cat cljsc_opts.edn)))" > npm-deps.edn