Skip to content

Instantly share code, notes, and snippets.

import kotlinx.coroutines.delay
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
suspend fun multiplyWithDelay(a: Int, b: Int): Int {
delay(10.seconds)
return a * b
}
import java.util.Comparator
import java.util.PriorityQueue
import kotlin.math.absoluteValue
import kotlin.math.ceil
fun main() {
val input = listOf(
"..f.......",
"..w.......",
".fxfxx....",
fun main() {
val s3Client = S3Client()
val httpClient = HttpClient()
val rabbitMqClient = RabbitMqClient()
val jsonMapper = JsonMapper()
val userRepo = UserRepo()
val orderRepo = OrderRepo()
val auth = Auth()
val inventoryClient = InventoryClient(httpClient, jsonMapper)
val taxesClient = TaxesClient(httpClient, jsonMapper)
fun main(){List(3){readLine()!!.toDouble()}.run{Math.pow(max(),min())}}
@mkulak
mkulak / aoc1.kt
Last active December 3, 2022 18:33
fun main() {
println(solve1(File("input1.txt").readLines()))
}
fun solve1(input: List<String>): Int =
input.fold(0 to 0) { (m, acc), str -> if (str.isEmpty()) Math.max(m, acc) to 0 else m to acc + str.toInt() }.first
fun solve2(input: List<String>): Int =
input.fold(arrayListOf(0)) { acc, str -> if (str == "") acc.add(0) else acc[acc.lastIndex] += str.toInt(); acc }.sortedBy { -it }.take(3).sum()
import java.time.LocalDate;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class DaysCalculator {
public static int calculate(List<Interval> input) {
TreeMap<LocalDate, Boolean> map = new TreeMap<LocalDate, Boolean>(); // true - begin, false - end
for (Interval interval : input) {
@Test fun `getSpaceUsers should return 403 if user is not host`() = testBlocking {
val owner = createUser()
val spaceId = createSpace(owner.token)
val user = createUser()
val res = client.getSpaceUsers(user.token, spaceId)
assertEquals(HttpStatus.FORBIDDEN, res.status)
res.assertJsonContentTypeHeader()
res.assertCorsHeaders()
}
import aiohttp
import asyncio
import time
import random
# pip3 install aiohttp requests
async def main():
pokemon_url = 'https://pokeapi.co/api/v2/pokemon'
Haskell:
bots: 5000 bots: 5000
rooms: 500 rooms: 500
duration: 60s duration: 60s
sent packets: 1441186 (24019 packets/s) sent packets: 1678676 (27977 packets/s)
received packets: 901162 (15019 packets/s) received packets: 1168579 (19476 packets/s)
total bytes sent: 51677387 (35 bytes/packet) total bytes sent: 60193385 (35 bytes/packet)
total bytes received: 39414269 (43 bytes/packet) total bytes received: 53018078 (45 bytes/packet)
room-update-latency: room-update-latency:
0.5 percentile - 176 ms 0.5 percentile - 104 ms
public class Foo {
public static void main(String[] args) {
Float naN = Float.NaN;
System.out.println(naN instanceof Number);
}
}
Output:
> true