Skip to content

Instantly share code, notes, and snippets.

View MuyembeII's full-sized avatar
🎯
Focusing

GMuyembe Jr MuyembeII

🎯
Focusing
  • Chilanga
View GitHub Profile
@3v1n0
3v1n0 / map-string-any-kotlin-serialization-tests.kt
Last active September 25, 2023 18:15
Kotlin Map<String, Any?> (andy Any type in general) (de)serialization tests with both Binary (CBOR) and JSON support
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.CompositeDecoder
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*
import kotlin.reflect.KType
import kotlin.reflect.full.isSubtypeOf
import kotlin.reflect.full.starProjectedType
@wturnerharris
wturnerharris / mysql_procedure_loop_ids_and_insert.sql
Created April 17, 2019 16:25
Here's a mysql stored procedure to loop through the results of a select query that returns ids and performs an additional operation on each id.
DROP PROCEDURE IF EXISTS migrateById;
DELIMITER $$
CREATE PROCEDURE migrateById()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE _post_id INT;
DECLARE migrate_ids CURSOR FOR
# modify the select statement to returns IDs, which will be assigned the variable `_post_id`
@kilink
kilink / KotlinDataDeserializer.kt
Created June 22, 2017 01:22
Kotlin data class deserializer
@JsonDeserialize(using = KotlinDataDeserializer::class)
data class Foo(val x: String, val y: String, val z: Int)
class KotlinDataDeserializer : StdDeserializer<Foo>(Foo::class.java) {
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): Foo {
return p.readValueAs(Foo::class.java)
}
override fun deserialize(p: JsonParser, ctxt: DeserializationContext, intoValue: Foo): Foo {
val copy = intoValue::copy
@hansenji
hansenji / JacksonKotlinModuleExample.kt
Created April 4, 2017 19:43
Jackson Kotlin Module Example
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
fun main(args: Array<String>) {
// val mapper = ObjectMapper().registerModule(KotlinModule())
// val mapper = ObjectMapper().registerKotlinModule()
val mapper = jacksonObjectMapper()
val writer = mapper.writerWithDefaultPrettyPrinter()
val json1 = writer.writeValueAsString(Data1(1, "Foo", "Bar"))
@remen
remen / fun_with_kotlin_and_jackson.kt
Last active October 17, 2021 08:59
Fun with kotlin and jackson
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
fun main(args: Array<String>) {
val jsonString : String = """
{
"authors" : [
{
"name" : "Kalle Jönsson",
@gorangajic
gorangajic / es6-spread-immutable-cheatsheet.md
Last active April 11, 2024 08:32
es6 spread immutable cheatsheet

update object

var state = {
    id: 1,
    points: 100,
    name: "Goran"
};

var newState = {