Skip to content

Instantly share code, notes, and snippets.

@tonvanbart
tonvanbart / roman.clj
Last active December 24, 2015 11:19
Roman numerals kata in Clojure, discovering the algorithm by TDD. IIRC the original description mentions the argument would not be greater than 3000 (as in a year A.D.), this is not checked. Arguments > 9999 will not be handled correctly.
(ns tonvanbart.roman
(:use clojure.test)
(:require [clojure.string :as str]))
(defn convert-step
"one step converting a number to roman numerals"
[n unitsymbol fivesymbol tensymbol]
(cond
(< n 4) (apply str (repeat n unitsymbol))
(< n 9) (str/join
(ns sicp.chapter1.ex1_11)
; SICP chapter 1, exercise 11
; let f(x) = x for x<3
; f(x) = f(x-1) + 2f(x-2) + 3f(x-3) otherwise
(defn f
"the tree-recursive version"
[n]
(if (< n 3) n
@tonvanbart
tonvanbart / .vimrc
Last active October 26, 2017 07:22
My current, very minimal, .vimrc
set nu
set showmode
set autoindent
set smartindent
set sw=4
set ts=4
set expandtab
set hlsearch
@tonvanbart
tonvanbart / warclean.sh
Last active September 19, 2016 11:42
A small bash script to delete given set of jar files from the WEB-INF/lib of a given warfile.
#!/bin/bash
main() {
if [ "$#" -ne 2 ]; then
EXPLAIN
exit 0
fi
clean "$@"
}
@tonvanbart
tonvanbart / .bash_aliases
Created April 1, 2015 08:03
Slightly modified version of a .bash_aliases file found online. This will set your prompt to user@host:working-dir, when you're in a Git repo the name of the branch is added at the end, colored to indicate if the branch is clean. All credits to the original author, I just tweaked it a little.
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://MediaDoneRight.com
# SETUP CONSTANTS
# Bunch-o-predefined colors. Makes reading code easier than escape sequences.
# I don't remember where I found this. o_O
# Reset
Color_Off="\[\033[0m\]" # Text Reset
(ns minesweeper.solver
(:use clojure.test))
(defn solve [scenario]
"Example input: {:rows 10 :cols 10 :mines 2}"
(let [mines (:mines scenario)
rows (:rows scenario)
cols (:cols scenario)
freecells (- (* rows cols) mines)]
(cond
@tonvanbart
tonvanbart / ReplaceAll.java
Last active July 3, 2016 22:17
Combine two maps a and b so that for a key in a, the value is b(a(key))
package org.vanbart;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNull;
@tonvanbart
tonvanbart / package.sh
Last active July 28, 2016 10:00
Create a zip-of-zips from a given directory structure.
#!/bin/bash
main() {
if [ "$#" -ne 2 ]; then
printusage
exit 0
fi
dozip $1 $2
}
@tonvanbart
tonvanbart / TemplateMethodFunctional.java
Last active October 25, 2016 21:19
Functional programming example in java8: replace template method pattern with function composition.
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Functional replacement for Template Method in java 8
* Created by ton on 25/10/16.
*/
@tonvanbart
tonvanbart / Example.java
Created November 11, 2016 10:27
Example using projectreactor.io : create a Flux to enable clients to subscribe to your method call.
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink;
/**
* Created by ton on 10/11/16.
*/