Skip to content

Instantly share code, notes, and snippets.

Ememobong Akpanekpo emayoung

  • Uyo, Nigeria
Block or report user

Report or block emayoung

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gistB
val cacheObservable:Observable<Data> = cacheSourceObservable
val remoteObservable:Observable<Data> = remoteSourceObservable.doOnNext { data ->
saveDataToCache(data)
}
val sourceObservable = Observable.concat(
cacheObservable.onErrorResumeNext(Function<Throwable, Observable<DriverStatsEntity>> { Observable.empty() /*ignore any errors from serving data from cache*/ }),
remoteObservable.onErrorResumeNext(Function<Throwable, Observable<DriverStatsEntity>> { throwable ->
if (!cache.hasCachedData()) Observable.error<Throwable>(throwable) /*show error from server since there is no data to be served*/
Observable.empty() /*ignore any errors from remote server and continue serving data from cache*/
})
View gistA
val cacheObservable:Observable<Data> = cacheSourceObservable
val remoteObservable:Observable<Data> = remoteSourceObservable.doOnNext { data ->
saveDataToCache(data)
}
val sourceObservable = Observable.concat(cacheObservable, remoteObservable)
View regex_number
val pattern = "###-##-#-####"
val count = pattern.length - pattern.replace("-", "").length
val patternsLength = mutableListOf<Int>()
var index = pattern.indexOf('-')
var length = pattern.substring(0,index).length
for(i in 0..count){
patternsLength.add(length)
length = index+1
@emayoung
emayoung / Remote Callbacks
Last active Dec 12, 2018
Remote callbacks provide a wrapper that makes it easier for developers to provide a PendingIntent. Generally those writing widgets, notifications, and more recently slices, have the fun of writing code that looks like this relatively frequently. The goal of Remote Callbacks is to remove as much of that fun as possible and let you get right down …
View Remote Callbacks
public class MyReceiver extends BroadcastReceiver {
final String ACTION_MY_CALLBACK_ACTION = "...";
final String EXTRA_PARAM_1 = "...";
final String EXTRA_PARAM_2 = "...";
public PendingIntent getPendingIntent(Context context, int value1, int value2) {
Intent intent = new Intent(context, MyReceiver.class);
intent.setaction(ACTION_MY_CALLBACK_ACTION);
intent.putExtra(EXTRA_PARAM_1, value1);
intent.putExtra(EXTRA_PARAM_2, value2);
View Interactors.kt
abstract class CompletableUseCase<in Params> constructor(
private val postExecutionThread: PostExecutionThread) {
private val disposables = CompositeDisposable()
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) {
val completable = this.buildUseCaseCompletable(params)
.subscribeOn(Schedulers.io())
View Interactors.kt
abstract class CompletableUseCase<in Params> constructor(
private val postExecutionThread: PostExecutionThread) {
private val disposables = CompositeDisposable()
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) {
val completable = this.buildUseCaseCompletable(params)
.subscribeOn(Schedulers.io())
View Interactors.kt
abstract class CompletableUseCase<in Params> constructor(
private val postExecutionThread: PostExecutionThread) {
private val disposables = CompositeDisposable()
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) {
val completable = this.buildUseCaseCompletable(params)
.subscribeOn(Schedulers.io())
View Interactors.kt
abstract class CompletableUseCase<in Params> constructor(
private val postExecutionThread: PostExecutionThread) {
private val disposables = CompositeDisposable()
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) {
val completable = this.buildUseCaseCompletable(params)
.subscribeOn(Schedulers.io())
View Interactors.kt
abstract class CompletableUseCase<in Params> constructor(
private val postExecutionThread: PostExecutionThread) {
private val disposables = CompositeDisposable()
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) {
val completable = this.buildUseCaseCompletable(params)
.subscribeOn(Schedulers.io())
View requestussdapi26
@RequiresApi(26)
fun requestUssdUsingTelephonyManager(ussd: String, simSlot: Int) {
val ussd = ussd.replace("%23", Uri.decode("#"))
Log.e("ussd", "requesting for ussd $ussd")
val manager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
val handler = Handler()
val callback = object : TelephonyManager.UssdResponseCallback() {
override fun onReceiveUssdResponse(telephonyManager: TelephonyManager, request: String, response: CharSequence) {
super.onReceiveUssdResponse(telephonyManager, request, response) // what if i remove this line
EventBus.getDefault().post(IntentResult(Activity.RESULT_OK, response.toString()))
You can’t perform that action at this time.