Skip to content

Instantly share code, notes, and snippets.

View mbobiosio's full-sized avatar
🎯
Focusing

Mbuodile Obiosio mbobiosio

🎯
Focusing
View GitHub Profile
object NetworkUtil {
fun isNetworkAvailable(context: Context?): Boolean {
if (context == null) return false
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import java.util.*
#parse("File Header.java")
@mbobiosio
mbobiosio / README.md
Created October 5, 2020 13:54 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store

{
"status": "success",
"message": "",
"data": {
"id": "69173",
"artistName": "Bonny Cepeda",
"albumTitle": "Asesina",
"genre": "Salsa y Tropical",
"albumDuration": "01:16:50",
"songCount": 17,
@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)
//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
/*
* 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|"
/*
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

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:

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(