Skip to content

Instantly share code, notes, and snippets.

@luomein
luomein / ComplicationController.swift
Created September 19, 2021 06:14
MVP ComplicationController for graphicCircular
class ComplicationController: NSObject, CLKComplicationDataSource {
func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) {
// for graphicCircular
let descriptors = [
CLKComplicationDescriptor(identifier: "graphicCircular", displayName: "graphicCircular", supportedFamilies:[ CLKComplicationFamily.graphicCircular]),
]
// Call the handler with the currently supported complication descriptors
handler(descriptors)
}
@luomein
luomein / ComplicationController.swift
Created September 19, 2021 06:56
multiple looks of Complications on the same Watch Face
class ComplicationController: NSObject, CLKComplicationDataSource {
func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) {
// for graphicCircular
let descriptors = [
CLKComplicationDescriptor(identifier: "graphicCircular1", displayName: "graphicCircular1", supportedFamilies:[ CLKComplicationFamily.graphicCircular]),
CLKComplicationDescriptor(identifier: "graphicCircular2", displayName: "graphicCircular2", supportedFamilies:[ CLKComplicationFamily.graphicCircular]),
]
// Call the handler with the currently supported complication descriptors
handler(descriptors)
@luomein
luomein / swiftui_learning_curve.csv
Created December 2, 2021 04:32
SwiftUI learning curve review
(1)TW Tide (2)Watch Mask (3)vHub
WatchKit heavy use light use
App Extension heavy use
SwiftUI State heavy use heavy use heavy use
SwiftUI Shape and Path heavy use heavy use
External API heavy use heavy use
CloudKit heavy use
CoreData heavy use heavy use
StoreKit heavy use heavy use
Concurrency light use light use light use
@luomein
luomein / 20220514_01.py
Created May 14, 2022 05:44
From Multivariate Time Series to Array with Time Dimension, step1
import pandas as pd
import numpy as np
def get_rank_df(df , station_column , time_column , sort_time_ascending = True ):
df.sort_values(by=[station_column , time_column] , ignore_index = True , inplace = True)
df = df.drop_duplicates(subset=[station_column , time_column]).reset_index(drop = True)
df["rank"] = df.groupby(station_column)[time_column].rank("dense", ascending= sort_time_ascending )
df = df.astype({'rank': 'int32'} )
@luomein
luomein / 20220514_02.py
Created May 14, 2022 06:03
From Multivariate Time Series to Array with Time Dimension, step2
import pandas as pd
import numpy as np
def filter_time_windows(result_df , station_column , time_window_size ):
result_df['counts'] = result_df.groupby([station_column, 'rank_group'])['rank'].transform('size')
result_df = result_df[result_df.counts == time_window_size ]
return result_df
@luomein
luomein / 20220514_03.py
Created May 14, 2022 06:10
From Multivariate Time Series to Array with Time Dimension, step3
import pandas as pd
import numpy as np
def get_feature_array(df , feature_column_list , time_window_size ) :
feature_count = len(feature_column_list )
x = df.loc[: , feature_column_list ].to_numpy().reshape( -1 , time_window_size , feature_count )
return x
@luomein
luomein / 20220514_05.py
Created May 14, 2022 06:15
From Multivariate Time Series to Array with Time Dimension, step5
import pandas as pd
import numpy as np
def get_grouped_df(df ,station_column , rank_group_column ):
gdb = df.groupby([station_column, rank_group_column ], sort = False).size()
y = pd.DataFrame(data = { station_column : gdb.index.get_level_values(0).tolist() , rank_group_column : gdb.index.get_level_values(1).tolist() })
return y
@luomein
luomein / TestFetchResultIsFault.swift
Last active August 3, 2022 01:45
Use XCode Test to Learn Core Data Faults--Part 1, resultType = .managedObjectResultType
func testFetchResultIsFault()throws{
for i in 0..<configurations.count{
//given
let viewContext = try initViewContext()
let configuration = configurations[i]
let fetchRequest = getFetchRequest(configuration:configuration)
//when
let object = try viewContext.fetch(fetchRequest).first! as! NSManagedObject
@luomein
luomein / AppDelegate.swift
Last active August 24, 2022 13:45
AppDelegate for Push Notification
import SwiftUI
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
application.registerForRemoteNotifications()
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if let error = error {
// Handle the error here.
}
@luomein
luomein / testAutoConfiguredStore.swift
Created August 29, 2022 05:09
testAutoConfiguredStore
import XCTest
import CoreData
@testable import labSingleStore
final class labSingleStoreTests: XCTestCase {
func testAutoConfiguredStore(){
let container = PersistenceController.shared.container
assert(container.persistentStoreDescriptions.count == 1)