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 Cocoa | |
import Foundation | |
extension String { | |
static func ~= (lhs: String, rhs: String) -> Bool { | |
if lhs == rhs { | |
return true | |
} | |
if let range = rhs.range(of: lhs, options: .regularExpression) { | |
return rhs[range] == rhs |
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 Foundation | |
import PlaygroundSupport | |
import Combine | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
enum RequestError: Error { | |
case sessionError(error: Error) | |
} |
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 Cocoa | |
extension DateFormatter.Style { | |
static public var allCases: [DateFormatter.Style] = [ | |
.none, | |
.short, | |
.medium, | |
.long, | |
.full, | |
] |
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 Cocoa | |
let formatter = DateFormatter() | |
formatter.dateStyle = .long | |
formatter.dateFormat = "(O) VVV" | |
formatter.locale = Locale(identifier: "zh") | |
TimeZone.knownTimeZoneIdentifiers | |
.compactMap(TimeZone.init(identifier:)) | |
.map { timeZone -> String in |
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
[ | |
{ | |
"User_na": "A", | |
"Total": "a", | |
"Scene_No": "1" | |
}, | |
{ | |
"User_na": "B", | |
"Total": "b", | |
"Scene_No": "2" |
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 Cocoa | |
extension Calendar { | |
func isDateIn7days(from date: Date) -> Bool { | |
let date1 = self.startOfDay(for: Date()) | |
let date2 = self.startOfDay(for: date) | |
let days = (date1 - date2).day ?? 0 | |
return days <= 8 && days > 0 | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Strapdown.js - Instant and elegant Markdown documents</title> | |
<!-- 🌙 Dark theme--> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.min.css"> | |
<link rel="stylesheet" href="https://raw.githack.com/google/code-prettify/master/styles/desert.css"> | |
<!-- 🌞 Light theme--> | |
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/light.min.css"> --> | |
</head> |
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
//: A Cocoa based Playground to present user interface | |
import AVFoundation | |
let voices = AVSpeechSynthesisVoice.speechVoices().reduce([String:[AVSpeechSynthesisVoice]]()) { (result, voice) -> [String:[AVSpeechSynthesisVoice]] in | |
var voices = result | |
let locale = Locale(identifier: voice.language) | |
let code = locale.localizedString(forLanguageCode: locale.languageCode!) ?? "??" | |
var voiceOnLanguage = voices[code] ?? [] | |
voiceOnLanguage.append(voice) | |
voices[code] = voiceOnLanguage |
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
extension Locale { | |
var flagCode: String { | |
guard let country = self.regionCode else {return "🌐"} | |
let base : UInt32 = 127397 | |
let code = country.unicodeScalars.compactMap{UnicodeScalar(base + $0.value)} | |
return String(String.UnicodeScalarView(code)) | |
} | |
} |
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
var charLayers = [CAShapeLayer]() | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
for layer in self.charLayers { | |
layer.removeFromSuperlayer() | |
} | |
let stringAttributes = [ NSAttributedString.Key.font: UIFont(name: "Zapfino", size: 32.0)! ] |