Skip to content

Instantly share code, notes, and snippets.

J. B. Rainsberger jbrains

Block or report user

Report or block jbrains

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jbrains
jbrains / VirtualPointOfSaleTerminal.java
Created Apr 30, 2019
A simple example of wiring an application together
View VirtualPointOfSaleTerminal.java
package ca.jbrains.pos;
import ca.jbrains.pos.ui.TextProcessorAndCommandInterpreter;
import ca.jbrains.pos.ui.lcd.UdpPostOffice;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class VirtualPointOfSaleTerminal {
public static void main(String[] args) throws IOException {
@jbrains
jbrains / StringBuilderWithFolding.java
Created Nov 21, 2018
What obvious way of using Vavr's fold() am I missing here?
View StringBuilderWithFolding.java
private String linesOf(List<String> lines) {
StringBuilder stringBuilder = new StringBuilder();
lines.map(line -> stringBuilder.append(line).append(System.lineSeparator()));
return stringBuilder.toString();
}
@jbrains
jbrains / DocumentConnectToDatabaseWithExposed.kt
Created Nov 4, 2018
First steps in using Kotlin, Exposed, and writing tests
View DocumentConnectToDatabaseWithExposed.kt
import io.kotlintest.Description
import io.kotlintest.Spec
import io.kotlintest.extensions.TestListener
import io.kotlintest.shouldBe
import io.kotlintest.specs.FreeSpec
import org.jetbrains.exposed.dao.EntityID
import org.jetbrains.exposed.dao.IntEntity
import org.jetbrains.exposed.dao.IntEntityClass
import org.jetbrains.exposed.dao.IntIdTable
import org.jetbrains.exposed.sql.Database
@jbrains
jbrains / LearnToMergeAFreemarkerTemplateTest.java
Created Oct 15, 2018
Why do we do this? Why isn't it easier just to create a template in memory and merge it with data in memory?
View LearnToMergeAFreemarkerTemplateTest.java
package ca.jbrains.org.freemarker;
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
jbrains / LearnReadingLinesTest.java
Created Oct 13, 2018
An example of using a custom Hamcrest matcher to write tests. What do you think of this style?
View LearnReadingLinesTest.java
package ca.jbrains.java.test;
import ca.jbrains.java.ReaderBasedTextSource;
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
jbrains / factors.java
Created Jul 22, 2018
Find the number of factors of 5 in natural number n
View factors.java
public static int factorsOfFiveIn(int n) {
int factorsOfFive = 0;
while (n > 1) {
if (n % 5 == 0) factorsOfFive++;
n /= 5;
}
return factorsOfFive;
}
View NonRepeatingNumbers.cs
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
//Using Maybe.cs
namespace ArrayStructure
{
[TestFixture]
public class Tests
{
@jbrains
jbrains / ReturnConstructor.elm
Created Dec 6, 2017
Which, in your opinion, is "better"?
View ReturnConstructor.elm
-- This version returns a constructor for a PlayerModel, needing only a "name"
playerNeedingName : Maybe PlayerModel -> List PlayerModel -> (String -> PlayerModel)
playerNeedingName selectedPlayer players =
selectedPlayer
|> Maybe.map withName
|> Maybe.withDefault (nextPlayerModel players)
View keybase.md

Keybase proof

I hereby claim:

  • I am jbrains on github.
  • I am jbrains (https://keybase.io/jbrains) on keybase.
  • I have a public key ASCk97WjVrw0fVggW5H9CdXC92koHvo0GSQrdW6T1q0j4Qo

To claim this, I am signing this object:

@jbrains
jbrains / 1-Before.elm
Created Aug 1, 2017
How do I move the composition into the pipeline operating on Maybes?
View 1-Before.elm
changePlayerName : PlayerModel -> String -> ScorekeeperModel -> ScorekeeperModel
changePlayerName playerToChange newName scorekeeperModel =
let
{ players } =
scorekeeperModel
in
{ scorekeeperModel
| players =
Exts.List.mergeBy
(.id)
You can’t perform that action at this time.