Skip to content

Instantly share code, notes, and snippets.

View jbrains's full-sized avatar

J. B. Rainsberger jbrains

View GitHub Profile
jbrains / test.purs
Created December 24, 2021 14:11
WANTED: A more concise way to execute a side effect in a test without checking its result
checkSellMultipleItems :: Spec Unit
checkSellMultipleItems =
describe "Sell Multiple Items" do
it "happy path" do
(POS.handleCommand $ TextCommand "12345") `shouldSatisfy` (const true)
(POS.handleCommand $ TextCommand "total") `shouldEqual` "Total: CAD 27.50"
jbrains /
Created April 30, 2019 13:32
A simple example of wiring an application together
package ca.jbrains.pos;
import ca.jbrains.pos.ui.TextProcessorAndCommandInterpreter;
import ca.jbrains.pos.ui.lcd.UdpPostOffice;
import java.util.HashMap;
public class VirtualPointOfSaleTerminal {
public static void main(String[] args) throws IOException {
jbrains /
Created November 21, 2018 09:56
What obvious way of using Vavr's fold() am I missing here?
private String linesOf(List<String> lines) {
StringBuilder stringBuilder = new StringBuilder(); -> stringBuilder.append(line).append(System.lineSeparator()));
return stringBuilder.toString();
jbrains / DocumentConnectToDatabaseWithExposed.kt
Created November 4, 2018 20:22
First steps in using Kotlin, Exposed, and writing tests
import io.kotlintest.Description
import io.kotlintest.Spec
import io.kotlintest.extensions.TestListener
import io.kotlintest.shouldBe
import io.kotlintest.specs.FreeSpec
jbrains /
Created October 15, 2018 16:58
Why do we do this? Why isn't it easier just to create a template in memory and merge it with data in memory?
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import io.vavr.collection.HashMap;
import io.vavr.collection.Map;
import org.junit.Assert;
import org.junit.Test;
jbrains /
Created October 13, 2018 19:16
An example of using a custom Hamcrest matcher to write tests. What do you think of this style?
import io.vavr.collection.List;
import io.vavr.collection.Stream;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Assert;
jbrains /
Created July 22, 2018 23:49
Find the number of factors of 5 in natural number n
public static int factorsOfFiveIn(int n) {
int factorsOfFive = 0;
while (n > 1) {
if (n % 5 == 0) factorsOfFive++;
n /= 5;
return factorsOfFive;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
//Using Maybe.cs
namespace ArrayStructure
public class Tests
jbrains / ReturnConstructor.elm
Created December 6, 2017 10:35
Which, in your opinion, is "better"?
-- This version returns a constructor for a PlayerModel, needing only a "name"
playerNeedingName : Maybe PlayerModel -> List PlayerModel -> (String -> PlayerModel)
playerNeedingName selectedPlayer players =
|> withName
|> Maybe.withDefault (nextPlayerModel players)
jbrains /
Created September 21, 2017 15:45

Keybase proof

I hereby claim:

  • I am jbrains on github.
  • I am jbrains ( on keybase.
  • I have a public key ASCk97WjVrw0fVggW5H9CdXC92koHvo0GSQrdW6T1q0j4Qo

To claim this, I am signing this object: