Skip to content

Instantly share code, notes, and snippets.

View toefel18's full-sized avatar
🏄‍♀️
Codesurfer

Christophe Hesters toefel18

🏄‍♀️
Codesurfer
View GitHub Profile
@toefel18
toefel18 / gh_shortcuts.sh
Created August 11, 2023 14:01
Useful GH commands
# close all waiting workflows
gh run list --limit 100 --status waiting --json databaseId --jq '.[].databaseId' | grep -v "USE THIS TO ECLUDE WORKFLOWS" | xargs -l gh run cancel
# close all prs
gh pr list --json number --jq '.[].number' | grep -v "USE THIS TO EXCLUDE A FEW" | xargs -l gh pr close
@toefel18
toefel18 / ConfigurationLoader.kt
Created August 2, 2022 15:18
Hoplite configuration
object ConfigurationLoader {
val log: Logger = LoggerFactory.getLogger(ConfigurationLoader::class.java)
/** Applications should rely on overriding env vars in the default profiles. This mechanism can be simplified */
private val profileKeys = listOf("profileOverride") // used to be "profile", "profiles", "spring.profiles.active"
private fun lazyCheckSystemProperty(name: String): Lazy<String?> = checkProfileVia("system property", name) { System.getProperty(name) }
private fun lazyCheckEnvVar(name: String): Lazy<String?> = checkProfileVia("environment var", name) { System.getenv(name) }
private fun checkProfileVia(source: String, name: String, supplier: () -> String?) = lazy {
@toefel18
toefel18 / IndexingDataStructure.kt
Last active April 4, 2022 18:45
In-memory data structure that can search over multiple fields of an object
class IndexingDataStructure<V>(private val lock: Any = Any()) {
abstract inner class Index<KEY, RETURN>(val name: String, protected val keyFromValueFunc: (value: V) -> KEY) {
abstract fun get(key: KEY): RETURN
internal abstract fun internalIncludeItem(value: V)
}
inner class UniqueIndex<KEY>(name: String, keyFromValueFunc: (value: V) -> KEY, private val map: MutableMap<KEY, V> = mutableMapOf()) : Index<KEY, V?>(name, keyFromValueFunc) {
override fun get(key: KEY): V? = synchronized(lock) { map[key] }
import java.lang.Exception
import kotlin.reflect.KClass
import kotlin.reflect.full.isSubtypeOf
import kotlin.reflect.full.starProjectedType
import kotlin.reflect.jvm.javaType
import org.slf4j.Logger
// the handlers should throw, but this throw is here so we can use Nothing
// as return type. By using Nothing, this method can be called without having
// actually return something
if [ -e $FILE ];
then
echo "Usage:"
echo "FILE=https://some/location/swagger.yml ./run-swagger-ui.sh"
exit 1
fi
curl -s -o swagger.yml $FILE
echo visit http://localhost:8080 rendering docs of $FILE
echo ctrl + c to stop
@toefel18
toefel18 / pre-commit
Last active January 23, 2022 21:01
Git pre-commit hook that applies spotless and adds the files again
#!/bin/bash
set -e
# command taken from https://github.com/JLLeitschuh/ktlint-gradle task addKtlintFormatGitPreCommitHook
filesToFormat="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.kts|\.java|\.kt/ { print $NF}')"
echo "files to format $filesToFormat"
for sourceFilePath in $filesToFormat
do
./gradlew spotlessApply -PspotlessIdeHook="$(pwd)/$sourceFilePath"
data class Entry(
val age: Int,
val name: String,
val ziek: String,
val datum: String,
val afwezig: String
)
fun main() {
@toefel18
toefel18 / Application.java
Last active January 25, 2020 22:29
Performance / blocking / non-blocking
@SpringBootApplication()
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
@Qualifier("completableFutureWorkerPool")
public Executor asyncTaskExecutor() {
return Executors.newCachedThreadPool(new CustomizableThreadFactory("completableFutureWorkerPool-"));
@toefel18
toefel18 / kotlin-html-dsl-tryout
Created December 6, 2019 18:12
kotlin-html-dsl-tryout
package nl.toefel.kotlin.html.dsl
fun html(init: HTML.() -> Unit): HTML {
val html = HTML()
html.init()
return html
}
interface Element {
@toefel18
toefel18 / TodoApp.js
Created February 24, 2019 18:53
React useState TODO app
import React, { useState } from "react";
import uuid from "uuid/v4";
const Todo = ({ todo, deleteTodo }) => {
return (
<li
key={todo.id}
style={{ textDecoration: todo.completed ? "line-through" : "" }}
>
{todo.text} <button onClick={() => deleteTodo(todo.id)}>X</button>