Skip to content

Instantly share code, notes, and snippets.

View noiaverbale's full-sized avatar
🤷
¯\_(ツ)_/¯

Elia Sgolmin noiaverbale

🤷
¯\_(ツ)_/¯
  • Vicenza, Italy
View GitHub Profile
2021/10/04 08:03:16 ...s/context/context.go:195:HTML() [E] Render failed: template: repo/diff/csv_diff:3:15: executing "repo/diff/csv_diff" at <call .root.CreateCsvDiff .file .root.BaseCommit .root.HeadCommit>: error calling call: runtime error: invalid memory address or nil pointer dereference
@noiaverbale
noiaverbale / Position.kt
Last active December 14, 2018 13:20
The position class of a chess game in kotlin
internal data class Position(val name: String) {
constructor(file: Int, rank: Int) : this("${(file + 'A'.toInt()).toChar()}${rank + 1}")
val file: Int = name.validateAndTransform { it[0] - 'A' }
val rank: Int = name.validateAndTransform { it[1].toString().toInt() - 1 }
private fun <T> String.validateAndTransform(trasformer: (String) -> T): T =
if (Regex("""^[A-H][1-8]$""") matches this)
trasformer(this)