Skip to content

Instantly share code, notes, and snippets.

View patxibocos's full-sized avatar
🚴

Patxi Bocos patxibocos

🚴
View GitHub Profile
@patxibocos
patxibocos / AnagramCalculator.kt
Last active June 19, 2023 22:55
AnagramCalculator.kt
class AnagramCalculator(private val wordsDictionary: Collection<String>) {
private fun findAnagrams(
word: String,
dictionary: Collection<String>,
acc: String = "",
): Collection<String> {
if (word.isEmpty() || dictionary.isEmpty()) {
return dictionary
}
@patxibocos
patxibocos / GridCanvas.kt
Created April 21, 2021 18:04
GridCanvas.kt
package com.patxi.intellijsplashscreen
import androidx.compose.foundation.Canvas
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.translate
import androidx.compose.ui.unit.IntSize
@patxibocos
patxibocos / IntelliJSplashScreen.kt
Last active May 10, 2021 21:46
IntelliJSplashScreen.kt
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.translate
import androidx.compose.ui.tooling.preview.Preview
@patxibocos
patxibocos / requestOverrideRuleExample.kt
Last active May 20, 2020 17:02
requestOverrideRuleExample.kt
@get:Rule
RequestOverrideRule(
MockedRequest(
method = GET,
url = "/example/endpoint",
jsonBody = json {
"intProperty" to 0
"stringProperty" to "test"
}
)
@patxibocos
patxibocos / consumeChannel.kt
Created May 16, 2020 18:01
consumeChannel.kt
scope.launch {
overrideChannel.consumeEach { mockedRequest ->
server.application.routing {
val httpAction: Route.(String, PipelineInterceptor<Unit, ApplicationCall>) -> Route =
when (mockedRequest.method) {
HttpMethod.GET -> Route::get
HttpMethod.POST -> Route::post
HttpMethod.PUT -> Route::put
}
httpAction(mockedRequest.url) {
@patxibocos
patxibocos / testRunnerCoroutines.kt
Created May 16, 2020 18:00
testRunnerCoroutines.kt
private val job = Job()
private val scope = CoroutineScope(job + Dispatchers.Default)
private val overrideChannel = Channel<MockedRequest>(Channel.UNLIMITED)
@patxibocos
patxibocos / requestOverrideRule.kt
Created May 16, 2020 17:59
requestOverrideRule.kt
class RequestOverrideRule(private vararg val mockedRequests: MockedRequest, private val overrideChannel: SendChannel<MockedRequest> = get().koin.get()) : TestRule {
override fun apply(statement: Statement, description: Description): Statement {
return object : Statement() {
override fun evaluate() {
mockedRequests.forEach {
overrideChannel.offer(it)
}
statement.evaluate()
}
}
@patxibocos
patxibocos / applicationOnCreate.kt
Created May 16, 2020 17:59
applicationOnCreate.kt
override fun onCreate(savedInstanceState: Bundle?) {
...
startKoin {
modules(..., environmentKoinModule, ...)
}
...
}
@patxibocos
patxibocos / overrideUrlsDataStore.kt
Created May 16, 2020 17:58
overrideUrlsDataStore.kt
environmentKoinModule.factory<UrlsDataStore>(override = true) {
val httpAddress = "localhost:8080"
object : UrlsDataStore {
override val api = httpAddress
override val bff = httpAddress
...
}
}
@patxibocos
patxibocos / ktorRouting.kt
Created May 16, 2020 17:58
ktorRouting.kt
get("path/to/get") {
call.respondText("Hello GET!")
}
post("path/to/post") {
call.respondText("Hello POST!")
}