Skip to content

Instantly share code, notes, and snippets.

View citynight's full-sized avatar
🎯
Focusing

Logan citynight

🎯
Focusing
View GitHub Profile
@onevcat
onevcat / Delegate.swift
Last active December 23, 2022 07:21
An auto-weak delegate for handle modern delegate pattern.
import Foundation
/// A class that keeps a weakly reference for `self` when implementing `onXXX` behaviors.
/// Instead of remembering to keep `self` as weak in a stored closure:
///
/// ```swift
/// // MyClass.swift
/// var onDone: (() -> Void)?
/// func done() {
/// onDone?()
import Foundation
enum Either<A: Codable, B: Codable>: Codable {
case left(A)
case right(B)
enum CodingKeys: CodingKey {
case left
case right
}
@chriseidhof
chriseidhof / animations.swift
Last active November 9, 2017 07:13
Purely Functional Animations
//
// ViewController.swift
// AnimationTesting
//
// Created by Chris Eidhof on 01.10.17.
// Copyright © 2017 objc.io. All rights reserved.
//
import UIKit
//cc -Wextra -o build/dump-header-map dump-header-map.c
// see: https://github.com/llvm-mirror/clang/blob/release_40/include/clang/Lex/HeaderMapTypes.h
// https://github.com/llvm-mirror/clang/blob/release_40/include/clang/Lex/HeaderMap.h// https://github.com/llvm-mirror/clang/blob/release_40/lib/Lex/HeaderMap.cpp
// This is basically dump() from there.
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <err.h>
@steipete
steipete / SpinlockTestTests.swift
Last active January 20, 2025 15:55 — forked from RomanTruba/Synchronization_test_iOS_SDK10
Updated for Xcode 8, Swift 3; added os_unfair_lock
//
// SpinlockTestTests.swift
// SpinlockTestTests
//
// Created by Peter Steinberger on 04/10/2016.
// Copyright © 2016 PSPDFKit GmbH. All rights reserved.
//
import XCTest
let mark = "####################################"
let chapter: (String) -> Void = { print("\n", mark, "# \($0)", mark, separator: "\n")}
// ----------------------------------------------------------------------------------------------------
// MARK: - Look ma, no protocols
//
// http://elm4ward.github.io/swift/generics/type/erasure/2016/04/21/erase-em-all.html
//
// Erasing generics to life in freedom
// This is a follow up to the article about Protocols with Typealias
@chriseidhof
chriseidhof / LICENSE
Last active October 30, 2025 15:50
A tiny networking library
Copyright 2015 Chris Eidhof
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHE