Codeblock

Expressive Code

References

More…

File Icons

script.kt
println("Kotlin")

script.ts
console.log('Typescript')

Focus

script.kt
class Sketch: PApplet {
override fun setup() {
fullscreen()
}
override fun draw() {
background(0)
rect(
x = 100,
y = 100,
width = 100,
height = 100
)
}
companion object {
fun main(args: Array<String>) = PApplet.main(Sketch::class.name)
}
}

Callout

settings.gradle.kts
rootProject.name = "ProjectName"

Usually same as root folder name

include("subproject")

Sticky Scroll

script.kt
import kotlin.math.ln
import kotlin.math.max
fun main() {
fun main() {
for(i in 1..3) {
println("Hello world x$i")
}
}
/**
* Pluralize a word depending on its count
*
* [Source](https://taingmeng.medium.com/pluralize-string-with-kotlin-extension-554fb8c63469)
*/
fun String.pluralize(count: Int, plural: String? = null): String {
fun String.pluralize(count: Int, plural: String? = null): String {
return if (count != 1) {
plural ?: (this + 's')
} else {
this
}
}
/**
* Converts '-'/'_' lowercase id into a display name
*/
fun String.displayName(): String {
fun String.displayName(): String {
val id = this
// Replace underscores and hyphens with spaces
// Split the string into words
val words = id.lowercase().split('_', '-')
// Capitalize and join
val newName = words.joinToString(" ") { it.capitalize() }
// Return the new name
return newName
}
/**
* 1st, 2nd, 3rd, etc...
*/
fun Int.toOrdinal(): String {
fun Int.toOrdinal(): String {
if (this % 100 in 11..13) return "${this}th"
return when (this % 10) {
1 -> "${this}st"
2 -> "${this}nd"
3 -> "${this}rd"
else -> "${this}th"
}
}

This website is currently available on Desktop only
Let @Stephcraft know on Discord you'd like a Mobile version

Join Discord