Skip to content

Instantly share code, notes, and snippets.

@r-plus
r-plus / r.md
Last active September 14, 2018 11:25

per_fileオプションのハンドリングをするのはモデル側(or AbstractReporter)の方が良いのではないかと考えています、理由としては

  • ファイルごとの実行時間を出すのを専用のReporterにもっていってしまうと、例えばJSONReporterでJSON形式でファイル毎の実行時間をだそうと思った場合 JSONReporter側でper_fileオプションのハンドリングをしなければならなくなってしまうと思っています。
  • またThresholdオプション+per_fileの場合はファイルの合計時間に対してフィルタリングがかかるべきで、 個別の実行時間をフィルタリングした後の合計値を表示するのはちょっと違うかなと思っています。 で、それを考えると各Reporter側にper_file処理を担当させると各Reporter側で filter_executions をoverrideして threshold処理の前にファイル毎にまとめる処理を入れないとならずそれも微妙かなと。

といったあたりで、まとめると専用のReporterにもっていってしまうと他のReporterで、実装次第でこのオプションの使える使えないが出てきてしまうのではないかなと。

@r-plus
r-plus / openSelectedLinks.js
Created November 19, 2017 09:30
Foxy Gestures user script.
import Foundation
open class CSVDecoder {
public init() {}
open func decode<T: Decodable>(_ type: T.Type, from csv: String) throws -> T {
// let titleRow = rows.removeFirst()
let decoder = _CSVRowDecoder(str: csv)
return try T(from: decoder)
@r-plus
r-plus / autocorrect_unneeded_break_in_switch.md
Last active October 5, 2017 03:35
Swiftlintのunneeded_break_in_switchルール警告行の一括行削除

Swiftlint 0.23 unneeded_break_in_switch 対応

Swiftlint 0.23に unneeded_break_in_switch ルールが追加された。 是非利用したいのだが、既存の警告の量が多い。 autocorrect非対応なので、自動では消してくれない。

breakは単一の行になっているから全部自動で消そう

  1. unneeded_break_in_switch ルールの警告のみが出る状態で swiftlint > warn.txt
  2. 行番号指定で削除するのに昇順だとずれるので、vimで降順にする :g/^/m0
@r-plus
r-plus / Swiftlint_rule.md
Last active August 19, 2017 14:34
Observable.create内でonNextしたらonCompletedが次の行に無いと警告するSwiftlint custom rule

Observable.create内でonNextしたらonCompletedが次の行に無いと警告するSwiftlint custom rule

Task/Promise/Future代わりにObservableを利用する場合、Observable.createするのだが、onNextは1回しかしないのでonNextの次行にonCompletedがなかったら警告する。

custom_rules:
  next_with_completed:
    regex: "\\.create\\s*\\{\\s*\\(?\\w+\\)?\\s*->\\s+Disposable in\\n[\\S\\s]*(onNext\\([\\w]+\\)|on\\(\\.next\\(\\w+\\)\\))\\n(?![^//]+\\.onCompleted)"
    message: "Must call onCompleted event next line of onNext."
    severity: warning
@r-plus
r-plus / basic.md
Last active August 15, 2017 14:13
Migration to RxSwift from Promise: 基本編

Migration to RxSwift from Promise: 基本編

普通のタスクを代替するやり方。 fulfillをonNext+onCompleted rejectをonError にして.successをflatMap(チェーンの最後ならsubscribe)にすれば良い

    func stringTask(_ isSuccess: Bool) -> Observable<String> {
 return Observable.create({ (observer) -&gt; Disposable in
@r-plus
r-plus / reduce+then.md
Last active August 14, 2017 14:27
Migration to RxSwift from Promise: reduce+then編

PromiseからRxSwiftへの移行reduce+then編

Promise

[Promise]をreduceとthenで全部つなげる使い方

let promises: [Promise<Void>] = promises()
promises.reduce(Promise<Void>.resolve()) { (acc, val) In
    return acc.then(val)
}.then { _ in
    print("finish all promises")
@r-plus
r-plus / SequentiallyAll.md
Last active August 13, 2017 07:32
SequentiallyAll processing for RxSwift migrate from Promise.

SequentiallyAll

Promise

allだとすべてのPromiseが同時に実行状態になり、100程のPromiseをallしたい場合リソースを大量食いするので並列度を抑えて逐次的に処理しつつ全部が終わったら次の処理をしたい。
SwiftTaskではallに渡すTaskを全てpause状態で作成しておいてon(success)でまだ実行されていないTaskをresumeして実現
Hydraでは同じ実装をPRして入っている https://github.com/malcommac/Hydra/blob/master/Sources/Hydra/Promise%2BAll.swift#L47

RxSwift

zipかcombineLatestで渡した全てのObservableのイベントが揃うまで待てる(Promise的all)
どちらにしても渡した全Observableはsubscribeされてしまうので、Observable.createのclosureはその段階で実行されてしまう。
OperationQueueを利用するスケジューラであるOperationQueueSchedulerを作成しzipのあとにsubscribeOnしてみたが全Observableが一気にsubscribeされてしまう事に変わりはなかった。

@r-plus
r-plus / save_shsh2.sh
Created December 20, 2016 16:00
Save shsh2 with nonce and without nonce.
ecid=XXXXXXXXXX
model=iPhone9,1
function saveWithNonce() {
if [ "$#" -eq 3 ]; then
./tsschecker_macos -d $model -e $ecid -i $1 --buildid $3 -s --apnonce $2
else
./tsschecker_macos -d $model -e $ecid -i $1 -s --apnonce $2
fi
filename=$(ls ${ecid}*)
よく忘れるのでメモ. 末尾の2桁の数字お41から1ずつ増やす
:'<,'>RengBang \(\d\d$\) 41 1