Skip to content

Instantly share code, notes, and snippets.

View zoejessica's full-sized avatar
🐗

Zoë Smith zoejessica

🐗
View GitHub Profile
@zoejessica
zoejessica / DarwinNotificationCenter.swift
Created April 26, 2020 00:22 — forked from AvdLee/DarwinNotificationCenter.swift
A notification center for Darwin Notifications. MIT License applies.
//
// DarwinNotificationCenter.swift
//
// Copyright © 2017 WeTransfer. All rights reserved.
//
import Foundation
/// A Darwin notification payload. It does not contain any userInfo, a Darwin notification is purely event handling.
public struct DarwinNotification {
@zoejessica
zoejessica / Withable.swift
Created April 24, 2020 23:33 — forked from nicklockwood/Withable.swift
Withable.swift
/// Withable is a simple protocol to make constructing
/// and modifying objects with multiple properties
/// more pleasant (functional, chainable, point-free)
public protocol Withable {
init()
}
public extension Withable {
/// Construct a new instance, setting an arbitrary subset of properties
init(with config: (inout Self) -> Void) {
@zoejessica
zoejessica / PagerView.swift
Created December 26, 2019 21:58 — forked from mecid/PagerView.swift
PagerView in SwiftUI
//
// PagerView.swift
//
// Created by Majid Jabrayilov on 12/5/19.
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
struct PagerView<Content: View>: View {
let pageCount: Int
@zoejessica
zoejessica / list-selection.swift
Created August 18, 2019 23:39
Showing a selection in a SwiftUI List from an observable object (not working atm!)
class Context: ObservableObject {
init(selectedIngredients: Set<Ingredient>, ingredients: [Ingredient]) {
self.selectedIngredients = selectedIngredients
self.ingredients = ingredients
}
@Published var selectedIngredients: Set<Ingredient>
let ingredients: [Ingredient]
}
@zoejessica
zoejessica / ApproximateValuesSnapshotting.swift
Last active March 4, 2019 01:42
Custom diffing strategy for the pointfree.co swift-snapshot library, to compare dictionaries of named floating point values within a given percentage accuracy threshold.
import Foundation
import SnapshotTesting
import XCTest
public typealias NamesToValues = [String : Double]
public func approximateValues(tolerance percentage: Double) -> SimplySnapshotting<NamesToValues> {
let diffingStrategy = Diffing.approximateValues(tolerance: percentage)
return SimplySnapshotting.init(pathExtension: "json", diffing: diffingStrategy)
}
import Foundation
import CoreData
import CloudKit
// https://github.com/macmade/user-defaults/blob/master/swift/Preferences.swift
/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2017 Jean-David Gadina - www.xs-labs.com
@zoejessica
zoejessica / Activity.swift
Created July 8, 2017 14:33 — forked from zwaldowski/Activity.swift
os_activity_t for Swift 3
//
// Activity.swift
//
// Created by Zachary Waldowski on 8/21/16.
// Copyright © 2016 Zachary Waldowski. Licensed under MIT.
//
import os.activity
private final class LegacyActivityContext {
@zoejessica
zoejessica / multilinelabelnode.swift
Created April 29, 2017 09:56
Multiline SKLabelNode in Swift 3
// from https://oleb.net/blog/2016/08/swift-3-strings/
extension String {
func wrapped(after: Int) -> [String] {
var i = 0
let lines = self.characters.split(omittingEmptySubsequences: false) { character in
switch character {
case "\n",
" " where i >= after:
i = 0
@zoejessica
zoejessica / multilinelabelnode.swift
Created April 29, 2017 09:56
Multiline SKLabelNode in Swift 3
// from https://oleb.net/blog/2016/08/swift-3-strings/
extension String {
func wrapped(after: Int) -> [String] {
var i = 0
let lines = self.characters.split(omittingEmptySubsequences: false) { character in
switch character {
case "\n",
" " where i >= after:
i = 0

Keybase proof

I hereby claim:

  • I am zoejessica on github.
  • I am zoejessica (https://keybase.io/zoejessica) on keybase.
  • I have a public key whose fingerprint is FB40 ACD5 4224 8770 4470 6C39 035A F65B 02C1 4E6B

To claim this, I am signing this object: