Skip to content

Instantly share code, notes, and snippets.

⚾️
baseball

Gordon Fontenot gfontenot

⚾️
baseball
Block or report user

Report or block gfontenot

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gfontenot
gfontenot / Sample.swift
Created Feb 15, 2020
Swift UI sample of layout bug
View Sample.swift
import SwiftUI
struct Sample: View {
var body: some View {
NavigationView {
WebView(url: URL(string: "https://example.com")!)
.navigationBarItems(
trailing: Button(
action: { },
label: { Text("Done") }
@gfontenot
gfontenot / ElmSpike.swift
Created Aug 3, 2018
Quick spike on an elm-ish architecture in Swift
View ElmSpike.swift
// Dumb value types representing UIViews. Comperable to our current models like Button.Model
struct StackView<Message> {
let children: [View<Message>]
}
struct Label {
let text: String
}
View CaseEnumeration.swift
func assert(_ cond: @autoclosure () -> Bool) -> String {
if cond() {
return ""
} else {
return ""
}
}
#if !swift(>=4.2)
protocol KnownEnum: RawRepresentable, Hashable where RawValue == String {
View goroutines.swift
import Foundation
enum Message<T> {
case value(T)
case finished
}
protocol Channel: IteratorProtocol {
func send(_ value: Message<Element>)
}
@gfontenot
gfontenot / Decoding.swift
Created Jul 22, 2015
Example of using partial application as a way to solve side loaded JSON with immutable value objects
View Decoding.swift
// Returning a function here, instead of a fully realized object
extension Company: Decodable {
static func decode(j: JSON) -> Decoded<[People] -> Company> {
return create
<^> j <| "id"
<*> j <| ["attributes", "name"]
}
}
View properties.swift
// stored property, no default value
let foo: String
// stored property, default value
let foo: String = "foo"
// or
let foo = "foo"
// computed property, no custom setter
var foo: String {
View functionalRefactor.swift
// Original implementation with multiple returns:
class func fromId(id: String) -> Office? {
let officesData = JSONData.load("offices") as? [[String: String]] ?? []
let officeData = officesData.filter { $0["id"] == id }.first
if let office = officeData {
return decode(JSONValue.parse(office))
}
@gfontenot
gfontenot / decodeDict.swift
Created Feb 19, 2015
example of decoding dictionary objects with Argo/FP
View decodeDict.swift
import Argo
import Runes
func +<T, V>(lhs: [T: V], rhs: [T: V]) -> [T: V] {
var dict = lhs
for (key, val) in rhs {
dict[key] = val
}
return dict
View requests.swift
import Foundation
infix operator >>- { associativity left precedence 150 }
public func >>-<T, U>(a: T?, f: T -> U?) -> U? {
return a.flatMap(f)
}
extension Optional {
func flatMap<U>(f: T -> U?) -> U? {
switch self {
View DispatchgGroup.swift
import Foundation
class DispatchGroup {
private var blocks: [dispatch_block_t] = []
private let dispatch_queue = dispatch_queue_create("com.dispatch_group.foo", DISPATCH_QUEUE_CONCURRENT)
private let dispatch_group = dispatch_group_create()
func andThen(block: dispatch_block_t) -> Group {
blocks += [block]
return self
You can’t perform that action at this time.