Skip to content

Instantly share code, notes, and snippets.

View ygrenzinger's full-sized avatar

Yannick Grenzinger ygrenzinger

View GitHub Profile
@ygrenzinger
ygrenzinger / AsciiArt.kt
Created April 30, 2020 18:55
Jetbrains Academy AsciiArt
package signature
import java.io.File
import java.util.*
data class AsciiFontChar(val letter: Char, val width: Int, val lines: List<String>) {
operator fun get(index: Int) = lines[index]
override fun toString() = lines.joinToString("\n")
}
@ygrenzinger
ygrenzinger / UnitConverter.kt
Created April 28, 2020 19:07
Unit Converter exercise on Jetbrain academy
package converter
import java.util.*
interface Unit {
fun label(): String
fun type(): String
fun <T : Unit> conversionMessage(x: Double, destination: T): String
fun conversionMessage(x: Double, destination: String): String {
return findUnit(destination)?.let {
@ygrenzinger
ygrenzinger / gist:1b430802b684719b342cdbd17bec7a9a
Created February 29, 2020 13:27
A way to reproduce the conflict between REMOTE/Git and convert/generateTests goals
How to reproduce :
clone this repo https://github.com/magelle/devoxx2020-contract-testing
in inventory project run Spring Cloud Contract plugin : No problem
You can then create a git repository. A local one is good enough, like explained [there](https://github.com/magelle/devoxx2020-contract-testing/blob/master/README.md#part-2)
You can add the following configuration :
<contractsMode>REMOTE</contractsMode>
<contractsRepositoryUrl>git://file:///Users/ygrenzinger/git/test.git</contractsRepositoryUrl>
@ygrenzinger
ygrenzinger / FiniteGrid.scala
Created November 15, 2019 09:26
F-Bound Scala
package gameoflife
import scala.collection.immutable.Seq
case class FiniteGrid(override val size: Int, override val rows: Seq[Row]) extends Grid[FiniteGrid](size: Int, rows: Seq[Row]) {
override def changeCellAt(position: (Int, Int), state: CellState): FiniteGrid =
FiniteGrid(size, changeRowsAt(rows, position, state))
}
object FiniteGrid {
@ygrenzinger
ygrenzinger / BowlingScoreCalculator.hs
Created August 14, 2019 23:52
Bowling Kata in Haskell
module ScoreCalculator ( bowlingScore ) where
import Data.Char
data Roll = Strike | Spare | PinHit Int deriving Eq
parseRawRolls :: String -> [Roll] -> [Roll]
parseRawRolls [] rolls = reverse rolls
parseRawRolls (' ' : rest) rolls = parseRawRolls rest rolls
parseRawRolls ('-':rest) rolls = parseRawRolls rest ((PinHit 0) : rolls)
@ygrenzinger
ygrenzinger / bolwing_kata.dart
Created August 7, 2019 20:32
Bowling Kata in Dart
import 'package:cli/cli.dart';
import 'package:test/test.dart';
// https://learnxinyminutes.com/docs/dart/
// http://codingdojo.org/kata/Bowling/
int parseRoll(String roll) {
if (roll == 'X') {
return 10;
}
@ygrenzinger
ygrenzinger / BoardImpl.kt
Created May 30, 2019 16:32
Coursera Kotlin
package board
import board.Direction.*
class SquareBoardImpl(private val size: Int, private val cells: List<Cell>) : SquareBoard {
constructor(width: Int) : this(width, createCells(width))
override val width: Int
get() = size
@ygrenzinger
ygrenzinger / MockkSlowness.kt
Created May 14, 2019 19:03
Mockk slowness
package com.kata.tetris
import io.mockk.every
import io.mockk.mockk
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
/*
<dependency>
@ygrenzinger
ygrenzinger / README.md
Created April 15, 2019 14:45
Tetris Kata

Tetris Kata

This kata is intended to simulate a game of Tetris.

The point of this kata to to provide a larger than trivial exercise that can be used to practice TDD. A significant portion of the effort will be in determining what tests should be written and, more importantly, written next.

Considerations:

  • Multi-threading should not be a consideration. This should be done in a single thread.
  • Drawing the board is a bonus feature, and is not required in order to solve the problem.
  • For the purpose of the kata we do not need a true "game loop". We simply need to implement the rules in such a way as to advance the game state.
@ygrenzinger
ygrenzinger / FooBarQix.java
Created April 8, 2019 18:43
FooBarQix Polytech
package com.course.polytech;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class FooBarQix {
private static Map<Integer, String> NUMBER_2_STRING = new HashMap<>();