Skip to content

Instantly share code, notes, and snippets.

@dpolivaev
dpolivaev / Game.java
Created December 15, 2013 14:20
GameOfLife based on a general cell distribution function, #gdcr13
package gameoflife;
public class Game {
public interface Distribution {
boolean cellExists(int x, int y);
}
final private Distribution distribution;
public Game(Distribution initialDistribution) {
@dpolivaev
dpolivaev / Instructions.md
Last active January 26, 2016 10:26 — forked from pgilad/Instructions.md
Git commit-msg hook to validate for jira issue or the word merge

Instructions

  • copy the file commit-msg to .git/hooks/commit-msg
  • make sure your delete the sample file .git/hooks/commit-msg.sample
  • Make commit msg executable. chmod +x .git/hooks/commit-msg
  • Edit commit-msg to better fit your development branch, commit regex and error message
  • Profit $$

Shell example

@dpolivaev
dpolivaev / No primitives outside-in Game of Life
Last active August 31, 2016 10:15
Outside-in driven by constraints "first class collections members" and "no getters"
We couldn’t find that file to show.

KataPacMan

Taken from: http://codingdojo.org/cgi-bin/index.pl?KataPacMan

Problem Description

Pacman finds himself in a grid filled with monsters. Will he be able to eat all the dots on the board before the monsters eat him?

Incomplete list of things the game needs:

Files with typical JGiven dependencies
import org.scalatest.Matchers
case class Point(x: Int, y: Int)
sealed trait Direction
case object N extends Direction
case object S extends Direction
/*
81 cards all unique
shuffle deck
draw 12 cards
maybe<set> findsSET(cqrds)
1 card : 4 features
feature : values
#!/usr/bin/env bash
set -o errexit
solutionDir="$(exercism download --uuid $@)"
echo "$solutionDir"
cd "$solutionDir"
find src/test -type f -print -exec sed -i "s%@Ignore%// @Ignore%g" '{}' \;
gradle clean test
@dpolivaev
dpolivaev / MultiCollectors.java
Created September 25, 2019 08:34
A method creating a single collector given a list of collectors, see https://stackoverflow.com/a/32072206/1833472 "groupingBy with multiple Collectors"
@SuppressWarnings({"null", "unchecked"})
public static <V, R> Collector<V, ?, List<R>> combine(List<Collector<V, ?, R>> collectors) {
final Supplier<List<Object>> supplier = () -> collectors.stream().map(Collector::supplier)
.map(Supplier::get).collect(Collectors.toList());
final BiConsumer<List<Object>, V> biConsumer = (List<Object> list, V e) -> IntStream.range(0, collectors.size())//
.forEach(i -> ((BiConsumer<Object, V>) collectors.get(i).accumulator()).accept(list.get(i), e));
final BinaryOperator<List<Object>> binaryOperator = (List<Object> l1, List<Object> l2) -> {
import static org.junit.Assert.fail;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import javax.persistence.EmbeddedId;
import javax.persistence.IdClass;
import org.reflections.Reflections;