Skip to content

Instantly share code, notes, and snippets.

@SlappyAUS
SlappyAUS / swiftui url update.swift
Created February 8, 2021 08:04
swiftui url update #swiftui #data #url
import Combine
class MyObserableObject: ObservableObject {
@Published var myData: [Int] = []
private var subscription: AnyCancellable?
init() {
subscription = Timer
.TimerPublisher(interval: 1, runLoop: RunLoop.main, mode: .default)
.map { _ -> AnyPublisher<[Int], Never> in
URLSession
@SlappyAUS
SlappyAUS / SearchableGrid.swift
Created January 28, 2021 04:29
SearchableGrid
import SwiftUI
import CoreData
struct SearchableGrid<T: NSManagedObject, Content: View, EmptyContent: View>: View where T: Identifiable {
@Environment(\.managedObjectContext) var context
@StateObject private var viewModel = SearchableGridGridViewModel<T>()
let dropEntered : (DropInfo, SearchableGridGridViewModel<T>, T) -> ()
let dropUpdated : ((DropInfo, T) -> DropProposal?)?
@SlappyAUS
SlappyAUS / ShapeStroke.swift
Created January 21, 2021 08:17
Shape Stoke #swiftui #shapes
Capsule()
.fill(Color.green)
.overlay(
Capsule()
.stroke(Color.black, lineWidth: 10)
)
.frame(width: 200, height: 100)
@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 = {
@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 / 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 / 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 / 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 / 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 / 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 {