Skip to content

Instantly share code, notes, and snippets.

View igorcferreira's full-sized avatar

Igor Castañeda Ferreira igorcferreira

View GitHub Profile
@igorcferreira
igorcferreira / ContentView.swift
Created January 15, 2024 20:14
Fetching view frame, including on List, using GeometryReader
struct ListCellView: View {
struct Selection: Equatable {
let label: String
let frame: CGRect
}
@State private var cellFrame: CGRect = .zero
let label: String
let action: (Selection) async -> Void
@igorcferreira
igorcferreira / FallbackJSONDecoder.swift
Created June 12, 2020 16:15
Demonstrate the usage of protocol for an easier Generic JSONDecoder with Fallback values
/// One of the motivations for this gist is a protocol that receives a Generic value and needs to return a value that may or may not be an optional.
/// Something like:
///
/// protocol Parser {
/// static func parse<T: Decodable>(data: Data) -> T?
/// }
///
/// This causes the issue of having to check the response type, even when you don't want to accept a nil value (ever)
/// let response: String? = parser.parse(data: Data())
/// if response == nil {
@igorcferreira
igorcferreira / URLRequest+Combine.swift
Last active April 28, 2020 23:17
An experiment of how to use Combine+URLRequest.
import Foundation
import Combine
import PlaygroundSupport
func request<Failure: Error, Output: Publisher>(url: URLRequest,
session: URLSession = .shared,
queue: DispatchQueue = .main,
parser: @escaping (Data) -> Output,
parseError: @escaping (Error) -> Failure,
completion: @escaping (Result<Output.Output, Failure>) -> Void) -> AnyCancellable {
/// Method used to retry a UI Test check, and wait for a while before declaring failure.
/// This can be useful to bypass animation or screen transition failures.
/// The original snippet was extracted from [Javi](https://twitter.com/Javi)
/// on a [thread](https://twitter.com/Javi/status/1255181595515863042) regarding UI Test strategies.
///
/// - Parameters:
/// - test: Block that will be evaluated on each test loop
/// - description: Description of the operation. Used on fail message
/// - timeout: Maximum time that will be waited before failing
/// - fatal: Indicator if the failure on the test block will be fatal to the test or not
@igorcferreira
igorcferreira / DynamicNavigationDestinationLink.swift
Last active September 2, 2019 11:27
Small Playground content, showcasing the use of DynamicNavigationDestinationLink to display content from remote source on SwiftUI
@igorcferreira
igorcferreira / .bash_profile
Created April 10, 2018 13:48
Script to kill Xcode derived data
function killdd() {
if pgrep -x "Xcode" > /dev/null
then
killall Xcode
fi
rm -rf ~/Library/Developer/Xcode/DerivedData
open $(xcode-select --print-path)
}
@igorcferreira
igorcferreira / fizzbuzz.swift
Created July 31, 2017 22:12
This is a sample code of the resolution of the FizzBuz code test
import Foundation
//: This is a sample code of the resolution of the FizzBuz code test, explained by [Tom Scott on the YouTube](https://youtu.be/QPZ0pIK_wsc)
/// The InputRule protocol is used to abstract a type that have a specific rule
protocol InputRule {
associatedtype ModifierInput
var rule: ModifierInput { get }
}
@igorcferreira
igorcferreira / CardType.swift
Last active March 6, 2017 14:12
Basic implementation to apply different regexes over a card number String and find the card type
import Foundation
enum CardTypeError:Error {
case TypeNotFound
}
enum CardType:CustomStringConvertible {
case visa
case mastercard
case amex
@igorcferreira
igorcferreira / etica.txt
Last active January 27, 2017 10:08
Resposta à Bunee.io
A publicação de conteúdo em redes sociais não é uma construção de um CV público.
Assim como a contribuição com projetos open source não se caracteriza, por si só, como um portfólio de venda.
Não é porque postei receitas e fiz checkin em restaurantes que tenho pretensão em ser crítico da Michelin.
Vocês indexam e expõe devs como se os mesmos estivessem aptos a serem bombardeados com spam de empresas e propostas de freelas ou projetos irrelevantes para o profissional.
Inclusive, listando tecnologias que a pessoa não domina, gerando uma propaganda falsa.
Foram além e infringiram regras do GitHub para coleção de dados:
https://twitter.com/ezefranca/status/808344095919894529
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack;
import static android.support.test.espresso.action.ViewActions.click;