Skip to content

Instantly share code, notes, and snippets.

View bpsm's full-sized avatar

Ben Smith-Mannschott bpsm

View GitHub Profile
@bpsm
bpsm / edn.wsn
Last active January 1, 2022 16:22
Proposed formal syntax for Extensible Data Notation
(* Syntax of Extensible Data Notation -- http://github.com/edn-format/edn
See https://github.com/edn-format/edn/issues/56
This grammar is written in slightly extended version of Wirth Syntax
Notation. A description is appended to the end of this document. *)
(* start *)
@bpsm
bpsm / gist:1858654
Created February 18, 2012 10:31
g[un]zip input to output
(ns clj-gunzip.core
(:require [clojure.java.io :as io])
(:require [clojure.string :as str])
(:import java.util.zip.GZIPInputStream
java.util.zip.GZIPOutputStream))
(defn gunzip
"Writes the contents of input to output, decompressed.
input: something which can be opened by io/input-stream.
@bpsm
bpsm / Point.java
Created December 21, 2011 19:03
An example of a pattern for constructing immutable objects using a fluent builder implemented as an inner class.
package innerclassbuilderexample;
/*
* An example of a pattern for constructing immutable
* objects using a fluent builder implemented as an
* inner class.
*
* Some boiler plate code can be saved if one is willing to give up
* fluency in the Builder's interface.
*/
(ns jardifference
(:import (java.util.jar JarFile JarEntry JarOutputStream))
(:require (clojure.java [io :as io])
(clojure [set :as set])))
(defn jar-entry-seq
[^JarFile jf]
(enumeration-seq (.entries jf)))
(defn interval [x y] [x y])
(defn plus [[a b] [c d]] [(+ a c) (+ b d)])
(defn minus [[a b] [c d]] [(- a d) (- b c)])
(def minmax (juxt min max))
(defn times [[a b] [c d]] (minmax (* a c) (* a d) (* b c) (* b d)))
(defn divide [[a b] [c d]] (minmax (/ a c) (/ a d) (/ b c) (/ b d)))
(def half #(/ % 2))
(defn ends->center [[a b]] [(half (+ a b)) (half (- b a))])
(defn center->ends [[a b]] [(- a b) (+ a b)])
(ns bpsmannschott
(:import java.io.File)
(:import java.io.FileNotFoundException))
(defn as-file [s]
"Return whatever we have as a java.io.File object"
(cond (instance? File s) s ; already a file, return unchanged
(string? s) (File. s) ; return java.io.File for path s
:else (throw (FileNotFoundException. (str s)))))
(ns people)
(defrecord Person [name age])
(def persons [(Person. "Boris" 40)
(Person. "Betty" 32)
(Person. "Bambi" 17)])
(def minor? #(-> % :age (<= 18)))
(ns libpsm.string
(:require [clojure.string :as str]))
(let [triml-with-pipe (comp #(str/replace-first % "|" "")
str/triml)]
(defn mstr*
"Multiline string with explicit left margin."
[s]
(str/join "\n" (map triml-with-pipe
(str/split-lines s)))))
ERROR in (complex-sqrt) (run-test32965.clj:44)
Uncaught exception, not in assertion.
expected: nil
actual: java.lang.IllegalArgumentException: No method in multimethod 'sqrt' for di
spatch value: :clojure.contrib.complex-numbers/complex
at clojure.lang.MultiFn.getFn (MultiFn.java:115)
clojure.lang.MultiFn.invoke (MultiFn.java:157)
clojure.contrib.test_complex_numbers/fn (test_complex_numbers.clj:291)
clojure.test$test_var__6804$fn__6805.invoke (test.clj:644)
clojure.test/test_var (test.clj:644)
From 3ba1fbf6833c21724659646518a4b999d783840d Mon Sep 17 00:00:00 2001
From: Andreas Schwab <schwab@suse.de>
Date: Fri, 26 Dec 2008 16:49:30 +0000
Subject: [PATCH] (keymap-canonicalize): Properly preserve keymap prompt.
---
lisp/ChangeLog | 2 ++
lisp/subr.el | 6 +++---
2 files changed, 5 insertions(+), 3 deletions(-)