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 Foundation | |
func rejectRequest(_ requests: [String], rateLimit: Int) -> [Int] { | |
var ids = [Int]() | |
var requestMap = [String: [Int]]() | |
requests.forEach { request in | |
let rawData = request.split(separator: " ") | |
let ipAddress = String(rawData[1]) | |
guard let requestId = Int(rawData[0]), | |
let time = Int(rawData[2]) else { |
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
# credit https://dev.to/rrampage/snake-case-to-camel-case-and-back-using-regular-expressions-and-python-m9j | |
# credit https://stackoverflow.com/a/3847369 | |
import re | |
REG = r"(.+?)([A-Z])" | |
def camel(match): | |
return match.group(1).lower() + match.group(2)[0].upper() + match.group(2)[1:].lower() | |
lowerFirstChar = lambda s: s[:1].lower() + s[1:] if s else '' |
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
# credit https://dev.to/rrampage/snake-case-to-camel-case-and-back-using-regular-expressions-and-python-m9j | |
import re | |
REG = r"(.+?)([A-Z])" | |
def snake(match): | |
return match.group(1).lower() + "-" + match.group(2).lower() | |
words = """MyClass |
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 IntentsUI | |
class IntentViewController: UIViewController, INUIHostedViewControlling { | |
private let margin = CGFloat(8) | |
var dataManager: CookBookDataManager? | |
@IBOutlet weak var contentStackView: UIStackView! | |
// MARK: - INUIHostedViewControlling |
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 IntentsUI | |
extension ViewController: INUIAddVoiceShortcutViewControllerDelegate { | |
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, | |
didFinishWith voiceShortcut: INVoiceShortcut?, | |
error: Error?) { | |
if let error = error as NSError? { | |
print(error) | |
return | |
} |
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 IntentsUI | |
class ViewController: UIViewController { | |
private var shortcutManager: VoiceShortcutManager? | |
private var dataManager: CookBookDataManager? | |
private func presentVoiceShortcutViewController() { | |
guard let shortcutManager = shortcutManager, |
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
struct Recipe: Codable { | |
let identifier: String | |
let name: String | |
let instruction: [String] | |
} | |
protocol CookBookDataManager { | |
func getRecipe(_ identifier: String) -> Recipe? | |
} |
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 Intents | |
final class VoiceShortcutManager { | |
var voiceShortcuts: [INVoiceShortcut]? | |
init() { | |
updateShortcut() | |
} | |
public func updateShortcut(_ completion: (() -> Void)? = nil) { |
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 Intents | |
class IntentHandler: INExtension { | |
override func handler(for intent: INIntent) -> Any { | |
guard intent is CookBookIntent else { | |
fatalError("Unhandled intent type: \(intent)") | |
} | |
return CookBookIntentHandler() | |
} | |
} |
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 Foundation | |
final class CookBookIntentHandler: NSObject, CookBookIntentHandling { | |
func handle(intent: CookBookIntent, completion: @escaping (CookBookIntentResponse) -> Void) { | |
guard let recipe = intent.recipe else { | |
completion(CookBookIntentResponse(code: .failure, userActivity: nil)) | |
return | |
} | |
completion(CookBookIntentResponse.success(recipe: recipe)) | |
} |
NewerOlder