Skip to content

Instantly share code, notes, and snippets.

View DevSrSouza's full-sized avatar

Gabriel Souza DevSrSouza

View GitHub Profile
@DevSrSouza
DevSrSouza / faster_tool_starwey_valley.sh
Last active July 16, 2021 13:56
Stardew Valley Linux script for faster tool (Animation cancelation)
pressTool()
{
xdotool keydown 'c'
sleep 0.090
xdotool keyup 'c'
sleep 0.042
xdotool keydown 'Shift_R+Delete+R'
sleep 0.005
xdotool keyup 'Shift_R+Delete+R'
}
@DevSrSouza
DevSrSouza / GtkTheme.kt
Created July 4, 2021 19:00
Compose for Desktop get and listen to Gtk Dark/Light Theme changes
// implementation("org.zeroturnaround:zt-exec:1.12") LIBRARY USAGED
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import kotlin.coroutines.resume
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
@DevSrSouza
DevSrSouza / pom.xml
Created May 18, 2021 12:31
Compose compiler in a Maven Project
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>mainModule</artifactId>
<groupId>me.devsrsouza</groupId>
<version>1.0</version>
<packaging>jar</packaging>
@DevSrSouza
DevSrSouza / Router.kt
Last active January 12, 2021 14:30
Simple routing system for Kotlin Multiplatform
import kotlinx.coroutines.flow.StateFlow
import kotlin.reflect.KClass
interface Router<T : Any> {
// null if the backStack was cleared and the app was closed
val currentDirection: StateFlow<T?>
// will push the new direction
// if pop is not null, it will pop all previous direction down to the latest appearance of the pop kclass
fun push(
@DevSrSouza
DevSrSouza / tuple-generator.main.kts
Last active September 23, 2020 02:39
Typed Tuple generator for Kotlin by calling `tuple("Txt", 15)`
@file:DependsOn("com.squareup:kotlinpoet:1.6.0")
import com.squareup.kotlinpoet.*
import java.io.File
val maxParameterCount = 12
fun typeName(it: Int) = (65 + it).toChar().toString()
val tupleClasses = Array(maxParameterCount) {
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
typealias InflateBindingCallback<BINDING> = (LayoutInflater, ViewGroup, viewType: Int) -> BINDING
typealias GetViewFromBindingCallback<BINDING> = (BINDING) -> View
@DevSrSouza
DevSrSouza / RouletteWheel.kt
Last active April 19, 2020 01:30
Fitness proportionate selection in Kotlin (RouletteWheel)
inline fun <T> List<T>.selectRouletteWheelWithMinimum(
min: Double = 100.0,
sum: (T) -> Double
): T? {
if(isEmpty()) return null
val total = reversed().sumByDouble(sum)
val random = (Math.random() * if(total > min) total else min)
@DevSrSouza
DevSrSouza / ServiceExtensions.kt
Last active October 25, 2023 18:14
Connecting to a service using Kotlin Coroutines
import android.app.Service
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
suspend inline fun <reified S : Service, B : IBinder> Context.connectService(
@DevSrSouza
DevSrSouza / GoldsMenu.kt
Last active January 23, 2020 12:01
KotlinBukkitAPI Menu Pagination sample
private val items = Array<ItemStack>(64) {
item(Material.GOLD_INGOT, it).displayName("$it")
}.toMutableList()
private var menuCache: MenuDSL? = null
val goldsMenu: MenuDSL
get() {
if(menuCache == null)
menuCache = generateMenUConfiguration()
}
@DevSrSouza
DevSrSouza / TakeMaxMilliseconds.kt
Created January 11, 2020 13:57
Take max milliseconds time to do a work and wait to continue doing.
package br.com.devsrsouza.kotlinbukkitapi.controllers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import java.util.concurrent.ConcurrentHashMap
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.coroutineContext
import kotlin.system.measureTimeMillis
fun main() {