This file contains hidden or 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 |
This file contains hidden or 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
/*Transform a *Set* into a *HashMap**/ | |
suspend fun <T> Set<T>.toHashMap(): HashMap<Int, T> = withContext(Dispatchers.IO) { | |
val hashMap: HashMap<Int, T> = HashMap() | |
var index = 0 | |
[email protected] { | |
if (hashMap.isEmpty()) hashMap[0] = it else index = hashMap.size; hashMap[index++] = it | |
} | |
hashMap | |
} |
This file contains hidden or 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
{ | |
"apps": [ | |
{ | |
"serverURL": "http://192.168.17.131:1337/parse", | |
"appId": "test_app_id", | |
"masterKey": "test_master_key", | |
"allowInsecureHTTP": "true", | |
"appName": "MyApp1" | |
} | |
], |
This file contains hidden or 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
{ | |
"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 | |
} |
This file contains hidden or 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
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". |
This file contains hidden or 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
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 |
This file contains hidden or 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 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() |
This file contains hidden or 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
/** | |
* 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 |
This file contains hidden or 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 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-----") |
This file contains hidden or 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 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(".....") |