Skip to content

Instantly share code, notes, and snippets.

View huguesbr's full-sized avatar

Hugues Bernet-Rollande huguesbr

View GitHub Profile
@huguesbr
huguesbr / extension.swift
Created April 6, 2017 10:19
Extension wrapper
// 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 July 29, 2018 07:39
Reactive proxy
//
// 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 April 5, 2017 15:17
Sample RxBluetoothKit implementation
import UIKit
import CoreBluetooth
import RxSwift
import RxBluetoothKit
extension CBUUID {
var type: UUID {
return UUID(rawValue: uuidString)!
}
@huguesbr
huguesbr / unwrap.swift
Created April 5, 2017 08:50
Rx Extensions
extension ObservableType {
// unwrap an optional
func unwrap() -> Observable<E> {
return flatMap { $0 == nil ? Observable.empty() : Observable.just($0!) }
}
}
@huguesbr
huguesbr / RxRetryPromptOn.swift
Created April 5, 2017 08:44
Rx `retryPromptOn` operator. Prompt a user to retry a sequence if an error is emitted
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 March 14, 2017 14:03 — forked from chrismdp/s3.sh
Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
# 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 July 20, 2017 17:32
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'
#!/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 July 3, 2016 08:57
FrenchKit 2016 Conference Talk Proposal - Simplifying your View Controller using Enum

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 July 3, 2016 08:57
FrenchKit 2016 Conference Talk Proposal - Building your UI Developer's Toolbox with Playground

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 08:54
Array groupedBy Extension
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