Skip to content

Instantly share code, notes, and snippets.

View mrenouf's full-sized avatar

Mark Renouf mrenouf

View GitHub Profile
object LChHues {
// --- Palette L*=67 C*=40 (24 Colors) ---
val lch_L67_C40_01 = Color(0xffe586a5)
val lch_L67_C40_02 = Color(0xffe78793)
val lch_L67_C40_03 = Color(0xffe48a81)
val lch_L67_C40_04 = Color(0xffdd8f72)
val lch_L67_C40_05 = Color(0xffd39566)
val lch_L67_C40_06 = Color(0xffc59c5d)
val lch_L67_C40_07 = Color(0xffb5a25a)
val lch_L67_C40_08 = Color(0xffa3a85b)
@mrenouf
mrenouf / Window.kt
Created April 8, 2025 02:47
Flow window function for log event flows -> lazy list UI
package com.android.atool.ui
import kotlinx.coroutines.channels.BufferOverflow.DROP_LATEST
import kotlinx.coroutines.flow.buffer
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.Flow
/**
* Creates a [Flow] that emits sliding windows of the elements from the original [Flow].
* Each emitted list represents a window of the specified [length]. The window starts with
@mrenouf
mrenouf / PosixFileModes.kt
Created April 22, 2024 14:18
Parse and format posix raw file modes (including file type and special (suid/setgid/sticky) bits)
private const val FILE_TYPES = "?pc?d?b?-?l?s???"
fun String.toPosixModeInt(): Int {
require(length == 10) { "Should have 10 characters" }
// type
val type = when(get(0)) {
'p' -> 1
'c' -> 2
'd' -> 4
'b' -> 6
package adb
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import java.lang.ref.Reference
import java.lang.ref.ReferenceQueue
@mrenouf
mrenouf / ByteBufferSlicePool.kt
Last active April 10, 2024 20:57
Pooled ByteBuffers (Fast TreeSet+Double-linked-list version)
package adb.io
import adb.WeakReferenceMap
import java.lang.ref.Cleaner
import java.nio.ByteBuffer
import java.util.*
class ByteBufferSlicePool2(
capacity: Int,
) : ByteBufferAllocator {
@mrenouf
mrenouf / ByteBufferSlicePool.kt
Last active April 10, 2024 20:58
Original Slow version, scales terribly (N^2 with the number of allocations)
package adb.io
import adb.io.ByteBufferSlicePool.Region.Alloc
import adb.io.ByteBufferSlicePool.Region.Free
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import java.lang.ref.ReferenceQueue
import java.lang.ref.WeakReference
package adb.io
import adb.io.ByteBufferSlicePool.Region.Alloc
import adb.io.ByteBufferSlicePool.Region.Free
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import java.lang.ref.ReferenceQueue
import java.lang.ref.WeakReference
import java.net.SocketAddress
import java.nio.ByteBuffer
import java.nio.channels.AsynchronousByteChannel
import java.nio.channels.AsynchronousSocketChannel
import java.nio.channels.CompletionHandler
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlinx.coroutines.suspendCancellableCoroutine
suspend fun AsynchronousByteChannel.readInto(buffer: ByteBuffer): Int = suspendCancellableCoroutine {
read(buffer, null, object : CompletionHandler<Int, Any?> {
override fun completed(result: Int, attachment: Any?) { it.resume(result) }
override fun failed(exc: Throwable, attachment: Any?) = it.resumeWithException(exc)
})
}
suspend fun AsynchronousByteChannel.writeFrom(buffer: ByteBuffer): Int = suspendCancellableCoroutine {
write(buffer, null, object : CompletionHandler<Int, Any?> {
override fun completed(result: Int, attachment: Any?) = it.resume(result)
sudo apt install build-essential autoconf bison flex texinfo \
help2man gawk libtool libncurses5-dev python3-dev \
python3-distutils git
git clone http://github.com/crosstool-ng/crosstool-ng
cd crosstool-ng
./bootstrap
./configure --enable-local
DEFCONFIG=samples/armv8-rpi3-linux-gnueabihf/crosstool.config ./ct-ng defconfig