Skip to content

Instantly share code, notes, and snippets.

@gabrieljones
gabrieljones / heap_dump.sh
Last active March 21, 2025 20:08
java heap dump of a java process running in a container without a shell
docker run --pid container:<target-docker-container-name> \
--network container:<target-docker-container-name> \
--rm \
--entrypoint "/opt/java/openjdk/bin/jcmd" \
--user 65532:65532 \
dockerproxy.aexp.com/eclipse-temurin:17 1 GC.heap_dump <some directory the target process can write to>/heap.hprof
# jcmd is not writing the file, it is merely sending a request to the target process to write the heap dump, the target process needs read write perms the file argument: <some directory the target process can write to>/heap.hprof
# 65532 is the user id of distroless/java :nonroot images
# GitHub does not let you push orphan branches. This is the next closest thing. (Null Commit, Empty Commit, Zero Commit)
git config user.name "_"
git config user.email ""
git switch --orphan empty-branch
GIT_AUTHOR_DATE="1970-01-01 00:00:00 +0000" GIT_COMMITTER_DATE="1970-01-01 00:00:00 +0000" git commit --allow-empty --allow-empty-message -m ""
❯ ollama run deepseek-r1:32b
>>> fibonacci sequence in Scala using LazyList.zip
<think>
Okay, so I need to figure out how to generate the Fibonacci sequence in Scala using LazyList.zip. Hmm, let me
start by recalling what a Fibonacci sequence is. It's a series where each number is the sum of the two preceding
ones, usually starting with 0 and 1.
Now, I remember that in Scala, LazyList is similar to streams and allows for lazy evaluation, which is good for
infinite sequences because it doesn't compute all elements upfront. So using LazyList makes sense here since the
Fibonacci sequence can be infinitely long.
package com.gabrieljones
/**
* Represents a set of elements that may or may not exist
* @tparam T the type of the elements in the set
*/
sealed trait ExiSet[T] {
def exists(p: T => Boolean): Boolean
}
@gabrieljones
gabrieljones / fibonacci.kt
Created January 18, 2024 15:05
multiple ways to compute the fiboonacci sequence
package gabrieljones
import com.google.common.math.BigIntegerMath
import java.math.BigDecimal
import java.math.BigInteger
import java.math.MathContext
import java.math.RoundingMode
import kotlin.coroutines.cancellation.CancellationException
fun main() {
@gabrieljones
gabrieljones / runCatchingNonFatal.kt
Last active January 18, 2024 15:00
runCatching that does not catch Fatal throwables and does not catch CancellationException
inline fun <R> runCatchingNonFatal(block: () -> R): Result<R> {
return try {
Result.success(block())
}
catch (t: Throwable) {
when (t) {
// VirtualMachineError includes OutOfMemoryError and other fatal errors
is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError, is CancellationException -> throw t
else -> Result.failure(t)
package com.gabrieljones
import java.util.concurrent.{Executors, ScheduledFuture}
import scala.sys.ShutdownHookThread
object AllLogicInShutdownHook {
def main(args: Array[String]): Unit = {
// schedule executor
println("Adding Hook...")
package com.gabrieljones
import scala.collection.mutable.ListBuffer
object NestedFinally {
def main(args: Array[String]): Unit = {
val es: ListBuffer[Exception] = ListBuffer.empty
try {
try {
throw new Exception("1")
@gabrieljones
gabrieljones / listcerts.sh
Created January 23, 2023 18:56
list the certs of cacerts in a distroless java based container image with the keytool inside the image
docker run --rm --entrypoint="/usr/lib/jvm/java-17-openjdk-amd64/bin/keytool" distroless/java17:nonroot -list -cacerts -storepass changeit
@gabrieljones
gabrieljones / Three Dimensions of a Dependency Version.md
Last active October 13, 2022 14:48
Three Dimensions of a Dependency Version

There are at least three natural dimensions to the modern maven dependency version. Dependency resolution version specifiers should incorporate all three dimensions. As of v7.5.1 Gradle has no mechanism to specify all three dimmensions simultaneously. You can do SemVer Range or latest.release vs latest.integration but not all three at the same time. https://docs.gradle.org/current/userguide/single_versions.html

Proposal: Allow use of all three dimensions simultaneously.

  1. SemVer Range eg
  • 2.15.0