Skip to content

Instantly share code, notes, and snippets.

View keymap.c
/*
* 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 Feb 28, 2020
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
View Base58.kt
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 Sep 4, 2019
The last settings.gradle.kts
View 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")
}
View Kotlin_Mappers.kt
// User.kt
@Parcelize
data class User(
val id: UUID = UUID.randomUUID(),
val name: String?
) : Parcelable
// ScopedUser.kt
@Parcelize
data class ScopedUser(
View Kotlin_Interfaces.kt
@Parcelize
data class User(
override val id: UUID = UUID.randomUUID(),
override val name: String?
) : Parcelable, ScopedUser
interface ScopedUser {
val id: UUID
}
View Kotlin_Bundles.kt
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(
View Kotlin_implicit_return4.kt
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
Number.toEnglish()
View _Number.kt
// 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 {
@shkschneider
shkschneider / Log
Last active Apr 29, 2019
Android Log helper (automatic class, method and line) replacing android.util.Log
View Log
package me.shkschneider.skeleton.helper;
import android.text.TextUtils;
import android.util.Log;
/**
* Improved android.util.Log.
*
* Logs class and method automatically:
* [MyApplication onCreate():34] Hello, world!
View Kotlin_implicit_return3.kt
fun x(): String = when {
// ...
// ... ->
{
val value = whatever()
if (value) {
"something"
} else {
""
}