Skip to content

Instantly share code, notes, and snippets.

@ncomet
ncomet / tdd.go
Last active August 2, 2021 13:00
import "fmt"
import "testing"
func SomeArrangeFunction() (string, error) {
// stuff
}
func SomeFunctionUnderTest(arg string) string {
// stuff
}
{
"key": 3.4,
"anotherKey": [
"test",
"test2",
1,
2.433,
true
],
"nullValue": null,
{"key":3.4,"anotherKey":["test","test2",1,2.433,true],"nullValue":null,"emptyObject":{},"emptyArray":[],"custom":"2020-07-15T10:59:19.042965+02:00[Europe/Paris]"}
@ncomet
ncomet / src.kt
Created September 16, 2020 08:54
val obj = obj {
"key" to 3.4
"anotherKey" to arr["test", "test2", 1, 2.433, true]
"nullValue" to null
"emptyObject" to obj { }
"emptyArray" to arr
"custom" to ZonedDateTime.now()
}
println(obj) // 1
@ncomet
ncomet / src.kt
Created September 16, 2020 08:52
"""
|{
| "cat": "meow",
| "dog": "woof"
|}
""".trimMargin()
@ncomet
ncomet / src.kt
Created September 16, 2020 08:43
"""{
"cat": "meow",
"dog": "woof"
}""".trimIndent()
@ncomet
ncomet / Anagrams.kt
Last active April 24, 2021 16:16
Anagrams in Kotlin
// we create a sequence that generates prime numbers
fun primes(): Sequence<Long> {
var i = 2L
return generateSequence { i++ }
.filter { n -> (2L until n).none { n % it == 0L } }
}
// we map chars to a unique prime
val charToPrime = ('a'..'z').zip(primes().take(26).toList()).toMap()
val outcome = bookingService.bookRoom(RoomID("roomIwant"))
when (outcome) {
}
interface BookingService {
fun bookRoom(roomId: RoomID): BookingOutcome
}
sealed class BookingOutcome
class RoomBooked(key: Key, bookingRange: ClosedRange<Instant>) : BookingOutcome()
object RoomNotAvailable : BookingOutcome()
object HotelClosed : BookingOutcome()