Skip to content

Instantly share code, notes, and snippets.

View wildthink's full-sized avatar

Jason Jobe wildthink

  • 22:04 (UTC -04:00)
View GitHub Profile
//
// URL+XAttr.swift
// Xattr Editor
//
// Created by Richard Csiko on 2017. 01. 21..
// https://raw.githubusercontent.com/rcsiko/xattr-editor/master/xattr-editor/Xattr%20Editor/Classes/Extensions/URL%2BXAttr.swift
//
// MIT License
//
// Copyright (c) 2017 rcsiko
import Foundation
extension String {
/**
Returns a country flag from an **uppercased** ISO Alpha-2 country code String
Example usage: "US".flag
@return A flag emoji. Example: 🇺🇸
*/
@wildthink
wildthink / CGRectAspectFit.m
Created March 22, 2017 17:15 — forked from lanephillips/CGRectAspectFit.m
Objective-C code to fit a CGRect inside or outside another CGRect while maintaining aspect ratio. The fitted rectangle is centered on the target rectangle.
CGFloat ScaleToAspectFitRectInRect(CGRect rfit, CGRect rtarget)
{
// first try to match width
CGFloat s = CGRectGetWidth(rtarget) / CGRectGetWidth(rfit);
// if we scale the height to make the widths equal, does it still fit?
if (CGRectGetHeight(rfit) * s <= CGRectGetHeight(rtarget)) {
return s;
}
// no, match height instead
return CGRectGetHeight(rtarget) / CGRectGetHeight(rfit);
@wildthink
wildthink / DocumentViewControllerExtension.swift
Created April 2, 2017 14:58
NSDocument ViewController Hooks
extension NSViewController {
var document: AnyObject? {
if let target = self.parent, target.responds (to: #selector(getter: self.document)) {
return target.perform(#selector(getter: self.document)) as AnyObject?
}
return self.view.window?.windowController?.document
}
var managedObjectContext: NSManagedObjectContext? {
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
self.shouldReloadCollectionView = NO;
self.blockOperation = [[NSBlockOperation alloc] init];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
__weak UICollectionView *collectionView = self.collectionView;
@wildthink
wildthink / BlurredRoundedView.swift
Created April 20, 2017 19:06
BlurredRoundedView updated to Swift 3
import UIKit
import MapKit
import XCPlayground
// https://macteo.it/ios/2016/08/10/blurred-rounded-uiview.html
let extraLightBlur = UIBlurEffect(style: .extraLight)
let cornerRadius : CGFloat = 0
class BlurredRoundedView: UIView {
@wildthink
wildthink / WeakSet.swift
Created July 11, 2017 18:29 — forked from preble/WeakSet.swift
A pure Swift weak set.
//
// Created by Adam Preble on 2/19/15.
//
/// Weak, unordered collection of objects.
public struct WeakSet<T where T: AnyObject, T: Hashable> {
typealias Element = T
/// Maps Element hashValues to arrays of Entry objects.
/// Invalid Entry instances are culled as a side effect of add() and remove()
//: Playground - noun: a place where people can play
import Foundation
// Use of the protocol allows us to hold collections of ActionTrampolices of any type T
protocol Action {
func performAction() -> Bool
}
class ActionTrampoline<T: AnyObject>: NSObject, Action
//
// Adaptable.swift
//
// Created by Jason Jobe on 5/2/17.
// Copyright © 2017 WildThink. All rights reserved.
//
import Foundation
public protocol Adaptable {
import Foundation
protocol Currency {
static var code: String { get }
static var factor: NSDecimalNumber { get }
}
enum GBP: Currency {
static let code = "GBP"
static let factor: NSDecimalNumber = 1.44
}