Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Web Page</title>
</head>
<body>
<h1>Welcome to My Simple Page</h1>
<p>Click the link below to visit the website:</p>
@kraigspear
kraigspear / detect.swift
Created June 19, 2023 07:43
Detect if running in Previews or Unit Test
public extension EnvironmentValues {
var isPreview: Bool {
#if DEBUG
return ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
#else
return false
#endif
}
var isUnitTest: Bool {
@kraigspear
kraigspear / Hashtag.swift
Last active June 17, 2023 12:43
Extract out hashtags using Swift Regex Literals
let hashTagExpression = /(#+[a-zA-Z0-9(_)]{1,})/
let note = "this is my #note with a #tag #whatup"
let ranges = note.ranges(of: regEx2)
ranges.forEach {
// Remove the # by skipping over the first character.
let newStart = note.index(after: $0.lowerBound)
let newRange = newStart..<$0.upperBound
let str = String(note[newRange])
print(str)
//
// NavigationLazyView.swift
//
//
// Created by Kraig Spear on 11/14/20.
//
import SwiftUI
public struct NavigationLazyView<Content: View>: View {
let build: () -> Content
@kraigspear
kraigspear / swiftformat.sh
Created March 9, 2021 13:02
Swift format
swiftformat . --indent 4 --swiftversion 5.3 --disable wrapMultilineStatementBraces
@kraigspear
kraigspear / beaver.swift
Created March 8, 2021 22:46
Beaver Logger
//
// BeaverLogger.swift
// Klimate
//
// Created by Kraig Spear on 10/23/20.
//
import Foundation
import SwiftyBeaver
public final class BeaverLogger: Logger {
@kraigspear
kraigspear / log.swift
Last active March 17, 2021 05:23
Logger in swift
//
// Logger.swift
// Klimate
//
// Created by Kraig Spear on 10/23/20.
//
import Foundation
public protocol Logger {
@kraigspear
kraigspear / resultqueue.swift
Created November 16, 2020 13:51
Providing the queue to call back on, default to main.
// Taken from https://www.swiftbysundell.com/clips/2/
extension Data {
func decoded<T: Decodable>(
as type: T.Type = T.self,
handledOn resultQueue: DispatchQueue = .main,
handler: @escaping (Result<T, Error>) -> Void
) {
let queue = DispatchQueue(label: "com.myapp.decoding")
let decoder = JSONDecoder()
//
// BaseOperation.swift
// SpearSwiftLib
//
// Created by Kraig Spear on 11/11/15.
//
import Foundation
/**
@kraigspear
kraigspear / QRCodeGeneration.swift
Last active March 17, 2021 05:25
Generate A QR Code
//
// QRCodeGeneration.swift
// TempCheck
//
// Created by Kraig Spear on 6/12/20.
//
import CoreImage.CIFilterBuiltins
import UIKit