Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Smith-Mannschott bpsm

View GitHub Profile
@bpsm
bpsm / edn.wsn
Last active Aug 26, 2017
Proposed formal syntax for Extensible Data Notation
View edn.wsn
(* 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 Feb 18, 2012
g[un]zip input to output
View gist:1858654
(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 Dec 21, 2011
An example of a pattern for constructing immutable objects using a fluent builder implemented as an inner class.
View Point.java
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.
*/
View jardifference.clj
(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)))
View interval-arithmetic.clj
(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)])
View gist:613279
(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)))))
View gist:549408
(ns people)
(defrecord Person [name age])
(def persons [(Person. "Boris" 40)
(Person. "Betty" 32)
(Person. "Bambi" 17)])
(def minor? #(-> % :age (<= 18)))
View gist:527621
(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)))))
View gist:372353
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)
View -keymap-canonicalize---Properly-preserve-keymap-prompt-.patch
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(-)
You can’t perform that action at this time.