View LiveSquishButton.swift
import UIKit
class LiveSquishButton: UIView {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
updateSquish(with: 0.05)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
View K-means colour matching.m
@import Foundation;
@import CoreGraphics;
@import ImageIO;
static NSUInteger maxThumbnailSize = 20;
extern uint64_t dispatch_benchmark(size_t count, void (^block)(void));
/// Returns a CGImage with a +1 retain count.
static CGImageRef createThumbnailFromURL(NSURL *imageURL, NSUInteger maxPixelSize)
View LazyMapCollection-1.swift
import Foundation
let dictionary = ["one": 1, "two": 2]
let lazyValues = dictionary.values
let jsonData = try JSONSerialization.data(withJSONObject: lazyValues, options: [])
// ❗️ Argument type 'LazyMapCollection<Dictionary<String, Int>, Int>' does not conform to expected type 'AnyObject'
View random-string.m
@implementation NSArray (DHRandom)
- (nullable id)dh_random {
if (self.count == 0) {
return nil;
}
return self[arc4random_uniform((u_int32_t)self.count)];
}
@end
View DHLazyLinkedList.h
@import Foundation;
NS_ASSUME_NONNULL_BEGIN
@interface DHLazyLinkedList<ObjectType> : NSArray<ObjectType>
- (instancetype)initWithRootObject:(ObjectType)rootObject nextObjectBlock:(ObjectType _Nullable (^)(ObjectType))next NS_DESIGNATED_INITIALIZER;
- (nullable ObjectType)objectAfterObject:(ObjectType)object;
View RGB-XYZ.c
#include <CoreGraphics/CoreGraphics.h>
static inline CGFloat gammaCorrect(CGFloat component) {
if (component > 0.04045f) {
return pow((component + 0.055f) / 1.055f, 2.4f);
}
return component / 12.92f;
}
View anchor-conversion.swift
// TODO: greater than, less than, multipliers, constants
import Foundation
let input = "[container.trailingAnchor constraintEqualToAnchor:childView.trailingAnchor]"
func attribute(fromAnchor anchor: String) -> String {
if let range = anchor.rangeOfString("Anchor") {
var s = anchor.substringToIndex(range.startIndex)
let firstChar = s.removeAtIndex(s.startIndex)
View filename-in-preamble.py
# coding: utf-8
import os
import sys
# Make source code files in a directory all begin with consistent preamble, which is:
# //
# // <filename>
#
# This code is very rough and could be better in lots of ways.
View reset-simulators.py
#!/usr/bin/python
#coding: utf-8
import json
import subprocess
def delete_all_simulators():
devices_json = subprocess.check_output(["xcrun", "simctl", "list", "--json", "devices"])
devices_by_runtime = json.loads(devices_json)["devices"]
for runtime, devices in devices_by_runtime.iteritems():
View UINavigationItem+DHDescription.m
@implementation UINavigationItem (DHDescription)
- (NSString *)description {
return [self dictionaryWithValuesForKeys:@[@"title", @"titleView", @"prompt", @"hidesBackButton", @"backBarButtonItem", @"leftItemsSupplementBackButton", @"leftBarButtonItems", @"rightBarButtonItems"]].description;
}
@end