Skip to content

Instantly share code, notes, and snippets.

View VovaStelmashchuk's full-sized avatar
🇺🇦

Volodymyr Stelmashchuk VovaStelmashchuk

🇺🇦
  • Appflame
  • Ukraine
View GitHub Profile
@VovaStelmashchuk
VovaStelmashchuk / main.py
Last active October 31, 2025 17:17
ESP32 electricty tracker micro python
from machine import Pin
import time
import network
import time
import ujson as json
import usocket as socket
import machine
import urequests
led = Pin(8, Pin.OUT)
@VovaStelmashchuk
VovaStelmashchuk / class-cast-exception.kt
Last active May 17, 2025 08:32
The potential-bugs code
fun fooBad(a: Any?) {
val x: String? = a as String? // If 'a' is not String, ClassCastException will be thrown.
}
fun fooGood(a: Any?) {
val x: String? = a as? String
}
suspend fun CoroutineScope.badFoo() {
launch {
delay(1.seconds)
}
}
fun CoroutineScope.goodFoo() {
launch {
delay(1.seconds)
}
@VovaStelmashchuk
VovaStelmashchuk / bad-apply-block.kt
Created May 11, 2025 10:21
Although the scope functions are a way of making the code more concise, avoid overusing them: it can decrease your code readability and lead to errors. Avoid nesting scope functions and be careful when chaining them: it's easy to get confused about the current context object and the value of this or it.
// Try to figure out, what changed, without knowing the details
fun makeConnection(first: User, second: User) {
first.apply {
second.apply {
b = a
c = b
}
}
}
fun runBarFlowBad() {
if (
user.role == UserDto.Role.ADMIN ||
(user.status == UserDto.Status.VIP ||
(user.status == UserDto.Status.TRIAL_VIP && user.paymentTransactionList.isNotEmpty())
&& user.age.isAdult())
) {
// do something
} else {
// do something else
0
SECTION
2
BLOCKS
0
ENDSEC
0
SECTION
2
ENTITIES
@VovaStelmashchuk
VovaStelmashchuk / Slug.kt
Created July 13, 2024 08:37
Kotlin correct ukraine slug generator, based on <add link here>
import java.util.Locale
fun slug(str: String): String {
return translit(str)
.lowercase(Locale.ENGLISH)
.replace(Regex("[^a-zA-Z0-9]"), "-")
.replace(Regex("-+"), "-")
.trim('-')
}
@VovaStelmashchuk
VovaStelmashchuk / layout.kbd.json
Last active February 10, 2024 12:26
Untitled Keyboard Layout
[
{
"background": {
"name": "Carbon fibre 2",
"style": "background-image: url('/bg/carbonfibre/carbon_texture1874.png');"
}
},
[
"esc\n`",
"Q",
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/v.stelmashchuk/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
find <folder>/ -name '*.icloud' -delete