Skip to content

Instantly share code, notes, and snippets.

View irace's full-sized avatar

Bryan Irace irace

View GitHub Profile
@irace
irace / Codable+JSONObjects.swift
Last active April 17, 2019 15:01
Nearby user discovery through MultipeerConnectivity in 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: [])
}
@irace
irace / ConsoleLogDestination.swift
Last active September 20, 2023 08:04
Simple Swift logger
import Foundation
final class ConsoleLogDestination: LogDestination {
func log(statement: String) {
#if DEBUG
print(statement)
#endif
}
func error(error: Error) {
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
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 November 29, 2017 19:35
UISearchController replacement. Relies on a couple of internal categories, helpers, etc.
//
// 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 April 1, 2017 20:33
Protocol inheritance and associated type specification
/*
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]
@irace
irace / gif.sh
Created January 30, 2017 23:40
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
#
@irace
irace / Keychain.swift
Created November 16, 2016 15:18
Swift Keychain
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 September 19, 2016 21:17
Spotify vs. Apple Music
Spotify Apple Music
Amazon Echo integration Offline Apple Watch playback
Smart playlists