Skip to content

Instantly share code, notes, and snippets.


Gary Fredericks gfredericks

View GitHub Profile
gfredericks /
Last active Dec 10, 2018
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 Mar 1, 2019
Self-contained clojure file with deps
View frobnicate.clj
#!/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 Mar 19, 2018
Half a draft of bijections in clojure
View bijections.clj
(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 Oct 18, 2017
Script for generating a compact bare git repo with 2^N files in it.
View files.rb
# 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 Apr 26, 2017
Proposed distribution for a bigint generator in test.check.
View gen_bigints.clj
;; 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 Sep 1, 2016
A clojure quine that draws itself in a swing buffer
View swing-quine.clj
;; 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 Aug 31, 2016
A counting quine in Clojure
View counting_quine.clj
(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 Aug 7, 2016
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 Jun 9, 2016
A defn-like macro powered by clojure.spec
View defn+spec.clj
(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 :& #{'&}
View clojure-spec-quine.clj
(s/def ::quine
((fn [x]
(s/cat :the-def #{'s/def}
:the-quine #{::quine}
:the-spec (s/spec
(s/cat :x #{x}
:x' (s/spec
(s/cat :quote #{'quote}
:x #{x}))))))
'(fn [x]
You can’t perform that action at this time.