Skip to content

Instantly share code, notes, and snippets.

View PattoMotto's full-sized avatar
📱

Patompong Manprasatkul PattoMotto

📱
  • @careem an Uber + E& company
  • Dubai, UAE
View GitHub Profile
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 {
# 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 ''
# 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
import IntentsUI
class IntentViewController: UIViewController, INUIHostedViewControlling {
private let margin = CGFloat(8)
var dataManager: CookBookDataManager?
@IBOutlet weak var contentStackView: UIStackView!
// MARK: - INUIHostedViewControlling
import IntentsUI
extension ViewController: INUIAddVoiceShortcutViewControllerDelegate {
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController,
didFinishWith voiceShortcut: INVoiceShortcut?,
error: Error?) {
if let error = error as NSError? {
print(error)
return
}
@PattoMotto
PattoMotto / ViewController.swift
Last active July 9, 2018 11:45
Method for present VoiceShortcutViewController and update UI, full project https://github.com/neungnarakjung/CookBook-Siri-Shortcuts-Example
import UIKit
import IntentsUI
class ViewController: UIViewController {
private var shortcutManager: VoiceShortcutManager?
private var dataManager: CookBookDataManager?
private func presentVoiceShortcutViewController() {
guard let shortcutManager = shortcutManager,
struct Recipe: Codable {
let identifier: String
let name: String
let instruction: [String]
}
protocol CookBookDataManager {
func getRecipe(_ identifier: String) -> Recipe?
}
import Intents
final class VoiceShortcutManager {
var voiceShortcuts: [INVoiceShortcut]?
init() {
updateShortcut()
}
public func updateShortcut(_ completion: (() -> Void)? = nil) {
import Intents
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
guard intent is CookBookIntent else {
fatalError("Unhandled intent type: \(intent)")
}
return CookBookIntentHandler()
}
}
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))
}