Skip to content

Instantly share code, notes, and snippets.

View Jellymath's full-sized avatar

Alexander Levin Jellymath

View GitHub Profile
@Jellymath
Jellymath / JacksonGet.kt
Created January 27, 2020 13:35
Provide unsafe version of single function get
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
val defaultMapper = ObjectMapper()
val defaultMapperContext = MapperContext(defaultMapper)
class MapperContext(val mapper: ObjectMapper) {
inline operator fun <reified T> JsonNode.get(vararg params: Any): T {
var current = this
for (param in params) {
package inlineEnumSet
import java.util.EnumSet
inline class InlineEnumSet<T : Enum<T>>(val set: UInt) {
companion object
}
//bit extraction functions
@Jellymath
Jellymath / MaxPathGraph.kt
Last active April 29, 2019 20:06
MaxPath
import java.lang.IllegalStateException
fun main() {
node(5) {
left(3) {
left(2) {
left(3)
right(6)
}
}
@Jellymath
Jellymath / Scripting.kt
Last active January 8, 2019 03:53
Answer code for XTANCE
import javax.script.ScriptEngine
import javax.script.ScriptEngineManager
import kotlin.reflect.KProperty
fun main(args: Array<String>) {
with(ScriptEngineManager().getEngineByExtension("kts")) {
// val x by value { 3 }
// println(x)
// val x = value("x", 3)
@Jellymath
Jellymath / Permutations.kt
Last active October 12, 2018 09:41
Some permutation fun code
fun main() {
println(listOf(1, 2, 2).permutations())
println(listOf(1, 2, 2).permutationsFromScala())
println(listOf(1, 2, 2).permutationsFromScala(distinct = true))
}
fun <T> Collection<T>.permutations(): List<List<T>> = when (size) {
0 -> emptyList()
1 -> listOf(listOf(first()))
else -> flatMapIndexed { i, x ->