Skip to content

Instantly share code, notes, and snippets.

View danielocampo2's full-sized avatar

Daniel Ocampo danielocampo2

  • Remote
View GitHub Profile
@danielocampo2
danielocampo2 / serializable.gd
Last active June 16, 2024 01:19
Serializable class for Godot
class_name Serializable
extends Object
# Serializable classes cannot have a constructor as an empty one is needed. Resort to static
# create function for easier object creation.
# Convert instance to a dictionary.
func to_dict() -> Dictionary:
var result = {
"_type": get_script().get_path() # This is a reference to the class/script type.
@danielocampo2
danielocampo2 / MultiDistinctBy.kt
Last active January 13, 2023 21:20
multiDistinctBy function for Kotlin: Like stdlib distinctBy but for multiple fields
fun <T, K> Iterable<T>.multiDistinctBy(vararg selectors: (T) -> K): List<T> {
require(selectors.isNotEmpty())
val set = HashSet<Int>()
val distinct = ArrayList<T>()
for (element in this) {
val key = selectors.fold(0) { sum, selector ->
sum.plus(selector(element)?.hashCode() ?: 0) }
if (set.add(key))
@danielocampo2
danielocampo2 / CommonExtensions.kt
Created June 6, 2017 23:14 — forked from adavis/CommonExtensions.kt
Common Android Extensions in Kotlin
fun View.visible() {
visibility = View.VISIBLE
}
fun View.invisible() {
visibility = View.INVISIBLE
}
fun View.gone() {
visibility = View.GONE