Skip to content

Instantly share code, notes, and snippets.

View Wavesonics's full-sized avatar

Adam Brown Wavesonics

View GitHub Profile
@Wavesonics
Wavesonics / DropDown.kt
Last active January 14, 2023 00:43
A Dropdown box composable
@Composable
fun <T> DropDown(
modifier: Modifier = Modifier,
padding: Dp = 16.dp,
items: List<T>,
defaultIndex: Int = 0,
onValueChanged: (T) -> Unit
) {
var selectedIndex by remember { mutableStateOf(defaultIndex) }
var itemsExpanded by remember { mutableStateOf(false) }
@Wavesonics
Wavesonics / DiffusionHeatMap.cpp
Created March 13, 2020 07:03
Thermal diffusion algirothm
void DiffusingHeatMap::_physics_process(float delta)
{
clearBackBuffer();
for(int yy = 0; yy < mapSize; ++yy)
{
for(int xx = 0; xx < mapSize; ++xx)
{
diffuse(xx, yy);
}
@Wavesonics
Wavesonics / WallClockTimer.gd
Last active February 7, 2023 22:21
A real-time timer for synchronizing events in Godot across multiple clients to within 1 second of each other, which for my use case was good enough. It's API is meant to be a drop-in replacement for the default Timer node. Additionally it solved the problem of Timers in Godot being effected by poor performance. On a slower computer that is being…
# A drop in replacement for the Timer class
# This timer is completely framerate independent
# It can also be given a unix time stamp instead of a duration
# for when it should fire. This is useful for synchornizing events
# across multiple clients such as in Multiplayer
extends Node
class_name WallClockTimer, 'res://utilities/wallclock_timer/icon.png'
signal timeout
####################
# Map_00.gd
####################
func _ready():
create_players(Network.players)
func create_players(players):
for player_id in players:
var player = players[player_id]
match player.type:
@Wavesonics
Wavesonics / Argument.kt
Created December 13, 2018 20:00
Kotlin newInstance() Fragment pattern
/**
* Eases the Fragment.newInstance ceremony by marking the fragment's args with this delegate
* Just write the property in newInstance and read it like any other property after the fragment has been created
*
* Inspired by Adam Powell, he mentioned it during his IO/17 talk about Kotlin
*/
class Argument<T : Any> : kotlin.properties.ReadWriteProperty<Fragment, T>
{
var value: T? = null
@Wavesonics
Wavesonics / Movie.kt
Created November 17, 2018 00:39
Best practices data class in Kotlin
data class Movie(var name: String, var studio: String, var rating: Float)
@Wavesonics
Wavesonics / Movie.java
Created November 17, 2018 00:38
Best practices data class in Java
public class Movie {
private String name;
private String studio;
private float rating;
public Movie(String name, String studio, float rating) {
this.name = name;
this.studio = studio;
this.rating = rating;
@Wavesonics
Wavesonics / Optimus.kt
Created October 24, 2018 01:44
Kotlin implementation of Optimus integer hashing algorithm https://github.com/jenssegers/optimus
class Optimus(private val prime: Int,
private val randomNumber: Int,
private val modInverse: Int = ModInverse(prime))
{
init
{
if (!isProbablyPrime(prime)) throw IllegalArgumentException("$prime is not a prime number")
}
fun encode(n: Int): Int = n * this.prime and MAX_INT xor this.randomNumber
body:before {
background: url( {IMAGE} ) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
content: "";
display: block;
@Wavesonics
Wavesonics / RouteHelper.kt
Created September 11, 2018 06:19
Route helper with params
class RouteHelper(private val router: Router) : BasicValueHelper()
{
override fun execute(options: Options?)
{
if( options != null )
{
val parameters = options.parameters
if( parameters != null && parameters.isNotEmpty() )
{
val routeName = parameters[0] as String