This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns user.test | |
(:require | |
[clojure.test :refer [deftest is]] | |
[clojure.test.check.results :as results] | |
[clojure.test.check.generators :as gen] | |
[clojure.test.check.properties :as prop] | |
[clojure.test.check.clojure-test :refer [defspec]])) | |
(def gen-lazy-flatten-merge-by-keyfn | |
(gen/elements [identity - #(mod % 17)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; 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.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
adapted from CLJ-1997
A common usage of gen/let
might look something like this:
(gen/let [a gen-a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 :& #{'&} |
NewerOlder