Skip to content

Instantly share code, notes, and snippets.

View wata's full-sized avatar

Wataru Nagasawa wata

View GitHub Profile
module Fluent
class ChatworkOutput < BufferedOutput
Fluent::Plugin.register_output('chatwork', self)
config_param :api_token, :string
config_param :room, :string, :default => nil
config_param :proxy, :string, :default => nil
config_param :title, :string, :default => nil
config_param :flush_interval, :time, :default => 1
@wata
wata / log.swift
Last active April 9, 2018 11:34
XCGLogger のログ送り先を Crashlytics にする
// SEE ALSO: https://github.com/DaveWoodCom/XCGLogger/pull/78#issuecomment-256779363
open class CrashlyticsLogDestination: BaseDestination {
public override init(owner: XCGLogger?, identifier: String = "\(XCGLogger.Constants.baseIdentifier).logdestination.crashlytics") {
super.init(owner: owner, identifier: identifier)
showDate = false
}
open override func output(logDetails: LogDetails, message: String) {
let args: [CVarArg] = [message]
@wata
wata / Logger.swift
Last active June 13, 2024 02:00
os_log と Crashlytics を使ったロガークラス
import Foundation
import os.log
import FirebaseCrashlytics
extension OSLogType: CustomStringConvertible {
public var description: String {
switch self {
case OSLogType.debug: return "🔹🔹🔹"
case OSLogType.info: return "ℹ️ℹ️ℹ️"
case OSLogType.error: return "‼️‼️‼️"
@wata
wata / UIViewController+Extensions.swift
Created May 9, 2018 05:45
クラス名を指定して型判定する
import UIKit
extension UIViewController {
func isKind(ofClassName className: String) -> Bool {
guard let klass = NSClassFromString(className) else {
return false
}
return self.isKind(of: klass)
}
}
@wata
wata / AVAsset+Extensions.swift
Last active May 30, 2018 15:33
AVAsset (video) から音声削除
extension AVAsset {
// Modified from: https://stackoverflow.com/questions/42383260/swift-remove-audio-from-video
var silentVideoAsset: AVAsset? {
let composition = AVMutableComposition()
guard
let videoTrack = self.tracks(withMediaType: .video).first,
let compositionVideoTrack = composition.addMutableTrack(withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid)
else { return nil }
import UIKit
class BlurredImageView: UIImageView {
private let blurEffectView: UIVisualEffectView = {
let blurEffect = UIBlurEffect(style: .light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
return blurEffectView
}()
@wata
wata / PHFetchOptions.md
Last active August 9, 2020 21:04
Exclude by mediaSubtype is broken

SEE ALSO: https://forums.developer.apple.com/thread/44133

predicate result
NSPredicate(format: "(mediaSubtype & %d) == 0", PHAssetMediaSubtype.photoScreenshot.rawValue) x Exclude "mediaSubtype equals photoScreenshot" and "no mediaSubtype" and "mediaSubtype equals 0" (These means excluding video)
NSPredicate(format: "mediaSubtype != %d", PHAssetMediaSubtype.photoScreenshot.rawValue) x same
NSPredicate(format: "NOT ((mediaSubtype & %d) != 0)", PHAssetMediaSubtype.photoScreenshot.rawValue) o Exclude only "mediaSubtype equals photoScreenshot"
@wata
wata / UIView+Fade.swift
Last active July 25, 2018 11:49
Animations of FadeIn / FadeOut
// Modified from: https://qiita.com/mono0926/items/c53b2e46e51a0b0bbf06
enum FadeType: TimeInterval {
case normal = 0.2
case slow = 1.0
}
extension UIView {
func fadeIn(_ type: FadeType = .normal, completion: (() -> Void)? = nil) {
self.alpha = 0
@wata
wata / backHomeIfNeeded.swift
Created July 31, 2018 12:05
Resume from the home screen when the application becomes active
private func backHomeIfNeeded() {
guard
self.needsBackHome,
!(UIApplication.shared.topViewController is UIAlertController)
else { return }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
Router.go(to: .home)
}
}
protocol CollectionReusable {
static func register(in collectionView: UICollectionView)
static func dequeue(from collectionView: UICollectionView, for indexPath: IndexPath) -> Self?
}
extension CollectionReusable where Self: UICollectionReusableView {
static func register(in collectionView: UICollectionView) {
collectionView.register(self, forCellWithReuseIdentifier: String(describing: Self.self))
}