Skip to content

Instantly share code, notes, and snippets.

View mukandrew's full-sized avatar
🦾
working hard, working smart

Murillo Andrew mukandrew

🦾
working hard, working smart
View GitHub Profile
@mukandrew
mukandrew / MapDelegateFromSnakeCase.kt
Created September 23, 2023 22:01
MapDelegate from SnakeCase property Name
/**
* To use delegate property from map, getting value from a snakeCase key
*
* eg.:
* ```kotlin
* val myMap = mapOf("hello_world" to "Some Value")
* val helloWorld: String by myMap.fromSnakeCase()
* ```
*
* So, the val "helloWorld" will contain "Some Value"
@mukandrew
mukandrew / .editorconfig
Created February 25, 2022 15:03
Android Kotlin EditorConfig
root = true
[*]
charset = utf-8
end_of_line = crlf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 100
tab_width = 4
@mukandrew
mukandrew / ActivityExt.kt
Last active February 27, 2022 04:25
Android Helper Extensions
/**
* To prevent the device to put in sleep after a period of the time
*
* @param enablePreventSleep ON/OFF prevent sleep
*/
internal fun FragmentActivity.setPreventSleep(enablePreventSleep: Boolean) {
if (enablePreventSleep) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
@mukandrew
mukandrew / CoroutineHelpers.kt
Last active February 7, 2022 19:07
Android-KT: Files with common response file and extension to throw the exception
internal suspend fun <T> runCatchingNetworkException(block: suspend () -> T): T {
return try {
block()
} catch (e: HttpException) {
val response = e.response()
throw NetworkException(
response?.code(),
response?.message(),
response?.errorBody()?.charStream()?.readText()?.replace("\"", "")
)