Skip to content

Instantly share code, notes, and snippets.

View DevSrSouza's full-sized avatar

Gabriel DevSrSouza

View GitHub Profile
@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) {
@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 / 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 / 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 / faster_tool_starwey_valley.sh
Last active August 19, 2024 14:04
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 / ComposeTest.kt
Last active August 1, 2021 20:41
Compose Desktop render to png test
fun main() {
val window = TestComposeWindow(width = 1024, height = 300)
window.setContent {
MainUi()
}
File(Paths.get("").toAbsolutePath().toString()).writeBytes(window.surface.makeImageSnapshot().encodeToData()!!.bytes)
}
@Composable
fun MainUi() {
sealed class Either<out L, out R> {
class Left<L>(val value: L) : Either<L, Nothing>()
class Right<R>(val value: R) : Either<Nothing, R>()
fun fold(
onLeft: (L) -> Unit,
onRight: (R) -> Unit,
) {
when(this) {
is Left -> onLeft(value)
@DevSrSouza
DevSrSouza / get-theme.main.kts
Created February 2, 2022 04:40
Kotlin Script that get Linux System Theme based on Dbus appearance color-schema from Gnome 42, KDE and Elementary
@file:DependsOn("com.github.hypfvieh:dbus-java-core:4.0.0")
@file:DependsOn("com.github.hypfvieh:dbus-java-transport-jnr-unixsocket:4.0.0")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.0")
import org.freedesktop.dbus.annotations.DBusInterfaceName
import org.freedesktop.dbus.connections.impl.DBusConnection
import org.freedesktop.dbus.interfaces.DBusInterface
import org.freedesktop.dbus.types.Variant
val connection = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION)
@DevSrSouza
DevSrSouza / insertSecionHeader.kt
Created February 5, 2022 19:05
InsertSectionHeader Paging 3
public inline fun <reified T : R, R : Any, C : Any> PagingData<T>.insertSectionHeader(
crossinline sectionBy: suspend (T) -> C,
crossinline insert: suspend (T) -> R,
): PagingData<R> {
return insertSeparators { first: T?, second: T? ->
if(first == null && second != null)
return@insertSeparators insert(second)
if(second == null) return@insertSeparators null
@DevSrSouza
DevSrSouza / generate-withContext.kt
Created April 14, 2022 20:30
Generate withContext functions for Kotlin Context (Context does not work with Generics yet)
fun main(args: Array<String>) {
val generatedWithGenericCount = 16
fun generateWithFunction(contextsCount: Int): String {
val generics = (1..contextsCount).map { "T$it" }.joinToString(", ")
val params = (1..contextsCount).map { "param$it: T$it" }.joinToString(",\n")
val contexts = "context(" + (1..contextsCount).map { "T$it" }.joinToString(", ") + ")"
val withBlocks = (1..contextsCount).map { "with(param$it){" }.joinToString(" ")
val withBlocksEnd = (1..contextsCount).map { "}" }.joinToString(" ")
return """