Skip to content

Instantly share code, notes, and snippets.

Avatar

Bryan Irace irace

View GitHub Profile
@irace
irace / Codable+JSONObjects.swift
Last active Apr 17, 2019
Nearby user discovery through MultipeerConnectivity in Swift
View Codable+JSONObjects.swift
import Foundation
/**
Extensions that allow `JSONEncoder` and `JSONDecoder` to produce/consume dictionaries, instead of simply raw data.
*/
extension JSONEncoder {
func encodeAsJSONObject<T>(_ value: T) throws -> Any where T: Encodable {
return try JSONSerialization.jsonObject(with: try encode(value), options: [])
}
View ConsoleLogDestination.swift
import Foundation
final class ConsoleLogDestination: LogDestination {
func log(statement: String) {
#if DEBUG
print(statement)
#endif
}
func error(error: Error) {
View DeduplicatingCollectionViewSelector.swift
import UIKit
/**
Enables smooth collection view selection by de-duplicating calls to `selectItemAtIndexPath:animated:scrollPosition:`
If `selectItemAtIndexPath:animated:scrollPosition:` is being driven off of something like `scrollViewDidScroll:`
delegate calls, we’d likely be invoking the former needlessly, with the same index path. This can result in jerky
scrolling.
This class will ensure that we ignore any calls to `selectItemAtIndexPath:animated:scrollPosition:` that are identical
View long-function-bodies.rb
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'ServiceKit' || target.name == 'SharedUI' || target.name == 'ContactPicker'
target.build_configurations.each do |config|
if config.name == 'Debug'
config.build_settings['OTHER_SWIFT_FLAGS'] = '-Xfrontend -warn-long-function-bodies=100'
else
config.build_settings['OTHER_SWIFT_FLAGS'] = ''
end
end
@irace
irace / SearchController.swift
Last active Nov 29, 2017
UISearchController replacement. Relies on a couple of internal categories, helpers, etc.
View SearchController.swift
//
// SearchController.swift
// Prefer
//
// Created by Bryan Irace on 5/31/17.
// Copyright © 2017 Prefer. All rights reserved.
//
import RxSwift
import RxCocoa
@irace
irace / Protocols.swift
Last active Apr 1, 2017
Protocol inheritance and associated type specification
View Protocols.swift
/*
This Swift bug seems to be related: https://bugs.swift.org/browse/SR-2235. Seems as though
the different ways that worked previously might have never actually been intended?
*/
protocol DataVendor {
associatedtype Vended
var data: [Vended]
View gif.sh
#!/bin/bash
#
# A simple script to generate an animated gif from an mp4 file.
#
# Some notes:
# - To use this you need both ffmpeg and imagemagick installed. You can 'brew install' both of them.
# - Our version of github enterprise has a 10MB size limit per file. Make sure your gifs are below that limit.
#
# This is based on https://gist.github.com/dergachev/4627207
#
View Keychain.swift
import Foundation
import Result
import Security
/**
* A simple wrapper around the Security framework’s keychain functions, providing a Swifty-er API.
*/
typealias KeychainQuery = [String: Any]
struct Keychain {
@irace
irace / music.md
Created Sep 19, 2016
Spotify vs. Apple Music
View music.md
Spotify Apple Music
Amazon Echo integration Offline Apple Watch playback
Smart playlists
View TargetActionSectionFooterTitleView.swift
import UIKit
/**
A drop-in replacement for the `UITableView`’s default section footer title, adding support for inline links. This class
will call the same, single target/action pair for *all* inline links, regardless of what their `NSLinkAttributeName`
values are. If you need to support multiple different inline links, this class is not for you.
Instead of implementing `tableView(tableView:titleForFooterInSection:)` and returning a string, implement
`tableView(tableView:, viewForFooterInSection section: Int)` and return an instance of this class.