Skip to content

Instantly share code, notes, and snippets.

Mattt mattt

Block or report user

Report or block mattt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mattt / bridge.swift
Last active Mar 29, 2019
Example usage of @mxcl's swift-sh
View bridge.swift
#!/usr/bin/swift sh
import DeckOfPlayingCards // @NSHipster ~> 4.0.0
import PlayingCard
import Cycle // @NSHipster == bb11e28
class Player {
var name: String
var hand: [PlayingCard] = []

Pitch: Unicode Named Character Escape Sequence


This proposal adds a new \N{name} escape sequence to Swift string literals, where name is the name of a Unicode character.


The Unicode named character escape sequence was previously discussed here:

View Comparator.swift
import Foundation
extension Collection where Element: Comparable {
func sorted(ascending: Bool = true, using comparator: (Element) -> (Element) -> ComparisonResult) -> [Element] {
return self.sorted { lhs, rhs in
comparator(lhs)(rhs) == (ascending ? .orderedAscending : .orderedDescending)
View UnitConcentrationMass+MicrogramsPerCubicMeter.swift
import Foundation
extension UnitConcentrationMass {
class var microgramsPerCubicMeter: UnitConcentrationMass {
let converter = UnitConverterLinear(coefficient: 1e-9)
return .init(symbol: "µg/m³", converter: converter)
View unzip.swift
func unzip<S: Sequence, T, U>(_ sequence: S) -> (AnySequence<T>, AnySequence<U>)
where S.Element == (T, U)
return (
AnySequence({ $0.0 }),
AnySequence({ $0.1 })
let fibonacci = sequence(first: (0, 1), next: { ($1, $0 + $1) })
View swift-unicode-name-escape-pre-pitch.swift
# Problem
In Swift, it can be cumbersome to work with Unicode characters that are
non-printing, confusable, or have difficulty rendering in the editor.
For example, to generate the "Family: Woman, Girl" emoji:
// Option 1: Unicode Scalar Value Escapes
View TruthyValue.swift
import Foundation
struct TruthyValue {
var value: Bool?
init(_ value: Bool?) {
self.value = value
init(_ value: Int) {
switch value {
View BoundedSequence.swift
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?
View zalgo.swift
func zalgo(_ string: String, intensity: Int = 5) -> String {
let combiningDiacriticMarks = 0x0300...0x036f
let latinAlphabetUppercase = 0x0041...0x005a
let latinAlphabetLowercase = 0x0061...0x007a
var output: [UnicodeScalar] = []
for scalar in string.unicodeScalars {
guard (latinAlphabetUppercase).contains(numericCast(scalar.value)) ||
mattt / Sieve.swift
Last active Jan 27, 2019
Sieve of Eratosthenes with Accelerate
View Sieve.swift
// Calculate prime numbers in a given range
// using Sieve of Eratosthenes
import Accelerate
var primes: [Int] = []
let range = 0...999
var numbers =
You can’t perform that action at this time.