Skip to content

Instantly share code, notes, and snippets.

/*
* cat qmk_firmware/keyboards/dz60/config.h qmk_firmware/keyboards/dz60/rules.mk
* cp -r qmk_firmware/keyboards/dz60/keymaps/olivierko qmk_firmware/keyboards/dz60/keymaps/shkschneider
* nano qmk_firmware/keyboards/dz60/keymaps/shkschneider/keymap.c
* make dz60:shkschneider
* qmk flash -kb dz60 -km shkschneider
*/
#include QMK_KEYBOARD_H
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
@shkschneider
shkschneider / Base58.kt
Created February 28, 2020 12:51
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
package me.shkschneider
// https://gist.github.com/vrotaru/1753908
object Base58 {
private val alphabet = (('0'..'9') - '0' + ('A'..'Z') - 'I' - 'O' + ('a'..'z') - 'l').sorted()
private val base58 = alphabet.size.also {
if (it != 58) throw RuntimeException("Base58!=Base$it")
}
private const val base256 = 256
@shkschneider
shkschneider / settings.gradle.kts
Last active September 4, 2019 11:45
The last settings.gradle.kts
fun submodules(parent: String? = "", file: File) {
file.listFiles()
?.filter { it.isFile && it.name.endsWith(".gradle") }
?.forEach {
val module = it.parentFile.name
println(":$module")
include(":$module")
if (parent != null) {
project(":$module").projectDir = File(rootDir, "$parent/$module")
}
@Parcelize
data class User(
override val id: UUID = UUID.randomUUID(),
override val name: String?
) : Parcelable, ScopedUser
interface ScopedUser {
val id: UUID
}
// User.kt
@Parcelize
data class User(
val id: UUID = UUID.randomUUID(),
val name: String?
) : Parcelable
// ScopedUser.kt
@Parcelize
data class ScopedUser(
private const val ID = "id"
private const val NAME = "name"
@Parcelize
data class User(
val id: UUID = UUID.randomUUID(),
val name: String?
) : Parcelable {
fun toBundle() = bundleOf(
fun EditText.setOnKeyboardSubmitListener(block: () -> Unit) {
setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
block()
true // implicit and won't do anything
// should use return@setOnEditorActionListener
}
false // explicit
}
}
@shkschneider
shkschneider / _Number.kt
Created May 9, 2019 14:21
Number.toEnglish()
// toEnglish
// <https://stackoverflow.com/a/47376072/603270>
private val zero = "zero"
private val oneToNine = listOf("one", "two", "three", "four", "five", "six", "seven", "height", "nine")
private val tenToNinteen = listOf("ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")
private val dozens = listOf("ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
private fun fromOneToAHundred(number: Short): String = if (number == 0.toShort()) "" else
when {
fun x(): String = when {
// ...
// ... ->
{
val value = whatever()
if (value) {
"something"
} else {
""
}
// <https://github.com/tailwhiper/kotlin-enum-extensions>
inline fun <reified E : Enum<E>> valueOf(name: String, default: E) =
enumValues<E>().find { it.name == name } ?: default
inline fun <reified E : Enum<E>> valueOf(ordinal: Int, default: E) =
enumValues<E>().find { it.ordinal == ordinal } ?: default
inline fun <reified E : Enum<E>> valueOfWithCondition(condition: (E) -> Boolean) =
enumValues<E>().find(condition)