Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
jspahrsummers / bad.m
Last active January 20, 2021 11:55
Synchronizing with multiple GCD queues
//
// DON'T do this, or else you risk a deadlock (e.g., by accidentally performing it in a different order somewhere)
//
dispatch_async(firstQueue, ^{
dispatch_sync(secondQueue, ^{
// code requiring both queues
});
});
@JadenGeller
JadenGeller / Cut.swift
Last active January 22, 2017 20:47
Cut a sequence given a predicate taking in successive elements
extension Collection where SubSequence: Sequence, SubSequence.Iterator.Element == Iterator.Element {
func cut(atSuccession shouldCut: (Iterator.Element, Iterator.Element) throws -> Bool) rethrows -> [Self.SubSequence] {
var (fromIndex, toIndex) = (startIndex, startIndex)
var result: [SubSequence] = []
for (x, y) in zip(self, dropFirst()) {
defer { toIndex = index(after: toIndex) }
guard try shouldCut(x, y) else { continue }
result.append(self[fromIndex...toIndex])
fromIndex = index(after: toIndex)
}
#!/usr/bin/swift
import AppKit
// MARK: - Helpers
@inline(__always) func error(_ message: String) {
print("💥 \(message)")
}
@inline(__always) func success(_ message: String) {
/// |                    World                 |
/// |------------------------------------------|
/// | Module A | Module B | Module C | Module D|
  1. World is a module
  2. World is aware of all modules.
  3. Modules aren't aware of World.