Skip to content

Instantly share code, notes, and snippets.

@SlappyAUS
SlappyAUS / propertyList.swift
Created October 8, 2020 09:56
Property List #data
// Mark "Item" struct as Codable
var itemArray: [Item] = []
let dataFilePath =
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
.first?
.appendingPathComponent("Items.plist")
func loadModel() {
if let data = try? Data(contentsOf: dataFilePath!) {
@SlappyAUS
SlappyAUS / coreData.swift
Last active October 9, 2020 23:51
CoreData #data #coreData
// App Delegate
import CoreData
func applicationWillTerminate(_ application: UIApplication) {
self.saveContext()
}
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
@SlappyAUS
SlappyAUS / camera_and_photo_selector.swift
Last active October 17, 2020 09:11
Camera and photo selector #ui
//
// ViewController.swift
// WhatFlower
//
// Created by Greg Eales on 17/10/20.
//
import UIKit
// TODDO: Add to .plist
@SlappyAUS
SlappyAUS / image_classification_model.swift
Last active October 17, 2020 09:11
Image Classification Model #coreml
import CoreML
import Vision
func detectImage(image: CIImage) {
guard let model = try? VNCoreMLModel(for: FlowerClassifier().model) else {
fatalError("Could not load CoreML model")
}
let request = VNCoreMLRequest(model: model) { (request, err) in
guard let results = request.results as? [VNClassificationObservation] else {
@SlappyAUS
SlappyAUS / git_cheat_sheet.md
Last active October 17, 2020 09:11
Git Cheat Sheet #cheatsheet

GIT Cheatsheet

git init
git status
git add [filename]			(add to staging area)
git add -A					(add all to staging)
git reset [filename]			(remove from staging)
git commit -m “message”		(commit from staging)
git commit -a -m “message”	(stage and commit)

git clone

@SlappyAUS
SlappyAUS / conda_environments.md
Last active October 17, 2020 09:10
Conda Environments #cheatsheet

1. Check conda is installed and in your PATH

Open a terminal client.
Enter conda -V into the terminal command line and press enter.
If conda is installed you should see somehting like the following.\

$ conda -V
conda 3.7.0

2. Check conda is up to date

@SlappyAUS
SlappyAUS / cocoa_pods_cheat_sheet.md
Last active October 17, 2020 09:17
Cocoapods Cheat sheet #cheatsheet

Cocoapods-Cheatsheet

Useful commands etc. for Cocoapods

Installation

Command                                          Description
pod init creates a Podfile for the current directory if none currently exists
pod install Downloads all dependencies defined in Podfile and creates an Xcode Pods library project in ./Pods
@SlappyAUS
SlappyAUS / podfile_cheatsheet.md
Created October 17, 2020 09:21
Podfile #cheatsheet

Cocoa Pods Cocoapods Basic Cheat Sheet

Create a Podfile at the root of your project

platform :ios, '5.0'

pod 'AFNetworking'
pod 'OHAttributedLabel'
@SlappyAUS
SlappyAUS / closures.swift
Created October 19, 2020 00:23
closures #syntax
// Custom closure with escaping
func getSentimentScore(searchTerm: String, scoreCallback: @escaping (_ score: Int) -> Void) {
}
@SlappyAUS
SlappyAUS / DateAggegation.swift
Created November 11, 2020 10:56
Date Aggregation #swift #dates
import Cocoa
struct entry {
let date: Date
let vol: Measurement<UnitVolume>
}
let entries = [