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 CacheRemote.kt
mWeekService.getCachedLessons() // From Cache
.doFinally(() -> {
mWeekService.getLessons() // From Network
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(new Function<WeekResponse, List<WeekModel>>() {
@Override
public List<WeekModel> apply(
@io.reactivex.annotations.NonNull final WeekResponse response)
throws Exception {
View BookingHistoryBoundaryCallback.kt
package com.dryva.data.boilerplate.source.trip
import android.arch.paging.PagedList
import com.dryva.data.boilerplate.repository.driver.DryvaCache
import com.dryva.data.boilerplate.repository.trip.TripCache
import com.dryva.data.boilerplate.repository.trip.TripRemote
import com.dryva.domain.model.BookingData
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
View build.gradle
allprojects {
apply from: "$rootDir/ktlint.gradle"
}
View config.txt
Go to File -> Settings... -> Editor
General -> Auto Import
check Optimize imports on the fly (for current project).
Code Style -> Kotlin
Set from... -> Predefined style -> Kotlin style guide (Kotlin plugin 1.2.20+).
open Code Generation tab
uncheck Line comment at first column;
select Add a space at comment start.
open Imports tab
View install1.txt
curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.33.0/ktlint &&
chmod a+x ktlint &&
sudo mv ktlint /usr/local/bin/
View build.gradle
apply plugin: 'kotlin'
apply from: "../ktlint.gradle"
View ktlint.gradle
repositories {
jcenter()
}
configurations {
ktlint
}
dependencies {
ktlint "com.pinterest:ktlint:0.33.0"
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
You can’t perform that action at this time.