This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import Foundation | |
import Observation | |
// A: Using specific class | |
/// Class that wraps withObservationTracking function into a Combine compatible continuos stream publisher | |
public class ObservationTracker<O: Observable & AnyObject, T> { | |
/// Subscribe to a publisher. | |
public var valuePublisher: AnyPublisher<T, Never> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FloatingPanel: NSPanel { | |
init(contentRect: NSRect, backing: NSWindow.BackingStoreType, defer flag: Bool) { | |
// Not sure if .titled does affect anything here. Kept it because I think it might help with accessibility but I did not test that. | |
super.init(contentRect: contentRect, styleMask: [.nonactivatingPanel, .resizable, .closable, .fullSizeContentView], backing: backing, defer: flag) | |
// Set this if you want the panel to remember its size/position | |
// self.setFrameAutosaveName("a unique name") | |
// Allow the pannel to be on top of almost all other windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
func extractViewsFromContent<Content: View> (@ViewBuilder content: () -> Content) -> [Any] { | |
let tupleView = content() | |
let tupleViewMirror = Mirror(reflecting: tupleView) | |
let tuple = tupleViewMirror.children.first!.value | |
let tupleMirror = Mirror(reflecting: tuple) | |
let views = tupleMirror.children.map { $0.value } | |
return views | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppKit | |
import SwiftUI | |
// Delete this line if not using a playground | |
import PlaygroundSupport | |
struct ContentView: View { | |
var body: some View { | |
// if spacing is not set to zero, there will be a gap after the first row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SwiftUI Custom Styles (TripleToggleStyle) | |
// https://swiftui-lab.com | |
// https://swiftui-lab.com/custom-styling | |
import SwiftUI | |
// MARK: - TripleToggle View | |
public struct TripleToggle: View { | |
@Environment(\.tripleToggleStyle) var style: AnyTripleToggleStyle | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SectionBackgroundFlowLayout.swift | |
// | |
// Created by Samuel's on 2020/7/29. | |
import UIKit | |
@objc protocol SectionBackgroundFlowLayoutDelegate: NSObjectProtocol { | |
func sectionsNeedBackgroundColor(in collectionView: UICollectionView, layout: UICollectionViewFlowLayout) -> [Int] | |
func classForBackgroundViewAttributes() -> UICollectionViewLayoutAttributes.Type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dart: Validate Password | |
This code snippet shows how to validate a password | |
**Requirement** : | |
Password should be more than 8 characters long | |
It should contain | |
at least one Uppercase ( Capital ) letter | |
at least one lowercase character | |
at least digit and | |
special character. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Select objects in array whose key matches a value | |
* | |
* @param {Array} arr Array to test | |
* @param {String} key Key to inspect | |
* @param {String} value Value key needs to match | |
* @return {String} Filtered array | |
* | |
*/ | |
module.exports = function (arr, key, value) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Select objects in array whose key includes a value | |
* | |
* @param {Array} arr Array to test | |
* @param {String} key Key to inspect | |
* @param {String} value Value key needs to include | |
* @return {String} Filtered array | |
* | |
*/ | |
module.exports = function (arr, key, value) { |
NewerOlder