Skip to content

Instantly share code, notes, and snippets.

@BjornRuud
BjornRuud / ViewOnChangeValue.swift
Created March 9, 2021 14:33
SwiftUI View.onChange(of:perform:) reimplementation for iOS 13
import SwiftUI
private struct ViewOnChangeValueObserver<Content: View, Value: Equatable>: View {
let content: Content
let value: Value
let action: (Value) -> Void
@State private var oldValue: Value
init(
@BjornRuud
BjornRuud / temperature.sh
Created March 17, 2020 14:49
View CPU and HDD temperatures on FreeBSD
#!/bin/sh
# Write some general information
echo System Temperatures - `date`
uptime | awk '{ print "\nSystem Load:",$10,$11,$12,"\n" }'
# Write CPU temperatures
echo "CPU Temperature:"
sysctl -a | egrep -E "cpu\.[0-9]+\.temp"
@BjornRuud
BjornRuud / URL+Namespace.swift
Created December 7, 2017 14:24
URL namespace to collect URLs in a convenient place.
extension URL {
enum MyURLNamespace {
// Static URL, always in memory
static let gitHub = URL(string: "https://github.com/BjornRuud")!
// Computed URL, created on demand
static var gitHubWithStaticParameter: URL {
let param = "SomeParameter"
return URL(string: "https://github.com/BjornRuud/\(param)")!
}
@BjornRuud
BjornRuud / UILabel+Debug.swift
Created November 7, 2017 12:09
Debug mode for UILabel that can optionally show bounds, ascender, descender, x height, cap height, baseline and leading.
import UIKit
struct UILabelDebugOptions: OptionSet {
let rawValue: Int
static let bounds = UILabelDebugOptions(rawValue: 1 << 0)
static let ascender = UILabelDebugOptions(rawValue: 1 << 1)
static let descender = UILabelDebugOptions(rawValue: 1 << 2)
static let xHeight = UILabelDebugOptions(rawValue: 1 << 3)
static let capHeight = UILabelDebugOptions(rawValue: 1 << 4)