This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.flow.* | |
fun Flow<ByteArray>.toLineFlow(): Flow<String> = flow { | |
val buffer = StringBuilder() | |
val decoder = Charsets.UTF_8.newDecoder() | |
collect { byteArray -> | |
val charBuffer = decoder.decode(java.nio.ByteBuffer.wrap(byteArray)) | |
buffer.append(charBuffer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator | |
import java.util.PriorityQueue | |
import kotlin.math.absoluteValue | |
import kotlin.math.ceil | |
fun main() { | |
val input = listOf( | |
"..f.......", | |
"..w.......", | |
".fxfxx....", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(){List(3){readLine()!!.toDouble()}.run{Math.pow(max(),min())}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
import asyncio | |
import time | |
import random | |
# pip3 install aiohttp requests | |
async def main(): | |
pokemon_url = 'https://pokeapi.co/api/v2/pokemon' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder