Skip to content

Instantly share code, notes, and snippets.

🏠
Working

Ivan Terekhin JEuler

🏠
Working
View GitHub Profile
@JEuler
JEuler / mime_to_extension.dart
Created Feb 9, 2020
MIME type to extension (dart) (media)
View mime_to_extension.dart
String mimeToExtension(String mime) {
switch (mime.toLowerCase()) {
case 'image/apng':
return 'apng';
case 'image/bmp':
return 'bmp';
case 'image/gif':
return 'gif';
case 'image/x-icon':
return 'ico';
View storage_service_example_impl.dart
/// Implementation of StorageService using Hive Key-Value DB
class StorageServiceImpl implements StorageService {
@override
Future saveUser(User user) async {
final userToSave = DBUser(
user.id,
user.name,
user.avatar);
final usersBox = await Hive.openBox('user');
View storage_service_example.dart
abstract class StorageService {
/// Save user to D
void saveUser(User user);
/// Get user from DB
Future<DBUser> getUser();
/// Stop all operations
void stop();
}
@JEuler
JEuler / some_kind_of_store.dart
Last active Dec 10, 2019
MobX Store example
View some_kind_of_store.dart
part 'some_kind_of_store.g.dart';
/// User Resources Store
class SomeKindOfStore = SomeKindOfStoreBase with _$SomeKindOfStore;
/// User Resources Store
abstract class SomeKindOfStoreBase with Store {
final WebService _webService;
final StorageService _storageService;
@JEuler
JEuler / flutter_app.dart
Last active Dec 10, 2019
FlutterAppMultiProvider
View flutter_app.dart
class FlutterApp extends StatelessWidget {
final WebService _webService;
final StorageService _storageService;
FlutterApp(this._webService, this._storageService);
@override
Widget build(BuildContext context) {
var localizationDelegate = LocalizedApp.of(context).delegate;
@JEuler
JEuler / reg_comments.txt
Created Sep 4, 2019
Regular to match comments.
View reg_comments.txt
"[^"\\]*(?:\\[\W\w][^"\\]*)*"|(\/\/.*)
View BaseActivityRx.kt
protected fun <T> subscribe(observable: Observable<T>?, observer: Observer<T>?, bind: Boolean = true) {
if (observable != null && observer != null) {
if (bind) {
observable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread(), true)
.bindToLifecycle(this)
.subscribe(observer)
} else {
observable
View BaseActivityRx.java
protected <T> void autoResubscribe(Observable<T> observable, ResubscriptionObserver<T> resubscriptionObserver) {
if (getObservableGroup() != null && observable != null) {
observable
.compose(getObservableGroup().<T>transform((String) resubscriptionObserver.resubscriptionTag()))
.compose(applySchedulers())
.subscribe(resubscriptionObserver);
}
}
@JEuler
JEuler / SendDataJob.kt
Created Feb 25, 2019
Priority queue job example
View SendDataJob.kt
class SendDataJob(private val dataInput: SomeDataClass) :
Job(Params(1).requireNetwork().persist().groupBy(“tag”)), KoinComponent {
// job is queued, need to update local storage
override fun onAdded() {
}
@Throws(Throwable::class)
override fun onRun() {
val sendService: SendService? by inject()
sendService?.sendData(dataInput)
@JEuler
JEuler / SendDataWorker.kt
Created Feb 25, 2019
SendData Worker example
View SendDataWorker.kt
class SendDataWorker(context: Context, params: WorkerParameters) : Worker(context, params), KoinComponent {
@SuppressLint("CheckResult")
override fun doWork(): Result {
val sendService: SendService? by inject()
val data = inputData.getString("data")
val dataInput = getGsonForJoda()?.fromJson(data, SomeDataClass::class.java)
return try {
val query = sendService?.sendData(dataInput)
?.blockingGet()
You can’t perform that action at this time.