Skip to content

Instantly share code, notes, and snippets.

View rommansabbir's full-sized avatar
👓
Only Development

Romman Sabbir rommansabbir

👓
Only Development
View GitHub Profile
{
"apps": [
{
"serverURL": "http://192.168.17.131:1337/parse",
"appId": "test_app_id",
"masterKey": "test_master_key",
"allowInsecureHTTP": "true",
"appName": "MyApp1"
}
],
{
"appName": "ParseServer",
"databaseURI": "mongodb://localhost:27017/parsedb",
"appId": "test_app_id",
"masterKey": "test_master_key",
"serverURL": "https://localhost:1337/parse",
"publicServerURL": "https://0.0.0.0:1337/parse",
"port": 1337
}
@rommansabbir
rommansabbir / Failure.kt
Created March 22, 2022 04:02
Sealed Class that return HTTP Failure (4xx, 5xx)
sealed class Failure {
/*Network Error*/
class NetworkConnection(var additionalData: Any? = null) : Failure()
/*Exception*/
class Exception(var additionalData: Any? = null) : Failure()
/**
* Although the HTTP standard specifies "unauthorized",
* semantically this response means "unauthenticated".
@rommansabbir
rommansabbir / Hilt.kt
Last active November 10, 2023 21:08
Android - Hilt: Inject multiple instances of SameType Object to the Dependent Module
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import javax.inject.Named
@rommansabbir
rommansabbir / IteratorPatternExample.kt
Created March 12, 2022 13:16
Iterator Pattern Example
class IteratorPatternExample {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val holder = VerifyTickets.getTicketHolder()
/*Printing several tickets*/
println("Printing next tickets...")
holder.ticketIterator.nextTicket()
holder.ticketIterator.nextTicket()
@rommansabbir
rommansabbir / MultithreadedDataHolder.kt
Created March 7, 2022 07:44
Volatile - Marks the JVM backing field of the annotated property as volatile, meaning that writes to this field are immediately made visible to other threads.
/**
* We have a data holder class called [MultithreadedDataHolder] that hold some data
* which will be used by different clients from different [Thread]s. Multiple clients
* can access the same object simultaneously.
*
* Any object that is annotated with Annotation [Volatile] make sure that the changes
* made in one thread are immediately reflect in other thread.
*/
object MultithreadedDataHolder {
/*It's guaranteed that all reader threads will see the updated value of the
@rommansabbir
rommansabbir / CommandPatternExample.kt
Created March 6, 2022 12:38
Command Design Pattern
class CommandPatternExample {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val remoteControl: BaseRemoteControl = RemoteControl()
println("-----Testing onButtonPressed on RemoteControl for Car-----")
val car = Car()
val carMoveCommand: Command = CarMoveCommand(car)
remoteControl.onButtonPressed(carMoveCommand)
println("-----Testing offButtonPressed on RemoteControl for Car-----")
@rommansabbir
rommansabbir / ChainOfResponsibilityExample.kt
Created March 3, 2022 09:05
Design Pattern - Chain of Responsibility
class ChainOfResponsibilityExample {
companion object {
@JvmStatic
fun main(args: Array<String>) {
SupportCenterClient.handlerChain.apply {
println(".....")
receiveRequest(AbstractSupportCenter.Constants.GENERAL, "I'm having general issue.")
println(".....")
receiveRequest(AbstractSupportCenter.Constants.TECHNICAL, "I'm having technical issue.")
println(".....")
@rommansabbir
rommansabbir / KotlinAysncToSync.kt
Created February 28, 2022 04:17
Kotlin: Convert Async APIs into Sync
class Worker {
/*Async API*/
fun doSomething(listener: Listener, throwError: Boolean) {
when (throwError) {
true -> {
Thread.sleep(3000)
listener.onError(Exception("Just a random exception..."))
}
else -> {
Thread.sleep(3000)
@rommansabbir
rommansabbir / BaseCustomView.kt
Created February 24, 2022 05:07
Custom Base View to support Kotlin's Coroutine according to View's Lifecycle (On Detach, kill Coroutine).
/**
* Custom Base View to support Kotlin's Coroutine according to View's Lifecycle (On Detach, kill Coroutine).
*
* @param context [Context]
* @param attrs [AttributeSet]
*/
open class BaseCustomView(context: Context, attrs: AttributeSet) :
ConstraintLayout(context, attrs) {
private val tag by lazy { this::class.java.canonicalName ?: "BaseCustomView" }