Skip to content

Instantly share code, notes, and snippets.

@magillus
magillus / example.kt
Created April 11, 2019 14:11
Koin helper methods for module definition with Generic types - here StateMachine is generic
///define in module
val stateMachineModule = module {
stateFactory{ TestImplStateMachine() } bind StateMachine::class
}
/// inject or get
val stateMachineTest:StateMachine<MyState> = getSm()
///class of state machine
class TestImplStateMachine : StateMachine<MyState> {
@magillus
magillus / ContentObserverSubscriber.java
Last active August 16, 2021 23:28
RxContentObserver, wraps ContentObserver registration and on change with RxJava2.0 Observable that will emit updates.
package com.example.mat.rxutil;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import java.lang.ref.WeakReference;
@magillus
magillus / RxBoundServcie.java
Last active March 27, 2021 15:07
Rx wrapper around bounded Android Service that emits IBinder. It binds to a service on subscription and unbinds on disposing the subscription's disposable.
package com.example.mat.rxutil;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import java.lang.ref.WeakReference;
@magillus
magillus / RxBroadcastReceiver.java
Last active August 21, 2020 22:25
RxJava2.0 Broadcast Receiver for getting intent broadcasts as Observable<Intent>
/**
* RxJava based broadcast reciever that registers its local BroadcastReceiver until end of subscription.
* Listens for update and passes Intent to the Stream (Subscriber).
*
* Copyright 2016 Mateusz Perlak - http://www.apache.org/licenses/LICENSE-2.0
* Created on 11/18/16.
*/
public class RxBroadcastReceiver implements ObservableOnSubscribe<Intent> {
protected final WeakReference<Context> contextWeakReference;
@magillus
magillus / ContentObserverSubscriber.java
Last active April 18, 2020 21:46
RxContentObserver, wraps ContentObserver registration and on change with RxJava Observable that will emit updates.
package com.example.mat.rxutil;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import java.lang.ref.WeakReference;
@magillus
magillus / main.dart
Created December 6, 2019 14:27
Flutter form test
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
@magillus
magillus / anywhere.dart
Last active March 21, 2019 22:05
Dart Unit tests - expectException method.
import 'package:test/test.dart';
main() {
test("throw excpetion test",() {
expectException(()=>throw Exception("sample error"), Exception);
});
}
@magillus
magillus / example.dart
Last active March 19, 2019 03:22
StreamBuilderFiltered - For filtered and cast streams.
abstract class MyBlocState{}
class Step1State extends MyBlocState{
String title;
}
class Step2State extends MyBlocState{
int progress;
}
class Step3State extends MyBlocState{
}
@magillus
magillus / dart-parsing-helper.dart
Created January 9, 2019 22:36
Dart useful methods for parsing Json/map to object
bool whenNull(dynamic value) {
return value == null;
}
bool whenNotNull(dynamic value) {
return value != null;
}
bool whenNullMap(String key, value) {
@magillus
magillus / example.dart
Last active November 2, 2018 00:26
Fimber = Timber like logging for Flutter. May extend to different trees (like native channel logging (?) TBD)
import 'package:fimber/fimber.dart';
// initialization in main.dart
Fimber.addTree(DebugTree());
// usage:
Fimber.d("Test debug $value");
Fimber.de(exIo, "Error reading file: $path");