This file contains hidden or 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
| func levelSafe(ints: [Int]) -> Bool { | |
| let increasing: Bool | |
| let diff = ints[1] - ints[0] | |
| if diff > 0 && diff <= 3 { | |
| increasing = true | |
| } else if diff < 0 && diff >= -3 { | |
| increasing = false | |
| } else { | |
| return false | |
| } |
This file contains hidden or 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
| const functions = require('firebase-functions'); | |
| const admin = require('firebase-admin'); | |
| admin.initializeApp(functions.config().firebase); | |
| // Update thread after messages | |
| exports.updateThreadAfterMessage = functions.database.ref('/thread_messages/{threadId}/{messageId}') | |
| .onCreate((snapshot, context) => { | |
| const messageData = snapshot.val(); | |
| console.log('New message for thread:', context.params.threadId, 'Message:', messageData.text); |
This file contains hidden or 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
| extension Date { | |
| func midnight(calendar: Calendar = .autoupdatingCurrent) -> Date { | |
| let todayComponents = calendar.dateComponents( | |
| [.month, .day, .year], | |
| from: self | |
| ) | |
| var components = DateComponents() | |
| components.year = todayComponents.year | |
| components.month = todayComponents.month | |
| components.day = todayComponents.day |
This file contains hidden or 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 | |
| struct ContentView: View { | |
| @State var showImagePicker: Bool = false | |
| @State var image: Image? = nil | |
| var body: some View { | |
| ZStack { | |
| VStack { | |
| Button(action: { |
This file contains hidden or 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 UIKit | |
| extension UIImage { | |
| func resizedImage(for size: CGSize) -> UIImage? { | |
| let renderer = UIGraphicsImageRenderer(size: size) | |
| return renderer.image { (context) in | |
| self.draw(in: CGRect(origin: .zero, size: size)) | |
| } | |
| } | |
| } |
This file contains hidden or 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
| extension String { | |
| subscript(_ index: Int) -> Character { | |
| return self[String.Index(utf16Offset: index, in: self)] | |
| } | |
| } | |
| extension String { | |
| func sub(_ l: Int, _ r: Int) -> String { | |
| let leftIndex = String.Index(utf16Offset: l, in: self) | |
| let rightIndex = String.Index(utf16Offset: r, in: self) |
This file contains hidden or 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
| func isLeapYear(_ year: Int) -> Bool { | |
| assert(year >= 0) | |
| if year % 4 == 0 { | |
| return year % 100 != 0 || year % 400 == 0 | |
| } | |
| return false | |
| } | |
| func daysInYear(_ year: Int) -> Int { |
This file contains hidden or 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 UIKit | |
| import PlaygroundSupport | |
| PlaygroundPage.current.needsIndefiniteExecution = true | |
| // Extension | |
| extension NotificationCenter { | |
| func post<T>(name: String, object: T, userInfo: [AnyHashable: Any]?) { | |
| post(name: NSNotification.Name(name), object: object, userInfo: userInfo) |
This file contains hidden or 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
| // Dictionary | |
| let nhlDict : [String : String] = [ | |
| "COL" : "Avalanche", | |
| "CHI" : "Blackhawks", | |
| "CBJ" : "Blue Jackets", | |
| "STL" : "Blues", | |
| "BOS" : "Bruins", | |
| "MTL" : "Canadiens", |
NewerOlder