Skip to content

Instantly share code, notes, and snippets.

Avatar

Hugues Bernet-Rollande huguesbr

View GitHub Profile
View extension.swift
// exploration
// add a extension wrapper to any type (like `Reactive` from `RxSwift`)
//: Playground - noun: a place where people can play
import UIKit
struct Extension<Base> {
let base: Base
init(_ base: Base) {
self.base = base
@huguesbr
huguesbr / Reactive.swift
Last active Jul 29, 2018
Reactive proxy
View Reactive.swift
//
// Reactive.swift
// RxSwift
//
// Created by Yury Korolev on 5/2/16.
// Copyright © 2016 Krunoslav Zaher. All rights reserved.
//
/**
Use `Reactive` proxy as customization point for constrained protocol extensions.
@huguesbr
huguesbr / ViewController.swift
Created Apr 5, 2017
Sample RxBluetoothKit implementation
View ViewController.swift
import UIKit
import CoreBluetooth
import RxSwift
import RxBluetoothKit
extension CBUUID {
var type: UUID {
return UUID(rawValue: uuidString)!
}
View unwrap.swift
extension ObservableType {
// unwrap an optional
func unwrap() -> Observable<E> {
return flatMap { $0 == nil ? Observable.empty() : Observable.just($0!) }
}
}
@huguesbr
huguesbr / RxRetryPromptOn.swift
Created Apr 5, 2017
Rx `retryPromptOn` operator. Prompt a user to retry a sequence if an error is emitted
View RxRetryPromptOn.swift
extension ObservableType {
public func retryPromptOn(_ vc: UIViewController) -> Observable<E> {
return self.retryWhen { (error: Observable<Error>) -> Observable<Void> in
return vc.rx.retryPrompt(error: error)
}
}
}
extension Reactive where Base: UIViewController {
func retryPrompt(error: Observable<Error>) -> Observable<Void> {
let retry = PublishSubject<Void>()
@huguesbr
huguesbr / s3.sh
Created Mar 14, 2017 — forked from chrismdp/s3.sh
Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
View s3.sh
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1
@huguesbr
huguesbr / processAnnotatedString.rb
Last active Jul 20, 2017
Automatically replace annotated String (see format below) in Swift with corresponding tr(...) calls for https://github.com/AliSoftware/SwiftGen. Copy both into the project and call 'sh replaceAnnotatedLocalizeString.sh'
View processAnnotatedString.rb
#!/usr/bin/env ruby
# take annotated string and transforms it to the tr(...) format as well as creating the localizable.strings entry
# arguments
localizable=ARGV[0]
filename=ARGV[1]
def makeFirstLetterUpper(string)
string[0].upcase + string[1..-1]
end
@huguesbr
huguesbr / Simplifying your View Controller using Enum.md
Created Jul 3, 2016
FrenchKit 2016 Conference Talk Proposal - Simplifying your View Controller using Enum
View Simplifying your View Controller using Enum.md

Enum is probably one of the most powerful feature of Swift. It's simple, yet it allow to easily build complex Finite State Machine. Let's explore how to extract View Controller's state dependant logic into enum and how to test it separatly.

View Controller often take different state depending of some specific state of the App (fetching data, user logged in/off, ...). This can lead to some internal test condition which clutter your code and are also hard to test. Wrapping up this logic into an enum with associated values allow to split this UI logic piece from the rest of the View Controller logic.

@huguesbr
huguesbr / Building your UI Developer's Toolbox with Playground.md
Last active Jul 3, 2016
FrenchKit 2016 Conference Talk Proposal - Building your UI Developer's Toolbox with Playground
View Building your UI Developer's Toolbox with Playground.md

Building UI can be frustating when it come to tweaking timing, size or others dimensions of your UI component. Let's explore how to build a set of tool that will greatly ease this process in Xcode using Playground.

Timing an animation can be done using CAMediaTimingFunction which can take a prebuild function (Linear, EaseIn, EaseOut, ...) but also modeled after a cubic Bézier curve. It can be tedious to find the right curve shape. Let's build a (almost) drag and drop Playground to tweak any animation using a Bézier curve visual builder.

Preview: http://bit.ly/29gCNnV

@huguesbr
huguesbr / groupedByTests.swift
Last active May 13, 2016
Array groupedBy Extension
View groupedByTests.swift
import Foundation
import XCTest
extension Array {
func groupedByA<Key: Hashable>(mappingClosure: (Element) -> Key?) -> [Key: [Element]] {
return reduce([:]) { (groupedBy, element) in
guard let key = mappingClosure(element) else {
return groupedBy
}
var groupedBy = groupedBy