Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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");
@magillus
magillus / Medium sticky.log.txt
Created August 21, 2018 11:44
Medium on media button play opens empty notification that can't be dimissed. Here is logcat for it
08-21 06:39:54.332 1535-4176/? D/MediaSessionService: Sending KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_MEDIA_PLAY_PAUSE, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, displayId=0, source=0x0 } to the last known PendingIntent PendingIntent{5b76839: PendingIntentRecord{7925b0e com.medium.reader broadcastIntent}}
08-21 06:39:54.333 1535-4176/? D/MediaSessionService: Sending KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MEDIA_PLAY_PAUSE, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, displayId=0, source=0x0 } to the last known PendingIntent PendingIntent{5b76839: PendingIntentRecord{7925b0e com.medium.reader broadcastIntent}}
08-21 06:39:54.335 1535-1550/? D/StorageManagerService: getExternalStorageMountMode : 1
getExternalStorageMountMode : 3
getExternalStorageMountMode : final mountMode=1, uid : 10324, packageName : com.medium.reader
08-21 06:39:54.335 1535-1550/? I/ApplicationPolicy: isApplicationExternalStorageWh
@magillus
magillus / BackgroundThread.kt
Created September 14, 2017 22:08
RxRealm Flowable wrappers with Looper
package com.example.playground;
import android.os.HandlerThread
import android.os.Process
/**
* Looper based BackgroundThread handler for REalm executions.
*/
class BackgroundThread : HandlerThread("Scheduler-Realm-BackgroundThread", Process.THREAD_PRIORITY_BACKGROUND)
@magillus
magillus / LifecycleObservableTransformer.java
Last active March 29, 2018 05:54
Observable transformer that will act on event of the Lifecycle to auto dispose its subscriptions when the event occurs. By default ON_DESTROY
package com.example.playground;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.OnLifecycleEvent;
import android.support.annotation.NonNull;
import android.util.Log;
import java.lang.ref.WeakReference;
import java.util.Map;
@magillus
magillus / Function.java
Last active June 8, 2017 11:56
Realm Context wrapper, for easy opening realm and closing with action and data return (copyFromRealm).
// copied from Reactive X functions - have your own if no need for full Rx in your project.
package io.reactivex.functions;
/**
* A functional interface that takes a value and returns another value, possibly with a
* different type and allows throwing a checked exception.
*
* @param <T> the input value type
* @param <R> the output value type
*/