Skip to content

Instantly share code, notes, and snippets.

View danielctull's full-sized avatar

Daniel Tull danielctull

View GitHub Profile
@danielctull
danielctull / Coalescer.swift
Last active March 22, 2018 11:52
A small class to coalesce multiple calls to trigger a block once.
import Foundation
/// This manages coalescing multiple calls per frame into a
/// single execution of the given block.
final class Coalescer {
private let notificationCenter: NotificationCenter
private let notificationQueue: NotificationQueue
private let notificationName = Notification.Name(rawValue: "CoalescingNotification")
@danielctull
danielctull / GreatWesternTrailRandomTile.swift
Created April 27, 2017 10:10
A random generator for private building tiles in Great Western Trail.
import Foundation
extension String {
func pad(to length: Int) -> String {
guard self.characters.count < length else {
return self
}
@danielctull
danielctull / ReplaceSegue.swift
Created March 7, 2017 10:15
A simple NSStoryboardSegue to replace the last view controller in a NSSplitViewController.
import Cocoa
class ReplaceSegue: NSStoryboardSegue {
override func perform() {
guard
let source = sourceController as? NSViewController,
let new = destinationController as? NSViewController,
// Used to make sure the value is 0 or above
public struct Positive {
let value: Float
public init(_ value: Float) {
if value < 0 {
self.value = 0
@danielctull
danielctull / AppDelegate.m
Last active April 12, 2019 07:15
Shows selection of table view cells on pressing the up/down arrow keys.
@implementation AppDelegate
#pragma mark - Key Command Controller
- (KeyCommandController *)keyCommandController {
if (!_keyCommandController) {
UIViewController *rootViewController = self.window.rootViewController;
if (rootViewController){
import Foundation
protocol File {}
class FileClass: File {}
let set = NSOrderedSet(array: [FileClass(), FileClass()])
let files = set.array as? [File] // Type 'File' does not conform to protocol 'AnyObject'

Keybase proof

I hereby claim:

  • I am danielctull on github.
  • I am danielctull (https://keybase.io/danielctull) on keybase.
  • I have a public key ASCl7emory6aN12AhnRtqg-o8bSLZcWLJFdPl1KLO0Vcigo

To claim this, I am signing this object:

@danielctull
danielctull / CTFrame.swift
Last active April 13, 2019 17:42
Is there a better way of coercing CFArray to a swift array?
import CoreText
extension CTFrame {
var lines: [CTLine] {
// This is the only way I've currently found to get the
// CFArray of CTLines to cast to a swift array.
let linesAO: [AnyObject] = CTFrameGetLines(self) as [AnyObject]
var images: [UIImage] = []
for i in 0...9 {
guard let image = UIImage(named: "Loading \(i)") else {
continue
}
images.append(image)
}
let integerToDescribe = 5
var description = "The number \(integerToDescribe) is"
switch integerToDescribe {
case 2, 3, 5, 7, 11, 13, 17, 19:
description += " a prime number, and also"
}
description += " an integer."