Skip to content

Instantly share code, notes, and snippets.

@juan-medina
juan-medina / dbom.kt
Created July 29, 2020 10:39
watter bomb kotlin
import kotlin.math.ceil
infix fun String.watterBomb(size: Int) = this.split("Y").map{
ceil(it.length / size.toDouble()).toInt()
}.sum()
fun main() {
println("xxYxx" watterBomb 3 == 2)
println("xxYxx" watterBomb 1 == 4)
println("xxxxYxYx" watterBomb 5 == 3)
@juan-medina
juan-medina / commands.kt
Last active June 25, 2020 14:19
creating commands options
Command("example command"
"attribute1" to "value1",
"attribute2" to 123,
"attribute3" to false,
"attribute4" to 125.5
)
Command.create("example command"
"attribute1" to "value1",
"attribute2" to 123,
@juan-medina
juan-medina / PetCommands.kt
Last active June 7, 2020 18:34
kafka pets
package org.learning.by.example.petstore.petcommands.service
import org.learning.by.example.petstore.petcommands.model.Pet
import reactor.core.publisher.Mono
interface PetCommands {
fun sendPetCreate(monoPet: Mono<Pet>): Mono<String>
}
/*
* Copyright (c) 2020 Learning by Example maintainers.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@juan-medina
juan-medina / quest.py
Created March 13, 2020 14:31
fibonacci jetbrains quest
import math
def fib(n):
F = [[1, 1], [1, 0]];
if (n == 0):
return 0;
power(F, n - 1);
return F[0][0];
@juan-medina
juan-medina / AnimalRace.java
Created January 12, 2020 09:39
AnimalRace.java
package com.juan.medina;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
public class AnimalRace {
public static final int RACE_LENGTH = 1000;
VerbalExpression regex = regex()
.startOfLine()
.then("+")
.capture().range("0", "9").count(3).maybe("-").maybe(" ").endCapture()
.count(3)
.endOfLine().build();
VerbalExpression regex = expresion {
@juan-medina
juan-medina / persons.kt
Last active December 10, 2019 20:35
persons.kt
data class Person(var name: String, var age: Int)
class PersonContainer {
private val list = arrayListOf<Person>()
fun add(person: Person) = list.add(person)
fun get(): List<Person> = list
infix fun String.with(age: Int) = Person(this, age)
}
fun persons(init: PersonContainer.() -> Unit): List<Person> {
@juan-medina
juan-medina / CombineData.kt
Created December 3, 2019 10:48
Kata04: Data Munging
import java.io.File
open class CombineData(private val fileName: String) {
private fun getColumnValue(line: String, column: Pair<Int, Int>): String {
return line.substring(column.first, column.first + column.second - 1).trim().replace("*", "")
}
fun calculate(
value: Pair<Int, Int>,
@juan-medina
juan-medina / ContactsAgendaTests.kt
Created December 1, 2019 11:52
kotlin-contacts-agenda
import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import org.junit.jupiter.api.Test
import java.io.File
// Implement a Phone Directory
//
// Given a list of contacts which exist in a phone directory. The task is to implement search query for the phone directory.
// The search query on a string ‘str’ displays all the contacts which prefix as ‘str’.