Skip to content

Instantly share code, notes, and snippets.

View rjstelling's full-sized avatar
🕶️
Encrypting Bits

Richard Stelling rjstelling

🕶️
Encrypting Bits
View GitHub Profile
@rjstelling
rjstelling / UniformTypeIdentifierExtensions.swift
Last active March 8, 2024 18:21
A couple of extensions to make working with UTI in Swift less painful.
import Foundation
// Typesafe UTI, system APIs are all stringly typed 🙄
public struct UTI: CustomDebugStringConvertible, CustomStringConvertible {
public enum Error: Swift.Error {
case invalidCharachters
}
private let rawUTI: String
{
"macOS Dynamic System Colors": {
"Alternate selected control text color": {
"Use for": "The text on a selected surface in a list or table.",
"AppKit API": "alternateSelectedControlTextColor"
},
"Alternating content background colors": {
"Use for": "The backgrounds of alternating rows or columns in a list, table, or collection view.",
"AppKit API": "alternatingContentBackgroundColors"
},
@rjstelling
rjstelling / iOS Support Matrix Text (english)
Created December 3, 2012 13:40
This is the text that needs translating so we can release localised versions of the iOS Support Matrix. Feel free to fork and translate: http://www.empiricalmagic.com/post/34832825209/ios-support-matrix-v2-0-winter-2012
iOS Support Matrix
Winter 2012 Edition - v2.0
iPhone June 2007
iPod touch Sept 2007, Feb 2008 (32GB only)
iPhone 3G July 2008
iPod touch (2nd Generation) Sept 2008 Sept 2009 - (8GB only)
iPhone 3GS June 2009
iPod touch (3rd Generation) Sept 2009
iPad April 2010
iPhone 4 June 2010
@rjstelling
rjstelling / Lazy Lock Down Curriculum.markdown
Last active January 6, 2021 01:58
Lazy Lock Down Curriculum - enjoyable but educational things for students to do during lock down. Entries should be self contained videos or activities that can supplement a students education during lock down and home schooling. Any content posted must be free (commercial videos or items that require purchase will be removed). Please make sure …

Lazy Lock Down Curriculum

Rules

  1. No adverts
  2. Entries should be age approprate (5-16)
  3. Be kind

Science

Lockdown Embryology with Prof. Alice Roberts

@rjstelling
rjstelling / RegularExpressionValidation.swift
Created March 23, 2020 10:09
A `@propertyWrapper` that validates a string using a regular expression. If the string matches then it is assigned to the property if it does not then the property is net to nil. Also included is an example of validating email addresses.
import Foundation
@propertyWrapper
public struct RegularExpressionValidation {
private var _verifiedString: String?
private let _regexPattern: String
private lazy var _regex: NSRegularExpression? = try? NSRegularExpression(pattern: _regexPattern, options: [.caseInsensitive])
public init(_ regexString: String) {
//
// SemanticVersioning.swift
//
//
// Created by Richard Stelling on 28/05/2020.
//
// The MIT License (MIT)
//
// Copyright (c) 2016-17 Richard Stelling (http://twitter.com/rjstelling)
@rjstelling
rjstelling / BorderButton.swift
Created October 27, 2020 11:07
Accessibility Border Button
import UIKit
class BorderButton: UIButton {
private class BorderLayer: CAShapeLayer {
fileprivate var _borderWidth: CGFloat { UIAccessibility.isBoldTextEnabled ? 2.0 : 1.0 }
fileprivate var _cornerRadius: CGFloat = 4.0
override var lineWidth: CGFloat { get { _borderWidth } set { } }
override var fillColor: CGColor? { get { UIColor.clear.cgColor } set { } }
@rjstelling
rjstelling / BaseFunctions.swift
Last active January 24, 2020 12:49
Simple base encoding and decoding in Swift.
import Foundation
public enum StringSearchError: Swift.Error {
case didNotFind(Character)
}
extension String {
static let ReducedDigits = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789"
static let DefaultBase36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
@rjstelling
rjstelling / cs_xproj_validate.sh
Last active October 9, 2019 12:05
SEE: https://github.com/rjstelling/Xcode-Project-Validate. A very simple shell script to read .xcodeproj files and check if there are issues with the CODE_SIGN_IDENTITY. Having multiple entries can cause build errors (especially when Archiving or command line building). Link to StackOverflow question answering some questions about when and why t…
# /bin/bash
#Usage: $ ./cs_xproj_validate.sh path/to/xcode/project/file/theproject.xcodeproj
#More info: http://stackoverflow.com/q/13962341/89035
PROJECT_FILE="$1/project.pbxproj"
PREVIOUS_LINE=-1
for LINE in `cat "$PROJECT_FILE" | grep -n CODE_SIGN_IDENTITY | grep -o -E '^([0-9]*)'`
@rjstelling
rjstelling / PrintIntegerAsBinaryString.swift
Created May 24, 2019 08:33
A generic function to print the "binary string" of any `FixedWidthInteger`.
func print<T: FixedWidthInteger>(asBinary val: T) {
let bitCount = MemoryLayout<T>.size * 8
let binaryStr = String(val, radix: 2)
let zeroPadding = String(repeating: "0", count: bitCount - binaryStr.count)
print("0b\(zeroPadding)\(binaryStr)")
}