Skip to content

Instantly share code, notes, and snippets.

@gustafnilklint
gustafnilklint / Spinner.swift
Created December 11, 2020 09:00
A simple progress indicator Written in swiftUI
//
// Spinner.swift
// IHS-aafh
//
// Created by Gustaf Nilklint on 2020-05-28.
// Copyright © 2020 Gustaf Nilklint. All rights reserved.
//
import SwiftUI
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
for task in backgroundTasks {
switch task {
case let backgroundTask as WKApplicationRefreshBackgroundTask:
BackgroundService.shared.updateContent()
backgroundTask.setTaskCompletedWithSnapshot(false)
case let urlSessionTask as WKURLSessionRefreshBackgroundTask:
BackgroundService.shared.handleDownload(urlSessionTask)
@gustafnilklint
gustafnilklint / BackgroundService.swift
Last active August 12, 2020 00:03
BackgroundRefresh
//
// BackgroundService.swift
//
// Created by Gustaf on 2020-01-27.
// Copyright © 2020 Gustaf. All rights reserved.
//
import Foundation
import WatchKit

Requirements

  • Install PlatformIO or equivalent

Set up Hardware

  • Follow the scematic/reference breadboard
  • I'm thinking one D1-mini per goal for now..

Implement the SW

// Author - Santosh Rajan
import Foundation
let jsonObject: [AnyObject] = [
["name": "John", "age": 21],
["name": "Bob", "age": 35],
]
func JSONStringify(value: AnyObject, prettyPrinted: Bool = false) -> String {
@gustafnilklint
gustafnilklint / NSString+extra.m
Created October 10, 2014 11:39
String with format, avoiding "(null)" "<null>" and extra spaces, drop this method in your NSString category
// Returns a string with the given format, any nil-values will be eliminated and extra white-space is trimmed away for you =)
+ (instancetype)safeStringWithFormat:(NSString *)format, ...
{
va_list ap;
va_start(ap, format);
NSString *intermediateString = [[NSString alloc] initWithFormat:format arguments:ap];
va_end(ap);
NSString *resultString = [intermediateString stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
resultString = [resultString stringByReplacingOccurrencesOfString:@"<null>" withString:@""];
@gustafnilklint
gustafnilklint / NSDictionary+prettyPrint.m
Created September 15, 2014 21:23
NSDictionary print itself as litheral
//
// NSDictionary+prettyPrint.m
// GarageRemote
//
// Created by Gustaf Nilklint on 2014-09-15.
// Copyright (c) 2014 Gustaf Nilklint. All rights reserved.
//
#import "NSDictionary+prettyPrint.h"