Skip to content

Instantly share code, notes, and snippets.

View huguesbr's full-sized avatar

Hugues Bernet-Rollande huguesbr

View GitHub Profile
@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 / global_variable_demo.swift
Created April 15, 2016 16:18
Simple global demo of global variable features (computed, willSet, didSet)
import XCTest
import Foundation
var testCases: [AnyClass] = []
class computedTests: XCTestCase {
let formula = 2 * M_PI
func testComputedGet() {
var radius: Double = 1
@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 / 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 / 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 / PhotoWriter.swift
Created April 10, 2017 12:44
Photo Writer - Sample Rx wrapper around the global function UIImageWriteToSavedPhotosAlbum
import Foundation
import UIKit
import RxSwift
class PhotoWriter: NSObject {
typealias Callback = (NSError?)->Void
let disposeBag = DisposeBag()
private var callback: Callback
init(callback: @escaping Callback) {
### Keybase proof
I hereby claim:
* I am huguesbr on github.
* I am rompelstilchen (https://keybase.io/rompelstilchen) on keybase.
* I have a public key ASDQjwFy183WMCQdyGvC9Y4nqKpzduv8nitFSnyuCH8W8go
To claim this, I am signing this object:
@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 / 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