Skip to content

Instantly share code, notes, and snippets.

Ben Kreeger kreeger

Block or report user

Report or block kreeger

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
@kreeger
kreeger / HTTPRecording.swift
Created Dec 27, 2019
A convenient way to mock out URL requests in Swift tests.
View HTTPRecording.swift
//
// HTTPRecording.swift
//
import Foundation
struct HTTPRecording {
let statusCode: Int
let httpVersion: String
let headers: [String: String]
View cloudSettings
{"lastUpload":"2020-04-06T03:45:10.794Z","extensionVersion":"v3.4.3"}
View bootstrap-macOS.sh
#!/usr/bin/env bash
#
# bootstrap-macOS.sh
# Install Xcode, make sure Mackup's files are downloaded, and then run this script.
#
# Install Xcode command line tools.
sudo xcode-select --install
View keybase.md

Keybase proof

I hereby claim:

  • I am kreeger on github.
  • I am kreeger (https://keybase.io/kreeger) on keybase.
  • I have a public key whose fingerprint is 65B5 0868 E045 FAEE E978 139E 876B 0A70 25B3 B62D

To claim this, I am signing this object:

@kreeger
kreeger / linux-bootstrap.sh
Last active Jan 26, 2019
Future machine setup. Run as root.
View linux-bootstrap.sh
# Update apt and such
apt update
apt upgrade -y
apt dist-upgrade -y
# Add apt keys
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | apt-key add -
wget -q https://download.sublimetext.com/sublimehq-pub.gpg -O- | apt-key add -
@kreeger
kreeger / DataSourceUsage.swift
Created Jan 8, 2019
Example data source usage code for the blog post "Flapjack" on O'Reilly's engineering blog.
View DataSourceUsage.swift
let dataSourceFactory = CoreDataSourceFactory(dataAccess: dataAccess)
let queryAttributes = ["radius": 2.0, "flavor": "Chocolate Chip"]
let dataSource: CoreDataSource<Pancake> = dataSourceFactory.vendObjectsDataSource(attributes: queryAttributes, sectionProperty: "flavor", limit: 100)
// Prepare yourself for pancakes, but only chocolate chip ones bigger than a 2" radius, and no more than 100.
// This block fires every time the data source picks up an insert/change/deletion.
dataSource.onChange = { itemChanges, sectionChanges in
// If you've added `Flapjack/UIKit` to your Podfile, you get helper extensions!
self.tableView.performBatchUpdates(itemChanges, sectionChanges: sectionChanges)
// Get a specific pancake:
print("\(String(describing: dataSource.object(at: IndexPath(item: 0, section: 0))))")
@kreeger
kreeger / DeleteDatabase.swift
Created Jan 8, 2019
Example database deletion code for the blog post "Flapjack" on O'Reilly's engineering blog.
View DeleteDatabase.swift
dataAccess.deleteDatabase(rebuild: true) { error in
if let error = error {
print(error.localizedDescription)
}
// It's almost as if it never happened.
}
@kreeger
kreeger / PerformInBackground.swift
Created Jan 8, 2019
Example background execution code for the blog post "Flapjack" on O'Reilly's engineering blog.
View PerformInBackground.swift
dataAccess.performInBackground { [weak self] context in
let pancake = context.create(Pancake.self, attributes: ["flavor": flavor, "radius": radius, "height": height])
let error = context.persist()
DispatchQueue.main.async {
guard let self = self else { return }
let foregroundPancake = self.dataAccess.mainContext.object(ofType: Pancake.self, objectID: pancake.objectID)
completion(foregroundPancake, error)
}
}
@kreeger
kreeger / FetchUsage.swift
Created Jan 8, 2019
Example fetch code for the blog post "Flapjack" on O'Reilly's engineering blog.
View FetchUsage.swift
// Get every pancake.
let pancakes = dataAccess.mainContext.objects(ofType: Pancake.self)
// Get just the chocolate chip ones.
let pancakes = dataAccess.mainContext.objects(ofType: Pancake.self, attributes: ["flavor": "Chocolate Chip"])
// Create your own.
let pancake = dataAccess.mainContext.create(Pancake.self, attributes: ["flavor": "Rhubarb"])
// Save your changes.
let error = context.persist()
@kreeger
kreeger / Pancake.swift
Created Jan 8, 2019
Example model implementation code for the blog post "Flapjack" on O'Reilly's engineering blog.
View Pancake.swift
extension Pancake: DataObject {
// The type of your primary key, if you have one of your own.
public typealias PrimaryKeyType = String
// The name of the entity as Core Data knows it.
public static var representedName: String {
return "Pancake"
}
// The key path to your model's primary key.
public static var primaryKeyPath: String {
return #keyPath(identifier)
You can’t perform that action at this time.