Skip to content

Instantly share code, notes, and snippets.

Gary Fredericks gfredericks

Block or report user

Report or block gfredericks

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gfredericks
gfredericks / all-these-class-files.org
Last active Dec 10, 2018
Some of the sources for my Clojure/conj 2018 slides
View all-these-class-files.org

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

Latex Prelude

@gfredericks
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
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
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)
"objects/#{id[0...2]}/#{id[2..-1]}"
end
@gfredericks
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: https://github.com/clojure/test.check/blob/master/doc/growth-and-shrinking.md
@gfredericks
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
;; (https://twitter.com/pjstadig/status/771152863410188288)
;;
(defn draw-in-swing-buffer
[s]
(let [panel (doto (javax.swing.JPanel.)
(.setLayout (java.awt.BorderLayout.)))
frame (doto (javax.swing.JFrame.)
@gfredericks
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)]
thing)]
(list 'let ['thing (list 'quote thing)]
thing)))
(= regular-quine (eval regular-quine)) ;; => true
(def counting-quine
@gfredericks
gfredericks / parallel.md
Last active Aug 7, 2016
Independent bindings in gen/let
View parallel.md

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
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.