Skip to content

Instantly share code, notes, and snippets.

@janbols
janbols / ValidationRule.java
Last active October 25, 2017 14:44
validation kleisli
import fj.P;
import fj.P2;
import fj.P3;
import fj.data.Validation;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Function;
@janbols
janbols / f23.erl
Created April 23, 2017 19:07
Erlang mooc exercise 3.4
%% Based on code from
%% Erlang Programming
%% Francecso Cesarini and Simon Thompson
%% O'Reilly, 2008
%% http://oreilly.com/catalog/9780596518189/
%% http://www.erlangprogramming.org/
%% (c) Francesco Cesarini and Simon Thompson
-module(f23).
-export([start/0, allocate/0, deallocate/1, stop/0]).
@janbols
janbols / frequency.erl
Created April 15, 2017 19:24
Erlang MOOC 2.10
%% Based on code from
%% Erlang Programming
%% Francecso Cesarini and Simon Thompson
%% O'Reilly, 2008
%% http://oreilly.com/catalog/9780596518189/
%% http://www.erlangprogramming.org/
%% (c) Francesco Cesarini and Simon Thompson
-module(frequency).
-export([startFrequency/0, stopFrequency/0, startClient/3, startClient/1, killFrequency/0, killClient/1, demo/0]).
@janbols
janbols / frequency.erl
Created April 13, 2017 20:11
2nd assignment for erlang MOOC
%% Based on code from
%% Erlang Programming
%% Francecso Cesarini and Simon Thompson
%% O'Reilly, 2008
%% http://oreilly.com/catalog/9780596518189/
%% http://www.erlangprogramming.org/
%% (c) Francesco Cesarini and Simon Thompson
-module(frequency).
-export([start/0, stop/0, startClient/3]).
@janbols
janbols / frequency.erl
Last active April 10, 2017 19:32
Assignment for erlang MOOC
%% Based on code from
%% Erlang Programming
%% Francecso Cesarini and Simon Thompson
%% O'Reilly, 2008
%% http://oreilly.com/catalog/9780596518189/
%% http://www.erlangprogramming.org/
%% (c) Francesco Cesarini and Simon Thompson
-module(frequency).
-export([start/0, allocate/0, deallocate/1, stop/0]).
@janbols
janbols / ThreadInterruptedInTimeoutTest.groovy
Created March 9, 2017 14:16
Using a timeout operator, the thread running the other single is in an interrupted state
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import spock.lang.FailsWith
import spock.lang.Specification
import java.util.concurrent.TimeUnit
class ThreadInterruptedInTimeoutTest extends Specification {
volatile boolean threadWasInterrupted = false
@janbols
janbols / index.erl
Created March 6, 2017 21:10
index assignment of erlang MOOC
-module(index).
-export([get_file_contents/1, show_file_contents/1, get_all_words/1, index_lines/1, index_file/1]).
% Takes a filename and returns a list of indexed words
% f.e. index:index_file("gettysburg-address.txt").
index_file(Name) -> index_lines(get_file_contents(Name)).
% Takes a list of lines and returns a list of indexed words
index_lines(Lines) -> sort_by_word(consolidate(sort_by_word_and_index(bag_of_indexed_words(zip_with_ix_nr(Lines))))).
@janbols
janbols / ObservableJdbcTemplate.java
Last active March 27, 2018 07:03
Returning sql data as Observable
import org.slf4j.Logger;
import org.springframework.jdbc.core.*;
import org.springframework.jdbc.core.namedparam.EmptySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;
import rx.Observable;
import rx.Observer;
import rx.observables.SyncOnSubscribe;
@janbols
janbols / Domain.groovy
Last active August 29, 2015 14:15
memoizing object creation during spock test
import groovy.transform.Immutable
@Immutable
class User {
UUID id
String fullName
int age
}
class VeryComplexFilter {
@janbols
janbols / NotifiesCustomers.groovy
Last active August 29, 2015 14:14
use closures as functions
@GrabResolver('https://oss.sonatype.org/content/groups/public')
@Grab('org.functionaljava:functionaljava:4.2')
import fj.F2
import groovy.transform.Canonical
import groovy.transform.Immutable
import groovy.transform.stc.ClosureParams
import groovy.transform.stc.SimpleType
@Canonical