Skip to content

Instantly share code, notes, and snippets.

View gaplo917's full-sized avatar
🎯
Focusing on Kotlin

Gary Lo gaplo917

🎯
Focusing on Kotlin
View GitHub Profile
@gaplo917
gaplo917 / channelFlow.kt
Created November 27, 2022 01:36
Concurrent Stream Processing is easy in Kotlin using ChannelFlow, https://t.me/gaplotechd/24265
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
data class ItemDetails(val data: Any)
val current by lazy { System.currentTimeMillis() }
val timeDiff: Long get() = System.currentTimeMillis() - current
fun logWithElapseTime(s: String) = println("Elapsed ${timeDiff}ms - $s")
@gaplo917
gaplo917 / gradle.properties
Created August 18, 2022 15:47
Gradle >= 7.3 properties
# greatly reduce build time
# https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching=true
# potentially increase build speed if the gradle task can be parallel
# https://docs.gradle.org/current/userguide/performance.html#parallel_execution
org.gradle.parallel=true
# watch file system
# https://blog.gradle.org/introducing-file-system-watching
@gaplo917
gaplo917 / web.js
Last active February 24, 2022 08:11
GCP X GT Water fight
// https://github.com/GoogleCloudPlatform/cloudbowl-microservice-game.git
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.get('/', function (req, res) {
res.send('Let the battle begin!');
});
@gaplo917
gaplo917 / lazyObservable.kt
Created October 8, 2020 09:01
Lazy Delegate Observable
import kotlin.reflect.KProperty
fun someContextValueGetter(): Int {
println("Getting Context Value")
return 999
}
abstract class LazyObs<T> : kotlin.properties.ReadWriteProperty<Any?, T> {
private val initialValue by lazy { provideInitialValue() }
private var value: T? = null
@gaplo917
gaplo917 / wRPC.js
Created September 16, 2020 11:20
Web Worker RPC Impl
export const status = {
OK: 0,
CANCELLED: 1,
INVALID_ARGUMENT: 3,
UNIMPLEMENTED: 12,
INTERNAL: 13,
}
/**
*
@gaplo917
gaplo917 / flatten.js
Created April 24, 2020 17:37
Quick Node Script to flatten JSON
// https://stackoverflow.com/questions/19098797/fastest-way-to-flatten-un-flatten-nested-json-objects
function flatten(data) {
const result = {}
function recurse(cur, prop) {
if (Object(cur) !== cur) {
result[prop] = cur
} else if (Array.isArray(cur)) {
for (let i = 0, l = cur.length; i < l; i++)
recurse(cur[i], prop + '[' + i + ']')
@gaplo917
gaplo917 / main.kt
Created May 8, 2019 11:19
Kotlin DynamoDB Object Mapping Sample
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.client.builder.AwsClientBuilder
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
import com.amazonaws.services.dynamodbv2.datamodeling.*
import com.amazonaws.services.dynamodbv2.model.BillingMode
import com.amazonaws.services.dynamodbv2.model.ResourceInUseException
import java.math.BigDecimal
import java.util.*
@gaplo917
gaplo917 / IntelliJ IDEA.app.vmoptions
Last active February 4, 2024 02:20
IntelliJ IDEA Java 17 ZGC VM Options
# Personal Feeling: using the following jvm config is smoother than default
# My Machine: Macbook pro M1max 64GB
# More Info: https://github.com/FoxxMD/intellij-jvm-options-explained
# Prerequisite (Intellij < 2022.2)
# 1. Install JetBrain Runtime 17 osx-aarch64 for Apple Silicon, https://github.com/JetBrains/JetBrainsRuntime/releases
# 2. Switch the runtime from JetBrain Runtime 11 to 17, https://www.jetbrains.com/help/idea/switching-boot-jdk.html
# JetBrain Toolbox
// Kotlin
open class AAA {
fun honey(){}
}
interface BBB {
fun empire(){}
}
abstract class CCC {
fun bleed() {}
// Dart
class AAA {
void honey() {}
}
abstract class BBB {
void empire() {}
}
mixin CCC {
void bleed() {}
}