Skip to content

Instantly share code, notes, and snippets.

struct Regex {
let pattern: String
let options: NSRegularExpressionOptions!
private var matcher: NSRegularExpression {
return NSRegularExpression(pattern: self.pattern, options: self.options, error: nil)
}
init(pattern: String, options: NSRegularExpressionOptions = nil) {
self.pattern = pattern
@mattt
mattt / Rakefile
Last active June 10, 2020 14:18
A benchmark comparing various methods of downloading popular Swift packages
require 'benchmark'
require 'tmpdir'
require 'json'
include Benchmark
namespace :benchmark do
task all: %i[full_clone shallow_clone curl_unzip]
task full_clone: ['packages.json'] do
@mattt
mattt / CTExposureDetectionSession+Extensions.swift
Last active April 27, 2020 23:51
Theoretical convenience API for working with Apple's ContactTracing framework
import ContactTracing
extension CTExposureDetectionSession {
func addPositiveDiagnosisKeys(batching keys: [CTDailyTracingKey], completion: CTErrorHandler) {
if keys.isEmpty {
completion(nil)
} else {
let cursor = keys.index(keys.startIndex, offsetBy: maxKeyCount, limitedBy: keys.endIndex) ?? keys.endIndex
let batch = Array(keys.prefix(upTo: cursor))
let remaining = Array(keys.suffix(from: cursor))
@mattt
mattt / Alamofire.json
Last active April 9, 2020 07:29
Extremely early proof-of-concept Markdown document generation output for swift-doc
{
"/Users/mattt/Desktop/Alamofire.swift" : {
"deinitializers" : [],
"functions" : [
{
"declaration" : {
"name" : "request",
"genericRequirements" : [],
"signature" : {
"output" : "DataRequest",
@mattt
mattt / cc.css
Last active April 9, 2020 07:29
Creative Commons Symbols @font-face CSS
@font-face {
font-family: "Creative Commons Symbols";
src: url(font_path("CreativeCommonsSymbols.woff2")) format("woff2"),
url(font_path("CreativeCommonsSymbols.woff")) format("woff");
font-weight: normal;
font-style: normal;
unicode-range: U+1F10D-1F10F, U+1F16D-1F16F;
}
i {
@mattt
mattt / NSRange-Conventional.h
Last active January 22, 2020 23:32
Re-declaration of existing `NSRange` functions and implementation of new functions to match conventions of comparable Foundation and Core Foundation types.
NS_INLINE NSRange NSRangeMake(NSUInteger loc, NSUInteger len) {
return NSMakeRange(loc, len);
}
NS_INLINE NSUInteger NSRangeMax(NSRange range) {
return NSMaxRange(range);
}
NS_INLINE BOOL NSRangeContainsLocation(NSUInteger loc, NSRange range) {
return NSLocationInRange(loc, range);
@mattt
mattt / swift-802.0.31.3.json
Last active December 9, 2019 20:32
Early Swift Doc output JSON for Swift standard library
This file has been truncated, but you can view the full file.
{
"files" : [
{
"enumerations" : [
{
"documentation" : [],
"declaration" : {
"attributes" : [],
"modifiers" : [
{
@mattt
mattt / undocumented-symbol-urls-2019-09-20.txt
Created October 19, 2019 17:13
Undocumented Apple API symbols according to nooverviewavailable.com (as of 2019-09-20)
This file has been truncated, but you can view the full file.
"https://developer.apple.com/documentation/accelerate/vimagecvimageformat/chromasiting/3241430"
"https://developer.apple.com/documentation/accelerate/vdsp/dcttransformtype/3240713"
"https://developer.apple.com/documentation/accelerate/vdsp/dfttransformtype/3240728"
"https://developer.apple.com/documentation/accelerate/vimage/error/3241360"
"https://developer.apple.com/documentation/accelerate/quadrature/error/3240672"
"https://developer.apple.com/documentation/accelerate/vimagecvimageformat/format/3241442"
"https://developer.apple.com/documentation/accelerate/vdsp/fouriertransformdirection/3240744"
"https://developer.apple.com/documentation/accelerate/vdsp/integrationrule/3240753"
"https://developer.apple.com/documentation/accelerate/vimage/options/3241388"
"https://developer.apple.com/documentation/accelerate/vdsp/radix/3240761"
import Darwin
extension Int {
static func random() -> Int {
return Int(arc4random())
}
static func random(range: Range<Int>) -> Int {
return Int(arc4random_uniform(UInt32(range.endIndex - range.startIndex))) + range.startIndex
}
public struct BoundedSequence<Base>: Sequence, IteratorProtocol where Base: Sequence {
public struct Boundary: Equatable {
public let isStart: Bool
public let isEnd: Bool
}
private var _iterator: Base.Iterator
private var _previous: Base.Element?
private var _current: Base.Element?
private var _next: Base.Element?