Skip to content

Instantly share code, notes, and snippets.

@Gopinathp
Gopinathp / hourly.sh
Last active November 25, 2021 17:42
cron schedule bash script
#!/bin/bash
. /home/gopinath/.bashrc
cd $HOME
export JAVA_HOME=/home/gopinath/.sdkman/candidates/java/current
export PATH=/usr/local/bin:$PATH
export PATH=/usr/bin:$PATH
export PATH=/home/gopinath/.sdkman/candidates/java/current/bin:$PATH
export PATH=/home/gopinath/.sdkman/candidates/kotlin/current/bin:$PATH
export PATH=/home/gopinath/.sdkman/candidates/kscript/current/bin:$PATH
kscript /home/gopinath/backupper.kts -b prod_backups -d prod_db,client_db -v -r
@Gopinathp
Gopinathp / FoodOrdersManagerTest.kt
Created December 7, 2021 19:47
Added mongodb container test sample
import kotlinx.coroutines.runBlocking
import org.bson.types.ObjectId
import org.junit.*
import org.junit.Assert.*
import org.testcontainers.containers.MongoDBContainer
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy
import org.testcontainers.utility.DockerImageName
import java.math.BigInteger
@Gopinathp
Gopinathp / atomics.kt
Last active July 14, 2022 22:50
Atomics.kt implementation
import java.util.concurrent.atomic.AtomicReference
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
private fun <T>atomicNullable(tIn: T? = null): ReadWriteProperty<Any?, T?> {
return object : ReadWriteProperty<Any?, T?> {
val t = AtomicReference<T>(tIn)
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
return t.get()
@Gopinathp
Gopinathp / ReferencesDelegates.kt
Last active December 19, 2021 15:20
Idiomatic kotlin delegate method of using weak reference and soft reference in Java.
package delegates
import java.lang.ref.SoftReference
import java.lang.ref.WeakReference
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
fun <T>weakReference(tIn: T? = null): ReadWriteProperty<Any?, T?> {
return object : ReadWriteProperty<Any?, T?> {