Skip to content

Instantly share code, notes, and snippets.

View unclebob's full-sized avatar

Robert C. Martin unclebob

View GitHub Profile
@unclebob
unclebob / newquil
Last active March 11, 2024 17:53
newquil -- Script for creating a clojure/quil project.
#!/bin/zsh
echo "making quil project $1."
mkdir $1
cd $1
mkdir src
mkdir spec
cat >deps.edn << EOF
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
quil/quil {:mvn/version "4.3.1563"}
@unclebob
unclebob / newclj
Created March 10, 2024 13:43
newclj -- a simple tool to prepare a clojure project using speclj
#!/bin/zsh
echo "making speclj project $1."
mkdir $1
cd $1
mkdir src
mkdir spec
cat >deps.edn << EOF
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
speclj/speclj {:mvn/version "3.4.5"}}
@unclebob
unclebob / apology.
Created April 27, 2012 12:19
Apology to Women Programmers.
Today I gave a keynote at ACCU in Oxford. In the midst of it I made two (count them) two statements that I should have known better than to make. I was describing the late '70s, and the way we felt about the C language at the time. My slide said something like: "C was for real men." Emily Bache, whom I know and hold in high regard, spoke up and said "What about women?". And I said something like: "We didn't allow women in those days." It was a dumb crack, and should either not have been said, or should have been followed up with a statement to the effect that that was wrong headed.
The second mistake I made was while describing Cobol. I mentioned Adm. Grace Hopper. I said something like "May she rest in peace." I don't know that any of the words were actually demeaning, but the tone was not as respectful as it should have been to an Admiral in the United State Navy, and one who was so instrumental in our industry; despite what I feel about Cobol.
I am a 59 year old programmer who was brought up
@Test
public void wrapJustBeforeWordBoundary() throws Exception {
assertThat(wrap("word word", 4), equalTo("word\nword"));
}
public class Wrapper {
public static String wrap(String s, int col) {
return new Wrapper(col).wrap(s);
}
private int col;
private Wrapper(int col) {
this.col = col;
}
@unclebob
unclebob / prime_factors_test.clj
Created October 18, 2010 14:34
Prime factors Kata in Clojure
(ns prime-factors-test
(:use clojure.test midje.sweet))
(defn factors-starting-at [f n]
(cond
(> f (Math/sqrt n)) (if (= n 1) [] [n])
(= 0 (mod n f)) (cons f (factors-starting-at f (/ n f)))
:else (recur (inc f) n)))
(defn prime-factors-of [n]
@unclebob
unclebob / commatize
Created February 7, 2012 17:44
A function to format a number with commas
(defn commatize [n]
(if (nil? n)
""
(let [s (str n)]
(apply str
(reverse (drop-last
(interleave
(reverse s)
(take (count s) (flatten (repeat [nil nil \,]))))))))))
@unclebob
unclebob / mad_libs_test.clj
Created October 18, 2010 20:53
Simple Mad Libs app.
(ns mad-libs-test
(:use clojure.test midje.sweet))
(defn find-prompt [t])
(defn get-response [t])
(defn mad-libs [text]
(let [
[pre prompt post] (find-prompt text)]
(if (nil? prompt)
public class Wrapper {
public static String wrap(String s, int col) {
if (s.length() <= col)
return s;
int space = (s.substring(0, col).lastIndexOf(' '));
if (space != -1)
return (s.substring(0, space) + "\n" + wrap(s.substring(space+1), col));
else
return (s.substring(0, col) + "\n" + wrap(s.substring(col), col));
}
@Test
public void wrapAfterWordBoundary() throws Exception {
assertThat(wrap("word word", 6), equalTo("word\nword"));
}