Skip to content

Instantly share code, notes, and snippets.

View stepango's full-sized avatar
👁️
Making devs happier with Bazel

Stepan Goncharov stepango

👁️
Making devs happier with Bazel
View GitHub Profile
class RegisterViewModel(
naviComponent: NaviComponent
) : ViewModel by ViewModelImpl(naviComponent) {
val name = ObservableString("")
val email = ObservableString("")
val password = ObservableString("")
var location: LocationModel? = null
val locationName = ObservableString("")
/ideate
"location": {
"longitude": 106.808536,
"latitude": -6.213988999999999,
"title": "JCC Senayan",
"address": "RT.1/RW.3, Gelora, Tanah Abang, Kota Jakarta Pusat, Daerah Khusus Ibukota Jakarta 10270, Indonesia",
"place_id": "ChIJLdsYtq32aS4RqOzRPJVoE14"
}
/project
@stepango
stepango / RepositoryContract.kt
Last active December 16, 2016 09:38
Rx repo contract
/**
* Single value repository that don't accept null as value
*/
interface SingleValueRepo<Value : Any> {
/**
* Saves [value] on given [io.reactivex.Scheduler]
*/
fun save(value: Value): Single<Value>
/**
@stepango
stepango / FileCopy.kt
Created November 14, 2016 03:20
Copy data from FileDescriptor to File in Kotlin, using okio
fun copy(fd: FileDescriptor, file: File) {
Okio.source(FileInputStream(fd)).use { source ->
Okio.buffer(Okio.sink(file)).use { buffer -> buffer.writeAll(source) }
}
}
@stepango
stepango / GlideVideoThumbnail.kt
Created November 11, 2016 09:31
WTF Glide url video thumbnail loading
package com.ninetyseconds.auckland.core.glide
import android.content.Context
import android.graphics.Bitmap
import android.media.MediaMetadataRetriever
import com.bumptech.glide.Glide
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.Priority
import com.bumptech.glide.load.data.DataFetcher
import com.bumptech.glide.load.model.GenericLoaderFactory
@stepango
stepango / UploadApi.kt
Created November 10, 2016 10:19
How to upload file via Retrofit2 without multipart
interface UploadApi {
@PUT fun uploadFile(@Url url: String, @Body file: RequestBody): Observable<Response<Any>>
}
@stepango
stepango / RequestBodyExt.kt
Last active March 30, 2021 13:30
Kotlin Retrofit2 RequestBody from FileDescriptor
fun requestBody(fd: FileDescriptor) = object : RequestBody() {
override fun contentType(): MediaType = MediaType.parse("multipart/form-data")
override fun writeTo(sink: BufferedSink) {
Okio.source(FileInputStream(fd)).use { source ->
sink.writeAll(source)
}
}
}
@stepango
stepango / Optional.kt
Last active November 3, 2016 08:30
Mimic Java8 Optional class
import java.util.NoSuchElementException
sealed class Optional<T : Any>(private val value: T?) {
constructor() : this(null)
fun get(): T {
value ?: throw NoSuchElementException("No value present")
return value
}
@stepango
stepango / GammaEvaluator.java
Created October 15, 2016 02:24 — forked from FrancoisBlavoet/GammaEvaluator.java
Correct color interpolation
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import static java.lang.Math.pow;
public class GammaEvaluator implements TypeEvaluator {
private static final GammaEvaluator sInstance = new GammaEvaluator();
/**
@stepango
stepango / BindingObservablesExt.kt
Last active November 7, 2018 21:09
Databinding Observable RxJava2 extensions
package com.ninetyseconds.auckland.core.databindings
import android.databinding.*
import android.databinding.Observable.OnPropertyChangedCallback
import android.os.Parcelable
import io.reactivex.Observable
import io.reactivex.Observable.create
import org.funktionale.option.toOption
import java.lang.Math.max
import java.lang.Math.min