This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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] = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Parcelize | |
data class User( | |
override val id: UUID = UUID.randomUUID(), | |
override val name: String? | |
) : Parcelable, ScopedUser | |
interface ScopedUser { | |
val id: UUID | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// User.kt | |
@Parcelize | |
data class User( | |
val id: UUID = UUID.randomUUID(), | |
val name: String? | |
) : Parcelable | |
// ScopedUser.kt | |
@Parcelize | |
data class ScopedUser( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun x(): String = when { | |
// ... | |
// ... -> | |
{ | |
val value = whatever() | |
if (value) { | |
"something" | |
} else { | |
"" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <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) |
NewerOlder