Skip to content

Instantly share code, notes, and snippets.

View mbobiosio's full-sized avatar
🎯
Focusing

Mbuodile Obiosio mbobiosio

🎯
Focusing
View GitHub Profile
{
"app_name": "My App",
"example_text_view_key": "Hello, World!",
"settings_title": "Settings",
"language_title": "Language",
"select_language": "Select Language",
"display_name": "English",
"ok_button": "OK",
"cancel_button": "Cancel",
"home_feature": "Changed Home"
{
"app_name": "My App",
"example_text_view_key": "Hello, World!",
"settings_title": "Settings",
"language_title": "Language",
"select_language": "Select Language",
"display_name": "English",
"ok_button": "OK",
"cancel_button": "Cancel",
"home_feature": "Changed Home"
@mbobiosio
mbobiosio / Extensions.kt
Last active November 15, 2023 16:58 — forked from albertogiunta/Extensions.kt
Extension functions (Kotlin) & build.gradle files for Android projects
/**
* ANY
*/
fun Any.toJson(): String = GsonInitializer.toJson(this)
/**
* String to Inches
**/
internal fun convertStringToInches(centimeters: String) : String =
(BigDecimal(centimeters.toDouble() * 0.393701).setScale(3, RpundingMode.HALF_EVEN)).toString()
/**
Usage for extensions.
Initialize Moshi in your Converter class
*/
private val moshi: Moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()
/**
* [Moshi] extension to transform a [List] to Json
fun main() {
/*
cards = ['Jack', 8, 2, 6, 'King', 5, 3, 'Queen']
<!-- Required Output = [2,3,5,6,8,'Jack','Queen','King']
Q: Sort the array as per the rules of card game using a generic method.
* */
val card1 = arrayListOf("Jack", 8, 2, 6, "King", 5, 3, "Queen")
val card2 = arrayListOf(

Interview Questions

Kotlin

Q1: What is a primary constructor in Kotlin? ☆☆

Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:

/*
Note: In this problem you must NOT generate any output on your own. Any such solution will be considered as being against the rules and its author will be disqualified. The output of your solution must be generated by the uneditable code provided for you in the solution template.
An important concept in Object-Oriented Programming is the open/closed principle, which means writing code that is open to extension but closed to modification. In other words, new functionality should be added by writing an extension for the existing code rather than modifying it and potentially breaking other code that uses it. This challenge simulates a real-life problem where the open/closed principle can and should be applied.
A Tree class implementing a rooted tree is provided in the editor. It has the following publicly available methods:
getValue(): Returns the value stored in the node.
getColor(): Returns the color of the node.
getDepth(): Returns the depth of the node. Recall that the depth of a node is the number of
/*
* Dealing with TMDB genres?
* This will help you fix that
*/
fun getGenre(ids:List<Int>):String{
var genre=""
for(i in ids ){
when (i) {
28 -> genre+="Action|"
12 -> genre+="Adventure|"
//Get TAG for class name
val Any.TAG: String
get() {
return if (!javaClass.isAnonymousClass) {
val name = javaClass.simpleName
/** First 23 chars */
if (name.length > 23 && Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
name.substring(0, 23) else name
} else {
val name = javaClass.name
@mbobiosio
mbobiosio / BindingAdapters.kt
Last active November 4, 2021 00:26
Every other useful Kotlin Extension useful for daily stuff
/**
* Converts milliseconds to formatted mm:ss
*
* @param value, time in milliseconds.
*/
@BindingAdapter("elapsedTime")
fun TextView.setElapsedTime(value: Long) {
val seconds = value / 1000
text = if (seconds < 60) seconds.toString()
else DateUtils.formatElapsedTime(seconds)