Skip to content

Instantly share code, notes, and snippets.

View juliancadi's full-sized avatar
♟️

Julian Caicedo juliancadi

♟️
View GitHub Profile
@juliancadi
juliancadi / SomeType.swift
Last active September 7, 2018 10:42
Sequence extension with class having generic types
import Foundation
struct SomeType<T> {
let property: T
}
extension Sequence {
func doMagic<T>() -> [T] where Element == SomeType<T> {
return self.map { $0.property }
@juliancadi
juliancadi / NiblessViewController.swift
Last active June 23, 2023 09:38
Nibless UIViewController in favor of initializer dependency injection.
import UIKit
open class NiblessViewController: UIViewController {
public init() {
super.init(nibName: nil, bundle: nil)
}
@available(*, unavailable,
message: "Loading this view controller from a nib is unsupported in favor of initializer dependency injection."
@juliancadi
juliancadi / NiblessView.swift
Last active December 4, 2018 17:56
Nibless UIView in favor of initializer dependency injection.
import UIKit
open class NiblessView: UIView {
public override init(frame: CGRect) {
super.init(frame: frame)
}
@available(*, unavailable,
message: "Loading this view from a nib is unsupported in favor of initializer dependency injection."
@juliancadi
juliancadi / list.output
Last active January 8, 2019 21:40
'xcrun simctl list' && 'xcrun simctl —version' output
== Device Types ==
iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)
iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)
iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6)
iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus)
iPhone 6s (com.apple.CoreSimulator.SimDeviceType.iPhone-6s)
iPhone 6s Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6s-Plus)
iPhone 7 (com.apple.CoreSimulator.SimDeviceType.iPhone-7)
iPhone 7 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-7-Plus)
@juliancadi
juliancadi / StorageStatusRepository.kt
Last active October 10, 2019 21:03
External storage path
private val externalStoragePath: String?
@RequiresApi(Build.VERSION_CODES.O)
get() {
val externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null)
if (externalFilesDirs.size == 1 && Environment.isExternalStorageEmulated()) { return null }
return externalFilesDirs.filterNotNull().firstOrNull { file ->
Environment.MEDIA_MOUNTED == EnvironmentCompat.getStorageState(file) &&
!file.path.contains(Environment.getExternalStorageDirectory().path)
}?.path.also { logger.debug("External memory path $it") }
}
@juliancadi
juliancadi / MIGRATION_03_04.kt
Created November 5, 2019 22:52
Room migration
database.execSQL("DROP TABLE ${AudioItemEntity.TABLE_NAME}")
database.execSQL("CREATE TABLE IF NOT EXISTS ${AudioItemEntity.TABLE_NAME} (`audioItemId` INTEGER PRIMARY KEY NOT NULL, `audioChannelId` INTEGER NOT NULL, `audioId` TEXT NOT NULL, `audioDescription` TEXT NOT NULL, `duration` INTEGER NOT NULL, `volume` INTEGER NOT NULL, `fileName` TEXT NOT NULL, `index` INTEGER NOT NULL)")
@juliancadi
juliancadi / nested.swift
Last active March 10, 2021 23:50
Nested closures
import Foundation
class Closureception {
deinit {
print("⚠️ Deallocated")
}
// MARK: - Cases
@juliancadi
juliancadi / Combine+Ext.swift
Created March 3, 2020 16:12
Combine side effect
extension Publisher {
public func on(_ f: @escaping (Self.Output) -> Void) -> AnyPublisher<Self.Output, Self.Failure> {
self.map {
f($0)
return $0
}.eraseToAnyPublisher()
}
}
@juliancadi
juliancadi / result.dart
Created June 18, 2021 17:51
Result monad for dart
class Result<Success, Error extends Exception> {
final Success? successIfAny;
final Error? errorIfAny;
const Result.success(this.successIfAny) : errorIfAny = null;
const Result.error(this.errorIfAny) : successIfAny = null;
Result<Success, Error> onSuccess(Function(Success) handler) {
if (successIfAny == null) return this;
handler(successIfAny as Success);