Skip to content

Instantly share code, notes, and snippets.

View surajsau's full-sized avatar
🙇‍♂️
よろしくお願いします!

Suraj Kumar Sau surajsau

🙇‍♂️
よろしくお願いします!
View GitHub Profile
@surajsau
surajsau / rounds_preference.js
Last active January 7, 2019 07:15
rounds_preference intent DailyRounds Assistant
/**
* This handles when the user has said his/her speciality preference.
* This intent can be reached either from 'cases' intent (cases-followup context),
* when the speciality preference hasn't been mentioned and assistant asks for it.
* Or, when the user says 'Change my speciality preference'.
*
* In the first case, 'cases-followup' context has exhausted only 1 lifespan until now,
* i.e., in answering "Yes" for the question "Would you like us to save your preference?".
* So, when 'cases-followup' context exists, it means that it has come from the initial
* intent of "Latest 10 cases" and so, we need to proceed with fetching the cases after
@surajsau
surajsau / rounds_map.js
Created January 6, 2019 03:28
rounds_preference entity mapping DailyRounds Assistant
const rounds_map = {
'primary':{'id':101, 'title':'DailyRounds'},
'cardio':{'id':108, 'title':'Cardiology'},
'ped':{'id':103, 'title':'Pediatric'},
'radio':{'id':104, 'title':'Radiology'},
'anaes':{'id':106, 'title':'Anaesthesia'},
'ent':{'id':112, 'title':'ENT'},
'optha':{'id':120, 'title':'Ophthalmology'},
'ortho':{'id':121, 'title':'Orthopedic'},
'best':{'id':135, 'title':'Best cases'}
@surajsau
surajsau / MainPresenter.kt
Created July 18, 2019 11:06
MVP to MVVM: MainPresenter
class MainPresenter(val service: GithubService) {
var view: MainView? = null
fun search(searchString: String) {
view?.showProgress()
service.getRequest(searchString, 0)
.subscribeOn(..)
.observeOn(..)
.doOnSuccess { onSearchResultReceived(it) }
@surajsau
surajsau / MainActivity.kt
Created July 18, 2019 11:12
MVP to MVVM: MainActivity
class MainActivity : AppCompatActivity(), MainView {
val presenter: MainPresenter by currentScope.inject()
val adapter: ResultAdapter by currentScope.inject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@surajsau
surajsau / DataObserver.kt
Created July 18, 2019 11:48
MVP to MVVM: DataObserver
class DataObserver<T>() {
var value: T? = null
set(value) {
field = value
observer?.invoke(value)
}
var observer: ((T?) -> Unit)? = null
@surajsau
surajsau / NewDataObserverImpl.kt
Last active July 18, 2019 11:57
MVP to MVVM: New Data Observer implementation
class MainPresenter(val service: GithubService) {
.
.
val progressVisibilityObserver = DataObserver<Int>()
private fun onSearchResultReceived(apiResponse: ApiResponse?) {
.
.
progressVisibilityObserver.value = 0
@surajsau
surajsau / LooseCoupling.kt
Last active July 18, 2019 13:32
MVP to MVVM: Lose Coupling Preview
class MainActivity : AppCompatActivity() {
val presenter: MainPresenter by currentScope.inject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
presenter.progressVisibilityObserver.observe {
..do something
}
@surajsau
surajsau / TightCoupling.kt
Created July 18, 2019 12:28
MVP to MVVM: Tight Coupling
class MainActivity : AppCompatActivity(), MainView {
val presenter: MainPresenter by currentScope.inject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
..
}
override fun doSomething() {..}
@surajsau
surajsau / flow1.kt
Last active February 5, 2020 10:11
Flow 1: Partial flow in MCQ
class A: AppCompatActivity() {
..
fun startB() {
..
startActivityForResult(intent, REQ_CODE)
}
override onActivityResult(intent, reqCode, ..) {
@surajsau
surajsau / flow2.kt
Created February 5, 2020 10:13
Flow 1: Complete flow in MCQ
class A: AppCompatActivity() {
..
fun startB() {
..
startActivityForResult(intent, REQ_CODE)
}
override onActivityResult(intent, reqCode, ..) {
if(reqCode == REQ_CODE) {
when(intent.getString("source")) {