Skip to content

Instantly share code, notes, and snippets.

@cjbrooks12
cjbrooks12 / ImmutableRandom.kt
Created August 16, 2022 18:26
Kotlin Immutable Random
import kotlin.random.Random
/**
* Denotes an instance of [Random] that does not mutate its own internal state. Unlike standard [Random],
* [ImmutableRandom] will always return the same value for subsequent calls to [nextBits], [nextInt], etc. One must
* call [nextRandom] to get a new instance of [ImmutableRandom] with a state that would typically have been updated
* internally.
*
* For the same seed, any sequence of `next*(), nextRandom()` should yield the same result as a normal [Random] calling
@TobseF
TobseF / KorGE-Player-Movement.kt
Created February 25, 2022 10:26
KorGE setup for super smooth player movement by keys or mouse-click
private var destination: Point = player.pos.copy()
private val playerSpeed = 6.0
private val step = 20
init {
addUpdater {
handeKeyboardControls()
}
addFixedUpdater(25.milliseconds) {
if (destination.distanceTo(player.pos) > playerSpeed) {
@mxalbert1996
mxalbert1996 / Scrollbar.kt
Last active December 9, 2025 13:35
Modifiers to draw scrollbars in Jetpack Compose
/*
* MIT License
*
* Copyright (c) 2022 Albert Chang
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@mayankmkh
mayankmkh / PrettyPrint.kt
Last active September 12, 2025 07:39
Pretty Print Kotlin Data Class
fun Any.prettyPrint(): String {
var indentLevel = 0
val indentWidth = 4
fun padding() = "".padStart(indentLevel * indentWidth)
val toString = toString()
val stringBuilder = StringBuilder(toString.length)
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled