Skip to content

Instantly share code, notes, and snippets.

Igor Castañeda Ferreira igorcferreira

View GitHub Profile
@igorcferreira
igorcferreira / FallbackJSONDecoder.swift
Created Jun 12, 2020
Demonstrate the usage of protocol for an easier Generic JSONDecoder with Fallback values
View FallbackJSONDecoder.swift
/// 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 Apr 28, 2020
An experiment of how to use Combine+URLRequest.
View URLRequest+Combine.swift
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 {
View XCTestCase+UI.swift
/// 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 Sep 2, 2019
Small Playground content, showcasing the use of DynamicNavigationDestinationLink to display content from remote source on SwiftUI
View DynamicNavigationDestinationLink.swift
@igorcferreira
igorcferreira / .bash_profile
Created Apr 10, 2018
Script to kill Xcode derived data
View .bash_profile
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 Jul 31, 2017
This is a sample code of the resolution of the FizzBuz code test
View fizzbuzz.swift
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 Mar 6, 2017
Basic implementation to apply different regexes over a card number String and find the card type
View CardType.swift
import Foundation
enum CardTypeError:Error {
case TypeNotFound
}
enum CardType:CustomStringConvertible {
case visa
case mastercard
case amex
@igorcferreira
igorcferreira / etica.txt
Last active Jan 27, 2017
Resposta à Bunee.io
View etica.txt
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
View MainActivityTestCase.java
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;
View playback-gpx.py
#!/usr/bin/env python
import sys
import logging
from optparse import OptionParser
import os
import gpxpy
import gpxpy.gpx
import time
from subprocess import check_output
You can’t perform that action at this time.