Skip to content

Instantly share code, notes, and snippets.

View libetl's full-sized avatar

LiBe libetl

View GitHub Profile
@libetl
libetl / KotlinBuilderTest.kt
Created October 17, 2018 21:49
simplest kotlin builder
fun main(args: Array<String>) {
val choosenMenu = menu {
fish
chips
hamburger
}
println(choosenMenu)
}
@libetl
libetl / RestTemplateInjector.kt
Last active October 31, 2018 20:33
RestTemplateInjector
package com.myservice.infra.testinterceptor
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.http.HttpRequest
import org.springframework.http.HttpStatus
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.ClientHttpResponse
import org.springframework.mock.http.client.MockClientHttpResponse
import java.io.File
@libetl
libetl / XmlToMap.java
Last active February 28, 2024 23:06
XmlToMap (Java + Kotlin)
package xmltomap;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@libetl
libetl / Router.kt
Last active December 30, 2020 18:17
Router
package org.toilelibre.libe
import java.lang.reflect.Method
import kotlin.math.pow
import kotlin.reflect.KFunction
import kotlin.reflect.full.companionObject
import kotlin.reflect.full.companionObjectInstance
import kotlin.reflect.full.declaredFunctions
import kotlin.reflect.full.memberProperties
@libetl
libetl / CreditCardNumberChecker.ts
Created November 10, 2019 19:52
CreditCardNumberChecker.ts
type CardType = 'MasterCard' | 'Visa' | 'American Express' |
'JCB' | 'Diners Club' | 'Discover' | 'unknown'
type MajorIndustryIdentifier =
'ISO/TC 68' | 'Airlines' | 'Travel and entertainment and banking/financial' |
'Banking and financial' | 'Merchandising and banking/financial' |
'Petroleum' | 'Healthcare and telecommunications' | 'National assignment' |
'unknown'
type CreditCardGuessedInformation = {
@libetl
libetl / fakemoment.ts
Created November 30, 2019 20:18
Fake moment.js
const moment = function moment(textValue: string | number, format: string) {
const timeOfTheDay = /^([0-9]{1,2}):([0-9]{1,2})$/.exec((textValue || "").trim())
const onlyTime = timeOfTheDay && new Date()
if (onlyTime && timeOfTheDay) onlyTime.setHours(parseInt(timeOfTheDay[1]), parseInt(timeOfTheDay[2]))
const date = !textValue ? new Date() :
!isNaN(textValue as number) ? new Date(textValue) :
!(textValue as string).trim() ? new Date() :
onlyTime ? onlyTime : new Date(textValue)
return {
date,
@libetl
libetl / x2plusy2below1.json
Created June 1, 2020 15:47
neuralNetworkWeightsAndBiasesExample
{"weightsAndBiases":[[{"bias":-0.10071499664092819,"weights":[]},{"bias":-0.15018810063963497,"weights":[]}],[{"bias":-2.8468035812909434,"weights":[5.45721869905237,-3.148199059174658]},{"bias":-5.242078727744964,"weights":[-3.3284653639142725,10.876261776883684]},{"bias":-12.976066169035779,"weights":[36.003431279150426,6.242494143417826]},{"bias":-20.989904892589315,"weights":[13.402075212498223,51.79564730855186]}],[{"bias":-5.425858592065819,"weights":[-58.58740543154484,-32.269696973037284,18.54140361818438,10.084452534168838]}]],"parameters":["x","y"],"theory":"x^2+y^2<1","layersLength":[2,4,1]}
@libetl
libetl / DatabaseSimulator.kt
Created July 31, 2020 17:26
DatabaseSimulator.kt
import io.mockk.every
import io.mockk.mockk
import java.sql.*
import java.time.ZonedDateTime
import javax.sql.DataSource
object DatabaseSimulator {
val registeredSQLServerMappings = mutableMapOf<String, ResultSet>()
val calledStatements = mutableListOf<String>()
package com.mycompany.infra.config
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.coroutineScope
@libetl
libetl / LoadYaml.kt
Created October 31, 2020 13:21
LoadYaml.kt
package com.mycompany.library.tools
import org.springframework.boot.env.YamlPropertySourceLoader
import org.springframework.core.env.ConfigurableEnvironment
import org.springframework.core.env.Profiles
import org.springframework.core.io.ClassPathResource
object LoadYaml {
data class LoadOptions(