Skip to content

Instantly share code, notes, and snippets.

View favila's full-sized avatar

Francis Avila favila

View GitHub Profile
@ericnormand
ericnormand / 00_script.clj
Last active January 6, 2024 07:13
Boilerplate for running Clojure as a shebang script
#!/bin/sh
#_(
#_DEPS is same format as deps.edn. Multiline is okay.
DEPS='
{:deps {clj-time {:mvn/version "0.14.2"}}}
'
#_You can put other options here
OPTS='
@halgari
halgari / gist:c17f378718cbd2fd82324002133ef678
Created November 23, 2018 20:54
Contributing to Clojure

So you’d like to contribute to Clojure, great! Let’s talk about what that involves.

The first thing you’ll want to make sure is that your idea is valid, and that you won’t spend a ton of time working on something that won’t make into master. To do this, you should create a JIRA ticket. For example, let’s say we want to improve how core.async handles channel closing propagation. It’s not a super complex problem, but there are some design questions about which of the various semantics currently in place should be the default, and if some semantics should be configurable.

So start by making a JIRA ticket and stating what the problem is you’re trying to solve, what the possible options for solving the problem. Now hit save and wait for the ticket to be triaged. Alex Miller will take a look when he can, and that can take a few days to a few weeks, depending on the time of the year (he has other responsibilities). Alex may out-right reject the idea if he knows Rich would never approve the ticket, but otherwise h

@mfikes
mfikes / README.md
Last active May 17, 2020 02:37
Seeing the inferred type of a ClojureScript expression

If you are curious about the types inferred by ClojureScript, it is easy to get some insight using a macro:

(defmacro inferred-type [form]
  `'~(cljs.analyzer/infer-tag &env
       (cljs.analyzer/no-warn (cljs.analyzer/analyze &env form))))

This is the kind of dev-time macro you could refer using the new user.cljs feature.

@Hendekagon
Hendekagon / copy2clip
Created May 19, 2017 15:18
copy2clip
(defn copy2clip [x]
(let [w (StringWriter.)]
(pprint x w)
(.. Toolkit getDefaultToolkit getSystemClipboard
(setContents (StringSelection. (.toString w)) nil))))
@favila
favila / entity-pull.clj
Created February 8, 2017 18:19
entity-pull: a datomic.api/pull that returns values the way datomic.api/entity would, with sets and ident keywords
(require '[datomic.api :as d])
(defn entity-pull
"Like pull, but returns values consistent with d/entity, i.e.,
entities with :db/ident are represented as keywords and sets are
used instead of vectors."
[db pat eid]
(->> (d/pull db pat eid)
(clojure.walk/prewalk
(fn [x]
@Jaretbinford
Jaretbinford / peermetrics.txt
Created January 18, 2017 13:58
metrics reported from the peer
The Datomic Pro peer can create the following CloudWatch metrics:
-----------------------------------PEER METRICS
|-------------------------------+------------+---------------+-----------------------------------------------------------------------------+
| Metric | Units | Statistic | Description |
|-------------------------------+------------+---------------+-----------------------------------------------------------------------------+
| AvailableMB | MB | minimum | unused RAM on peer * |
@ghadishayban
ghadishayban / productions.clj
Last active November 20, 2021 00:06
unified generators
;;
;; Example usages at the bottom of the file
;;
(defn productions
"Returns a sequence of values by repeatedly calling `produce!` until it
returns `fin`. The sequence can be used lazily/caching or reducible/non-caching.
The arity-2 variant's `produce!` takes no arguments and returns a value
or the terminator.
@favila
favila / entity-changes.clj
Last active October 16, 2019 13:14
enity-changes Return transaction history for a datomic entity and its components.
(require '[datomic.api :as d])
(defn entity-changes
"Return transaction history for an entity and its components.
Returns a sequence of maps, each is the transaction map (tx metadata) plus a
key `:entity-changes`, which is a nested map of keys: entity id, attribute
ident, `:db/add` or `:db/retract`, and the value added or retracted, e.g.:
{12345678910 {:long-card-1-attr {:db/retract 1
:db/add 0}
:long-card-many-attr {:db/add #{0}}
@vvvvalvalval
vvvvalvalval / mock-connection.clj
Last active September 19, 2018 06:09
Mocking datomic.Connection for fast in-memory testing
(ns bs.utils.mock-connection
"Utilities for using Datomic"
(:require [datomic.api :as d])
(:use clojure.repl clojure.pprint)
(:import (java.util.concurrent BlockingQueue LinkedBlockingDeque)
(datomic Connection)))
(defrecord MockConnection
[dbAtom, ^BlockingQueue txQueue]
@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