Skip to content

Instantly share code, notes, and snippets.

View rocketraman's full-sized avatar

Raman Gupta rocketraman

View GitHub Profile
@rocketraman
rocketraman / DelayTest.kt
Last active October 3, 2023 18:43
Testing resolution of kotlinx coroutines delay
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.time.measureTime
suspend fun main() {
suspend fun delayLoop(delayMillis: Long, delayCount: Int) {
var totalDelay: Long = 0
var maxDelay: Long = 0
repeat(delayCount) {
import org.kodein.di.DirectDIAware
import org.kodein.di.instance
/**
* Auto resolve a class dependencies by using its constructor reference.
* The resolution is done at compile time by leveraging inline functions, no reflection is required.
*
* Example:
* ```
* val myModule = DI.module("myModule") {
schema {
query: Object49
mutation: Object8
}
interface Interface1 {
field3: Enum1!
}
interface Interface2 {
@rocketraman
rocketraman / GoogleCloudJsonEventLayout.json
Created June 30, 2021 22:09
Google Cloud JsonEventTemplate layout
{
"timestamp": {
"$resolver": "timestamp",
"pattern": {
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"timeZone": "UTC",
"locale": "en_US"
}
},
"severity": {
@rocketraman
rocketraman / ContextualCalendarDayWindow.kt
Last active June 23, 2021 20:25
Beam calendar day windows with context elements
package com.xacoach.xascore.backend.analytics.windowfns
import org.apache.beam.sdk.coders.Coder
import org.apache.beam.sdk.transforms.*
import org.apache.beam.sdk.transforms.windowing.*
import org.apache.beam.sdk.values.KV
import org.apache.beam.sdk.values.PCollection
import org.apache.beam.sdk.values.TypeDescriptor
import org.apache.beam.sdk.values.TypeDescriptors
import org.joda.time.DateTimeZone
@rocketraman
rocketraman / external-dns-nodes-gke.sh
Last active August 4, 2020 20:16
External DNS script for handling node port services, which is not supported yet by External DNS upstream - see https://github.com/kubernetes-sigs/external-dns/issues/1210#issuecomment-668729798
#!/usr/bin/env bash
usage() {
echo >&2 "Invalid environment and/or arguments specified"
exit 1
}
# settings
project_id=${PROJECT_ID:-$1}
zone=${ZONE:-$2}
@rocketraman
rocketraman / passwordsync
Last active November 5, 2023 10:53
Keepassxc password sync using rclone
#!/usr/bin/env bash
#
# Copyright 2020 Raman Gupta
# LICENSE: https://opensource.org/licenses/MIT
# https://gist.github.com/rocketraman/820d94f2f9c8731a6f2d56cbc2ddb60f
#
# Syncs a local keepassxc database with a remote source via rclone.
# The basic process is:
# 1) rclone copy to temporary local location
# 2) use keepassxc cli to merge the remote database into the local one
@rocketraman
rocketraman / scans-init.gradle.kts
Last active April 28, 2020 18:05
Enable build scans for all builds via `~/.gradle/init.d/scans-init.gradle.kts`
import com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin
import com.gradle.scan.plugin.BuildScanPlugin
import org.gradle.util.GradleVersion
initscript {
val pluginVersion = "3.2.1"
repositories {
gradlePluginPortal()
}
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class TestLogging {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.info("This is a test.", new Exception("Test exception!"));
}
}
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class TestLogging {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.info("Start");
logger.info("This is a test.", new Exception("Test exception!"));
logger.info("End");