Skip to content

Instantly share code, notes, and snippets.

View mlcollard's full-sized avatar

Michael L. Collard mlcollard

View GitHub Profile
@mlcollard
mlcollard / NumberLocalization.swift
Created April 27, 2018 13:05
iOS: Number Localization playground
// Localization of numbers
import Foundation
let nf = NumberFormatter()
nf.numberStyle = .decimal
print(nf.string(from: 1234) ?? "INVALID NUMBER")
nf.locale = Locale(identifier: "es_ES")
var template = """
<document>
<loadingTemplate>
<activityIndicator><text>Hello World!</text></activityIndicator>
</loadingTemplate>
</document>
"""
var templateParser = new DOMParser();
var parsedTemplate = templateParser.parseFromString(template, "application/xml");
@mlcollard
mlcollard / pythonserver.sh
Last active April 25, 2018 13:34
iOS: TVML: python server for TVML
# Note: Run in directory where javascript, e.g., applications.js, is stored
python -m SimpleHTTPServer 9001
@mlcollard
mlcollard / rubyserver.sh
Created April 25, 2018 13:31
iOS: TVML: ruby command to run local server
# Note: Run in directory where javascript, e.g., applications.js, is stored
ruby -run -ehttpd . -p9001
@mlcollard
mlcollard / AppTransportSecurity.plist
Created April 25, 2018 13:29
iOS: TVML: Permissions to run local server
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
// MARK: - Timeline Configuration
var startTime = Date()
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
handler([.forward, .backward])
}
func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
handler(startTime.addingTimeInterval(-(60.0 * 60.0 * 10)))
@mlcollard
mlcollard / LocalNotification.swift
Created April 20, 2018 12:35
iOS: Notifications
// TODO: import UserNotifications
// Create the notification content
let content = UNMutableNotificationContent()
content.title = "Hi"
content.body = "Hello"
print(#function, #line)
// Configure the notification trigger for 3 seconds
@mlcollard
mlcollard / getCurrentTimeLineEntry.swift
Last active May 2, 2018 11:12
iOS: Watch: Complications
// Call the handler with the current timeline entry
let template = CLKComplicationTemplateModularSmallRingText()
template.textProvider = CLKSimpleTextProvider(text: "UA")
let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
handler(timelineEntry)
@mlcollard
mlcollard / ShareExtensioninfo.plist
Created April 16, 2018 15:43
iOS: Share Extension info.plist
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionJavaScriptPreprocessingFile</key>
@mlcollard
mlcollard / didSelectPost.swift
Created April 16, 2018 15:21
iOS: didSelectPost() processing for share extension
override func didSelectPost() {
// content of the post
print(#function, #line, self.contentText ?? "NO CONTENT")
// extract URL from attachments
if let item = extensionContext?.inputItems.first as? NSExtensionItem,
let itemProvider = item.attachments?.first as? NSItemProvider,
itemProvider.hasItemConformingToTypeIdentifier("public.url") {