Skip to content

Instantly share code, notes, and snippets.

@pablogm
pablogm / NSThread+blocks.swift
Last active October 10, 2021 06:45
Swift extension to add some methods to the NSThread class to run a block on any thread you have a reference to.
//
// NSThread+blocks.swift
// Swift extensions
//
import Foundation
public typealias Block = @convention(block) () -> Void
extension NSThread {
// A view that can flip between its "front" and "back" side.
//
// Animation implementation based on:
// Chris Eidhof, Keyframe animations <https://gist.github.com/chriseidhof/ea0e435197f550b195bb749f4777bbf7>
import SwiftUI
// MARK: - Chris's keyframe animation design
struct Keyframe<Data: Animatable> {
@vilhalmer
vilhalmer / gist:3052f7e9e7f34b92a40f
Created November 1, 2014 01:28
NSVisualEffectView undocumentation
NSVisualEffectMaterial constants, and the undocumented materials they coorespond to in various modes:
+----------------------+-------+----------+------+---------+
| MATERIAL # | LIGHT | LIGHT EM | DARK | DARK EM |
+----------------------+-------+----------+------+---------+
| | | | | |
| 0 - Appearance Based | 3 | 3 | 5 | 5 |
| | | | | |
| 1 - Light | 3 | 3 | 3 | 3 |
| | | | | |
| 2 - Dark | 4 | 4 | 4 | 4 |
@steipete
steipete / UIImage+PSPDFKitAdditions.m
Created August 13, 2011 20:52
Preload UIImage for super-smooth interaction. especially great if you use JPGs, which otherwise produce a noticeable lag on the main thread.
- (UIImage *)pspdf_preloadedImage {
CGImageRef image = self.CGImage;
// make a bitmap context of a suitable size to draw to, forcing decode
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef imageContext = CGBitmapContextCreate(NULL, width, height, 8, width*4, colourSpace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
@sindresorhus
sindresorhus / StatusBarButton.swift
Last active April 21, 2022 18:22
Creates a NSStatusBarButton with proxy methods for the NSStatusItem methods, so you don't have to deal with that class anymore. Most of the NSStatusItem properties are deprecated, so it's much nicer to deal with the NSStatusBarButton directly.
final class AssociatedObject<T: Any> {
subscript(index: Any) -> T? {
get {
return objc_getAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque()) as! T?
} set {
objc_setAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque(), newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
@russbishop
russbishop / TypeErasure.swift
Last active May 18, 2022 01:20
Type erasure with multiple adopting types
// Paste me into a playground!
import Cocoa
//: # Basic Setup
protocol FancyProtocol {
associatedtype Thing
func holdPinkyUp(x: Thing)
}
@kastiglione
kastiglione / helpers.swift
Last active June 2, 2022 02:02
Swift helpers, and the lldb setup to use them. Presented @ SLUG https://speakerdeck.com/kastiglione/advanced-debugging-and-swift
extension UIView {
/// Example: call someView.nudge(0, 30)
func nudge(_ dx: CGFloat, _ dy: CGFloat) {
self.frame = self.frame.offsetBy(dx: dx, dy: dy)
CATransaction.flush()
}
}
extension UIView {
/// Example: po UIView.root
@nicklockwood
nicklockwood / main.swift
Created December 1, 2017 11:04
Thread-safe cache implementation benchmark
var cache = [Int: Int]()
let queue = DispatchQueue(label: "cacheQueue", attributes: .concurrent)
let iterations = 100000
// In the first run, cache is empty so we're writing each time
do {
let start = CFAbsoluteTimeGetCurrent()
for i in 0 ... iterations {
var exists = false
queue.sync {

This page is now depreacted!

Check out the repo instead. The Wisdom of Quinn Now with 100% more archived PDFs.

The Wisdom of Quinn

Informative DevForum posts from everyone's favorite DTS member.

(Arranged newest to oldest)

slidenumber: true autoscale: true

iOS13とmacOS CatalinaのWebSocketサポート

参加してなくてもついていけるもん!

WWDCゴリゴリキャッチアップ会 2019

@omochimetaru