Skip to content

Instantly share code, notes, and snippets.

View cmc5788's full-sized avatar
🖥️
writing code, hopefully

Christopher Casey cmc5788

🖥️
writing code, hopefully
View GitHub Profile
@cmc5788
cmc5788 / coverage_badge.svg
Created December 21, 2021 22:41
coverage_badge
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cmc5788
cmc5788 / async_noti.dart
Created June 29, 2021 18:11
AsyncChangeNotifier
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:rxdart/rxdart.dart';
typedef TaskNotifier = void Function(VoidCallback notify);
typedef TaskWorker = Stream<void> Function(TaskNotifier notifier);
@cmc5788
cmc5788 / main.dart
Last active June 29, 2021 03:57
Leaked stream in async
import 'dart:async';
Future<void> foo() async {
await for (final i in Stream<int>.periodic(const Duration(milliseconds: 500), (x) => x)) {
print('$i');
}
}
void main() async {
// once this is awaited, the inner implicit stream subscription is uncancalleble
@cmc5788
cmc5788 / main.dart
Last active February 21, 2021 18:07
updated bloc / reducer_bloc
import 'dart:async';
import 'dart:math';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:rxdart/rxdart.dart';
//
@cmc5788
cmc5788 / AnimUtil.java
Created August 20, 2017 16:28
Rx animation utils for android
public final class AnimUtil {
public static final ViewAction VISIBLE_RESET = new ViewAction() //
.visibility(View.VISIBLE).alpha(1f).scale(1f).translationX(0).translationY(0).lock();
public static final ViewAction GONE_RESET = new ViewAction() //
.visibility(View.GONE).alpha(1f).scale(1f).translationX(0).translationY(0).lock();
public static final ViewAction VISIBLE_RESET_ZERO_ALPHA = new ViewAction() //
.visibility(View.VISIBLE).alpha(0f).scale(1f).translationX(0).translationY(0).lock();
@cmc5788
cmc5788 / RxCollectionView.swift
Last active April 11, 2017 05:25
rxy collection view
import UIKit
import RxSwift
class RxCollectionView<Element : Comparable>: UICollectionView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
public typealias E = Element
var elements : [E] = []
public var cellSizeChooser : (RxCollectionView<E>, E, Int) -> CGSize = { cv, _, _ in
let dim = cv.bounds.size.width / 3.0
@cmc5788
cmc5788 / JSON+Util.swift
Last active April 7, 2017 03:23
Swift JSON / Rx utils
import RxSwift
public protocol StringProtocol {}
extension String : StringProtocol {}
public typealias JSON = [String : AnyObject]
extension ObservableType where Self.E == Any? {
public func mapToJSON() -> RxSwift.Observable<JSON> {
public func shareReplayLatestWhileConnectedWithLinger(_ delayTime : RxTimeInterval, scheduler : SchedulerType = Schedulers.main) -> RxSwift.Observable<Self.E> {
let sharedSource = self.concat(Observable.empty()
.delaySubscription(delayTime, scheduler: scheduler))
.shareReplayLatestWhileConnected()
return Observable<Self.E>.create { observer in
let sub = sharedSource.subscribe(onNext: {
@cmc5788
cmc5788 / Rx+Util.swift
Last active November 14, 2020 01:34
General RxSwift utility stuffs
import RxSwift
extension UIButton {
public func throttledTapObservable(_ throttle : RxTimeInterval = 1.0) -> RxSwift.Observable<Swift.Void> {
return self.rx.tap.asObservable()
.throttle(throttle, latest: false, scheduler: MainScheduler.instance)
}
}
@cmc5788
cmc5788 / DataRequest+Rx.swift
Last active July 10, 2017 03:55
Alamofire, Rxified
import Alamofire
import RxSwift
extension DataRequest {
public func observeResponseJSON() -> Observable<Any?> {
let original = self.request!
return Observable.create { observer in