Skip to content

Instantly share code, notes, and snippets.

View Rsych's full-sized avatar
🙈
I may be slow to respond.

J. W. Kim Rsych

🙈
I may be slow to respond.
View GitHub Profile
@Rsych
Rsych / ConditionalSaving.swift
Created October 26, 2021 12:28
Conditional saving of NSManagedObjectContext
struct SavingwithMOC: View {
// MARK: - Properties
@Environment(\.managedObjectContext) var moc
// MARK: - Body
var body: some View {
Button {
if self.moc.hasChanges {
try? self.moc.save()
}
@Rsych
Rsych / RatingView.swift
Created October 23, 2021 12:09
Rating with 5 stars in SwiftUI
struct RatingVIew: View {
// MARK: - Properties
@Binding var rating: Int
var label = ""
var maximumRating = 5
var offImage: Image?
var onImage = Image(systemName: "star.fill")
@Rsych
Rsych / PersistenceController.swift
Created October 23, 2021 11:14
New PersistenceController
import Foundation
import CoreData
struct PersistenceController {
// A singleton for our entire app to use
static let shared = PersistenceController()
// Storage for CoreData
let container: NSPersistentContainer
@Rsych
Rsych / SwiftUITabView.swift
Last active October 28, 2021 08:45
SwiftUI Tabview
import SwiftUI
struct ContentView: View {
// MARK: - Properties
@State var selectedTab = 0
// MARK: - Body
var body: some View {
TabView(selection: $selectedTab) {
FirstView()
@Rsych
Rsych / SwiftUi_custom_modifier.swift
Created October 3, 2021 04:02
SwiftUi custom modifier
// MARK: - View Modifier
struct Title: ViewModifier {
func body(content: Content) -> some View {
content
.font(.largeTitle)
.foregroundColor(.blue)
}
}
extension View {
func titleStyle() -> some View {
@Rsych
Rsych / SwiftUi_custom_container.swift
Created October 3, 2021 03:44
SwiftUI Custom container
//: custom container properties
struct GridStack<Content: View>: View {
let rows: Int
let columns: Int
let content: (Int, Int) -> Content
var body: some View {
VStack {
ForEach(0 ..< rows) { row in
HStack {
@Rsych
Rsych / SwiftUI_Conditional_modifier.swift
Created October 3, 2021 03:14
SwiftUI conditional modifier
@State private var colorToggle = false
var body: some View {
Buttton {
self.colorToggle.toggle()
} label: {
Image(systemName: "clock")
.font(.largeTitle)
}
.foregroundColor(colorToggle ? .red : .blue)
@Rsych
Rsych / myCallbacks.py
Last active August 24, 2021 15:08
Tensorflow callbacks function renewed. Added early stopping and save model checkpoint
#@title Callbacks function define
%load_ext tensorboard
# %reload_ext tensorboard
import datetime
import os
# Create a function to build a TensorBoard callback
def create_tensorboard_callback():
# Create a log directory for storing TensorBoard logs
logdir = os.path.join('drive/MyDrive/logs/tf_cnn',
@Rsych
Rsych / cnn_LeNet.py
Created August 17, 2021 05:44
convolution neural network LeNet
INPUT_SHAPE = (28, 28, 1)
NB_CLASSES = 10 # number of outputs, we've got 10 digits
# Define our CNN
# CONV -> RELU -> POOL
model = Sequential()
model.add(Conv2D(20, (5, 5), activation='relu', input_shape = INPUT_SHAPE))
# model.add(BatchNormalization())
model.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))
# CONV => RELU => POOL
model.add(Conv2D(50, (5, 5), activation='relu', input_shape = INPUT_SHAPE))
@Rsych
Rsych / simplemaxPooling.py
Last active August 16, 2021 09:22
max pooling
from keras.layers import MaxPooling2D
model.add(MaxPooling2D((2,2)))