Skip to content

Instantly share code, notes, and snippets.

View DevSrSouza's full-sized avatar

Gabriel Souza DevSrSouza

View GitHub Profile
@DevSrSouza
DevSrSouza / .gitignore
Created March 24, 2024 20:17
Xcodegen configuration for a Compose Multiplatform app sample
ComposeSample.xcodeproj
---
PVE delte local-lvm partition
Reference: https://post.smzdm.com/p/awkv4pq4/
lvremove pve/data
lvextend -l +100%FREE -r pve/root
Datacenter >> remove `local-lvm` partition >> edit `local` >> select all options
@DevSrSouza
DevSrSouza / mtvehicles-migrate-to-oraxen.main.kts
Last active June 11, 2023 05:34
Generate Oraxen configuration for MTVehicles Texture with Furniture support
/** This script will migrate MTVehicles resource pack to Oraxen
* This will include:
* - Fixing ItemFrame position of the models
* - Fix new texture folder that will not anymore bem on custom/cars/, instead it will be at default/mtvehicles
* - For each model that is only a texture replacement, it will generate an Orxen config with Generate enabled with the given name. So... no more bunch of Cars models with only texture change
* - Will remove from models the: "particle": "items/particle" and "texture": "items/texture", that Oraxen says is not proper format.
*/
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
@DevSrSouza
DevSrSouza / StorageApi.kt
Last active October 9, 2022 16:09
PoC Kotlin Storage (Key/Value) API simple and extensible
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.onStart
import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.serializer
import java.util.UUID
public interface Storage<T : Any> {
public suspend fun store(container: T?)
@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 """
@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 / 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)
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 / 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() {