Skip to content

Instantly share code, notes, and snippets.

@SlappyAUS
SlappyAUS / EnumAsImages.swift
Created December 6, 2020 00:00
Enums as Images #swift #enum
enum SFSymbols {
static let location = UIImage(systemName: "mappin.and.ellipse")
static let repos = UIImage(systemName: "folder")
static let gists = UIImage(systemName: "text.alignleft")
static let followers = UIImage(systemName: "heart")
static let following = UIImage(systemName: "person.2")
}
@SlappyAUS
SlappyAUS / DateUtil.swift
Last active December 15, 2020 07:53
DateUtils #swift #date
//
// DateUtil.swift
// DrinkSum
//
// Created by Greg Eales on 5/11/20.
//
import Foundation
struct DateUtil {
static func getModifiedDate(date: Date, currentDate: Date) -> String {
@SlappyAUS
SlappyAUS / DateSnippets.swift
Created December 15, 2020 07:54
Date Snippets #swift #date
private func setDateFromSelection() {
let monthNumber = getMonthNumberFromName(name: month)
let timeComponents = Calendar.current.dateComponents(
[.hour, .minute, .second, .nanosecond], from: selectedDate)
let dateComponents = DateComponents(
year: year,
month: monthNumber,
day: day,
hour: timeComponents.hour,
@SlappyAUS
SlappyAUS / SwipeableModfier.swift
Last active December 24, 2020 11:06
Swipeable Modifier #swift #swiftui #modifiers
//
// SwipeableModifier.swift
// DrinkSum
//
// Created by Greg Eales on 22/12/20.
//
import SwiftUI
struct Swipeable<V>: ViewModifier where V: View {
@SlappyAUS
SlappyAUS / KerasDeepNeuralNet.py
Created December 23, 2020 11:24
Keras Deep Neural Net Template #python #ml #tensorflow
# Setup plotting
import matplotlib.pyplot as plt
from learntools.deep_learning_intro.dltools import animate_sgd
plt.style.use('seaborn-whitegrid')
# Set Matplotlib defaults
plt.rc('figure', autolayout=True)
plt.rc('axes', labelweight='bold', labelsize='large',
titleweight='bold', titlesize=18, titlepad=10)
plt.rc('animation', html='html5')
@SlappyAUS
SlappyAUS / SaveSwiftUIViewasImage.swift
Created December 28, 2020 02:23
Save SwiftUI View as Image #swift #swifui #image
import SwiftUI
func convertViewToData<V>(view: V, size: CGSize, completion: @escaping (Data?) -> Void) where V: View {
guard let rootVC = UIApplication.shared.windows.first?.rootViewController else {
completion(nil)
return
}
let imageVC = UIHostingController(rootView: view.edgesIgnoringSafeArea(.all))
imageVC.view.frame = CGRect(origin: .zero, size: size)
@SlappyAUS
SlappyAUS / Drag.swift
Created January 9, 2021 00:01
Drag and Drop #swiftui
import SwiftUI
import UniformTypeIdentifiers
struct GridData: Identifiable, Equatable {
let id: String
}
//MARK: - Model
class Model: ObservableObject {
@SlappyAUS
SlappyAUS / SVGtoPNG
Created January 14, 2021 02:09
SVG to PNG #graphics #convert #svg #png #rsvg
for i in *.svg ; do rsvg-convert -d 500 -w 300 "$i"> "$i".png ; done
@SlappyAUS
SlappyAUS / WorkingWithBundles.swit
Created January 14, 2021 07:43
Working With Bundles #swift #bundles
// MARK: - Emoji Packs
extension Emoji {
private func getEmojiFileName(for pack: String) -> String {
let strArr = codePoints
.compactMap({ String(format:"%04X", UInt32($0)) })
.joined(separator: "-")
.lowercased()
return strArr + ".svg"
}
@SlappyAUS
SlappyAUS / SeedingCoreData.swift
Created January 16, 2021 07:45
Seeding core Data #swift #coredata
func getDocumentsDirectory()-> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let documentsDirectory = paths[0]
return documentsDirectory
}
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {