This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if the current network is connected to the internet and validated. | |
* Validation indicates the network is functional (e.g., it can be used for browsing). | |
* | |
* @return True if the network is connected, has internet capability, and is validated; false otherwise. | |
*/ | |
private fun Context.isInternetFunctional(): Boolean { | |
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val network = connectivityManager.activeNetwork | |
val networkCapabilities = connectivityManager.getNetworkCapabilities(network) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object JwtHelper { | |
/** | |
* Enum class representing JWT algorithms with their corresponding values. | |
*/ | |
enum class JwtAlgorithm(val value: String) { | |
ALGORITHM_HS256("HS256"), ALGORITHM_HS384("HS384"), ALGORITHM_HS512("HS512") | |
} | |
/** | |
* Enum class representing HMAC signature algorithms with their corresponding values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Executes a coroutine with configurable dispatchers for subscription and observation. | |
* | |
* @param subscribeOn The dispatcher context for subscribing to the asynchronous operation (default: Dispatchers.IO). | |
* @param observeOn The dispatcher context for observing the result (default: Dispatchers.Main). | |
* @param block A suspend function representing the asynchronous operation to be executed. | |
* @param onSuccess A suspend function that is invoked with the result of the asynchronous operation when it succeeds. | |
* @param onError A function that is invoked if the asynchronous operation encounters an error. | |
*/ | |
fun <T> withCoroutine( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Default implementation of [LocaleHelperKt]. | |
*/ | |
class DefaultLocaleHelper private constructor(context: Context) : BaseLocaleHelper(context) { | |
companion object { | |
/* Mark the instance as Volatile*/ | |
@Volatile | |
private var instance: LocaleHelperKt? = null | |
private var LOCK: Any = Any() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Intent?.toDebugString(): String { | |
val intent = this ?: return "" | |
return StringBuilder().apply { | |
appendLine("--- Intent ---") | |
appendLine("type: ${intent.type}") | |
appendLine("package: ${intent.`package`}") | |
appendLine("scheme: ${intent.scheme}") | |
appendLine("component: ${intent.component}") | |
appendLine("flags: ${intent.flags}") | |
appendLine("categories: ${intent.categories}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Android: Load JSON from `src/main/assets/` */ | |
/* Extension function where `Context` passed explicitly */ | |
fun loadJSONFromAsset(context: Context, fileName: String): String { | |
val inputStream: InputStream = context.assets.open(fileName) | |
val size: Int = inputStream.available() | |
val buffer = ByteArray(size) | |
inputStream.read(buffer) | |
inputStream.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LoginInterceptor: Interceptor{ | |
override fun intercept(chain: Interceptor.Chain): Response { | |
//If requested endpoint matched to targeted endpoint, we will return an mocked response. | |
if (chain.request().url.toUri().toString().endsWith("fake-login")) { | |
val responseString = "OUR_JSON_RESPONSE_FROM_ASSET_OR_OTHER_SOURCE" | |
return chain.proceed(chain.request()) | |
.newBuilder() | |
.code(200) | |
.protocol(Protocol.HTTP_2) | |
.message(responseString) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* UseCase is designed to execute a given operation by following | |
* Single Responsibility Design Principle. | |
*/ | |
abstract class UseCaseV2<ReturnType, in Params> where ReturnType : Any { | |
/** | |
* Abstract API that should be implemented by the respective child to execute the operation. | |
* | |
* @param params [Params] | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object BFS { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
val station1 = Node("Westminster", null, null) | |
val station2 = Node("Waterloo", station1, null) | |
val station3 = Node("Trafalgar Square", station1, station2) | |
val station4 = Node("Canary Wharf", station2, station3) | |
val station5 = Node("London Bridge", station4, station3) | |
val station6 = Node("Tottenham Court Road", station5, station4) | |
val bfs = BreadthFirstSearch(station6, station3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BinarySearch { | |
companion object { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
println("Index position: " + binarySearch(mutableListOf(1,15,34,45,65,76,87), 76)) | |
} | |
private fun binarySearch(list: List<Int>, itemToFind: Int): Int { | |
//Starting point | |
var left = 0 |
NewerOlder