Skip to content

Instantly share code, notes, and snippets.

gfredericks / lazy-flatten-merge-by-test.clj
Last active September 23, 2020 01:23
This function I wrote one time
(ns user.test
[clojure.test :refer [deftest is]]
[clojure.test.check.results :as results]
[clojure.test.check.generators :as gen]
[ :as prop]
[clojure.test.check.clojure-test :refer [defspec]]))
(def gen-lazy-flatten-merge-by-keyfn
(gen/elements [identity - #(mod % 17)]))
gfredericks /
Last active February 11, 2023 01:22
Some of the sources for my Clojure/conj 2018 slides

What Are All These Class Files Even About?, and Other Stories

Latex Prelude

gfredericks / frobnicate.clj
Last active March 1, 2019 11:35
Self-contained clojure file with deps
#!/usr/bin/env bash
#! top-of-file comments can be written using more #! lines, which
#! is a valid comment in both clojure and bash
":";# alternately this works too
#! The construction below uses cross-language syntactic hackery to
#! specify the -Sdeps arg in a part of the file that's interpreted
#! by clojure as clojure syntax (i.e., not a line comment), so it
gfredericks / bijections.clj
Created March 19, 2018 17:07
Half a draft of bijections in clojure
(ns user.bijections
(:refer-clojure :exclude [-> comp update])
(:require [clojure.core :as core]
[clojure.set :as set])
(:import (java.util UUID)))
;; Motivation:
;; - avoid the edge cases inherent in allowing multiple
gfredericks / files.rb
Created October 18, 2017 11:29
Script for generating a compact bare git repo with 2^N files in it.
# Creates a git repo with 2^N files. N is the only arg. Creates a
# bare repo called "files".
require 'digest/sha1'
require 'zlib'
def filename(id)
gfredericks / gen_bigints.clj
Last active April 26, 2017 14:28
Proposed distribution for a bigint generator in test.check.
;; goals:
;; - unbounded distribution (arbitrarily large bigints can be generated,
;; even for small `size`)
;; - but respects `size` -- with larger `size`, larger numbers are likely
;; to be generated
;; - has a roughly 0.1% chance of generating an integer larger than
;; Double/MAX_VALUE (2^1024)
;; sizing background:
gfredericks / swing-quine.clj
Created September 1, 2016 01:56
A clojure quine that draws itself in a swing buffer
;; This file is clojure code that draws itself in a swing buffer
;; (
(defn draw-in-swing-buffer
(let [panel (doto (javax.swing.JPanel.)
(.setLayout (java.awt.BorderLayout.)))
frame (doto (javax.swing.JFrame.)
gfredericks / counting_quine.clj
Created August 31, 2016 22:43
A counting quine in Clojure
(def regular-quine
"A regular quine. Evals to itself."
'(let [thing '(list 'let ['thing (list 'quote thing)]
(list 'let ['thing (list 'quote thing)]
(= regular-quine (eval regular-quine)) ;; => true
(def counting-quine
gfredericks /
Last active August 7, 2016 15:35
Independent bindings in gen/let

Independent bindings in gen/let

The Problem

adapted from CLJ-1997

A common usage of gen/let might look something like this:

(gen/let [a gen-a
gfredericks / defn+spec.clj
Created June 9, 2016 19:02
A defn-like macro powered by clojure.spec
(ns user.defn+spec
(:require [clojure.spec :as s]))
(defn non-&-sym? [x] (and (symbol? x) (not= '& x)))
(s/def ::arglist
(s/cat :normal-args (s/* (s/cat :name non-&-sym?
:spec-form (s/? (s/cat :- #{:-}
:spec ::s/any))))
:varargs (s/? (s/cat :& #{'&}