Skip to content

Instantly share code, notes, and snippets.

View miroslavign's full-sized avatar

Miroslav Ignjatovic miroslavign

View GitHub Profile
@miroslavign
miroslavign / ActivityFragmentExample.kt
Created December 9, 2018 22:39 — forked from jquerius/ActivityFragmentExample.kt
Kotlin Fragment to Activity Communication Example
class ExampleFragment : Fragment() {
// this is the instance of our parent activity's interface that we define here
private var mListener: OnFragmentInteractionListener? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
fun onButtonPressed(uri: Uri) {
if (mListener != null) {
mListener!!.onFragmentInteraction(uri)
@miroslavign
miroslavign / DebounceBuffer.java
Created March 9, 2018 17:04 — forked from benjchristensen/DebounceBuffer.java
DebounceBuffer: Use publish(), debounce() and buffer() together to capture bursts of events.
import java.util.List;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Subscriber;
import rx.schedulers.Schedulers;
public class DebounceBuffer {
public static void main(String args[]) {
@miroslavign
miroslavign / canny.cpp
Created January 20, 2018 23:39 — forked from egonSchiele/canny.cpp
Adding automatic thresholding to cvCanny in OpenCV
// new
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
@miroslavign
miroslavign / RXJava-Wrap-CallbackAPI-README.md
Created December 24, 2017 22:40 — forked from danielesegato/RXJava-Wrap-CallbackAPI-README.md
RxJava: Creating Observable from legacy asynchronous API using callbacks

About the gist

EDIT: This has become soon obsolete when Observable.fromAsync() has been released in RxJava. An issue from JakeWarthon here: ReactiveX/RxJava#4177 generated a pull request which is being implemented / discussed here: ReactiveX/RxJava#4179 . See below on how to use it.

I'm learning RxJava. Many Rx-libraries out there are using Obvservable.create() with an inline OnSubscribe implementation to wrap legacy APIs, like this one for the Android GoogleMap API:

class MapFragmentMapReadyOnSubscribe implements Observable.OnSubscribe<GoogleMap> {
  final MapFragment fragment;
// https://akarnokd.blogspot.ru/2017/09/rxjava-vs-kotlin-coroutines-quick-look.html
// Refactoring
import kotlinx.coroutines.experimental.*
suspend fun f1(i: Int): Int {
Thread.sleep(if (i != 2) 2000L else 200L)
return 1
}
suspend fun f2(i: Int): Int {
@miroslavign
miroslavign / RxArchitecture.java
Created September 22, 2017 22:15 — forked from vaughandroid/RxArchitecture.java
Experimenting with Rx architecture
class Wiring {
private final Observable<ViewModel> viewModelObservable;
Wiring(View view, ActionDispatcher actionDispatcher, Service service, ViewModelScanner viewModelScanner) {
viewModelObservable = view.uiEventObservable()
.compose(actionDispatcher.uiEventToAction())
.compose(service.actionToResult())
.compose(viewModelScanner.resultToViewModel());
package com.charter.aesd.activationlogin.edge.service
import rx.Observable
import rx.functions.Func1
import rx.functions.Func3
/**
* Created by rhasija on 1/14/16.
*/
class ObsTest {
@miroslavign
miroslavign / HomeActivity.kt
Created June 7, 2017 07:55 — forked from antoniolg/HomeActivity.kt
Snackbar extensions on Kotlin, to create a useful small DSL.
class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
setSupportActionBar(toolbar)
fab.setOnClickListener {
it.snack("Snack message") {
action("Action") { toast("Action clicked") }
@miroslavign
miroslavign / BindingObservablesExt.kt
Created June 5, 2017 17:03 — forked from stepango/BindingObservablesExt.kt
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
private Observable<SentToS3Event> getAmazonObservable(String newFilename) {
Observable<SentToS3Event> amazonObservable = Observable.defer(new Func0<Observable<SentToS3Event>>() {
@Override
public Observable<SentToS3Event> call() {
return Observable.create((ObservableEmitter<SentToS3Event> subscriber) -> {
final PutObjectRequest putObjectRequest = new PutObjectRequest(AmazonS3FetchParams.MY_BUCKET_NAME, newFilename, new java.io.File(fileURI))
.withCannedAcl(CannedAccessControlList.PublicRead)
.withStorageClass(StorageClass.Standard);
putObjectRequest.setGeneralProgressListener(new S3ProgressListener() {
@Override