Skip to content

Instantly share code, notes, and snippets.

@carlynorama
carlynorama / AOC2022_day15.swift
Last active December 16, 2022 03:04
My answer to Day15 of Advent of Code. Uses ranges. Searches what I thought might be more likely rows first. "AOC2022_day15.swift" is the playground file. "Range+Smush.swift" is for the "Sources" folder and "day15_testinput.txt" for "Resources."
//
// Day15.swift
// AdventOfCode2022
//
// Created by carlynorama on 12/15/22.
import Foundation
let testData = "day15_testinput"
@carlynorama
carlynorama / regex_indexParser.swift
Last active December 6, 2022 16:56
Use a regular expressions to get indices from one string. Then use those indices to get the content from another. #AdventOfCode2022 #Day5 https://adventofcode.com/2022/day/5
import UIKit
let stringA = " 1 2 3 4 5 6 7 8 9"
let stringB = "[F] [R] [C] [F] [L] [Q] [F] [D] [P]"
let matches = stringA.matches(of: /\b[0-9]+\b/)
for match in matches {
@carlynorama
carlynorama / SoftlyFailingIncompleteJSON.swift
Created November 5, 2022 23:39
For when SOME of your json can make the object
import SwiftUI
struct Traveler: Codable, Identifiable {
let firstName: String
let middleName: String?
let familyName: String
var id:String {
"\(familyName), \(firstName)"
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
paths:
- 'Output/**'
name: Deploy Project
on: [push, workflow_dispatch]
jobs:
mytests:
runs-on: ubuntu-latest
steps:
- name: Get code
uses: actions/checkout@v3
- name: Install NodeJS
uses: actions/setup-node@v3
@carlynorama
carlynorama / OptionalChildrenIntrospection.swift
Last active November 2, 2022 22:59
Add this to any Struct if you want a string of all the optional values that actually have defined content.
var whatDoIHave:String {
let mirror = Mirror(reflecting: self)
var itemsToDisplay:[String] = []
for child in mirror.children {
//print("key: \(child.label), value: \(child.value)")
if child.value is ExpressibleByNilLiteral {
let typeDescription = object_getClass(child.value)?.description() ?? ""
if !typeDescription.contains("Null") && !typeDescription.contains("Empty") {
itemsToDisplay.append(child.label ?? "no_key")
@carlynorama
carlynorama / HTMLtoSwiftUI.swift
Last active October 31, 2022 21:47
Rendering HTML as AttributedString in a scroll view without crahsing.
//
// ContentView.swift
// HTMLTests
//
// Created by Carlyn Maw on 10/30/22.
//
//https://www.hackingwithswift.com/example-code/uikit/how-to-load-a-html-string-into-a-wkwebview-or-uiwebview-loadhtmlstring
//https://developer.apple.com/forums/thread/682431
//https://developer.apple.com/documentation/foundation/attributedstring
//
// ResponseService.swift
// NetworkingExample
//
// Created by Carlyn Maw on 10/29/22.
//
import Foundation
enum RequestServiceError:Error, CustomStringConvertible {
@carlynorama
carlynorama / StreamWrappedPublisher.swift
Last active September 27, 2022 05:06
Comparing an AsyncPublisher vs an AsyncPublisher wrapped in a stream.
import Foundation
import SwiftUI
actor TestService {
static let shared = TestService()
@MainActor @Published var counter:Int = 0 {