Skip to content

Instantly share code, notes, and snippets.

@DivineDominion
DivineDominion / ValueTransformation.swift
Created March 1, 2015 19:27
Paste this into a playground and see what happens with the two client code examples at the bottom. Should work out of the box.
import Cocoa
/// A wrapper around any type to make Result compile
class Box<T> {
let unbox: T
init(_ value: T) {
self.unbox = value
}
}
import Cocoa
// Missing isWord
func isWord(string: String) -> Bool {
if let _ = Int(string) { return false }
let range = NSSpellChecker.shared().checkSpelling(of: string, startingAt: 0)
return range.location == NSNotFound
}
/*:
import UIKit
// Swift rewrite challenge
// Starting point: https://gist.github.com/jkereako/200342b66b5416fd715a#file-scale-and-crop-image-swift
func scaleAndCropImage(
image: UIImage,
toSize size: CGSize,
fitImage: Bool = true
) -> UIImage {
import Vapor
import HTTP
import Foundation
extension Node {
var backDoorToRealValues: Any {
return self.wrapped.backDoorToRealValues
}
}
import Foundation
// Extend String to support regex searching by conforming
// to CustomStringConvertible
extension String: CustomStringConvertible {
public var description: String {return self}
}
// Regex support for keys
public extension Dictionary where Key: CustomStringConvertible {
@steipete
steipete / Warnings.xcconfig
Last active March 13, 2018 14:47
Did you knew that Clang Analyzer as alpha checkers? Early Christmas is here! (Ignore the rest... we run our PDF SDK https://pspdfkit.com with -Weverything because warnings are awesome to prevent bugs) - See https://gist.github.com/steipete/28849365e603dc2015c7107d85142e7b/revisions for a list of Xcode 8.3 changes
// clang -cc1 -analyzer-checker-help
// OVERVIEW: Clang Static Analyzer Checkers List
// USAGE: -analyzer-checker <CHECKER or PACKAGE,...>
//
// CHECKERS:
// alpha.core.BoolAssignment Warn about assigning non-{0,1} values to Boolean variables
// alpha.core.CallAndMessageUnInitRefArg
// Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers, and pointer to undefined variables)
// alpha.core.CastSize Check when casting a malloc'ed type T, whether the size is a multiple of the size of T
// alpha.core.CastToStruct Check for cast from non-struct pointer to struct pointer
@chourobin
chourobin / RKAppDelegate.m
Last active October 22, 2018 14:22
Setting up magical record with RestKit
#import <RestKit/RestKit.h>
#import "CoreData+MagicalRecord.h"
// Use a class extension to expose access to MagicalRecord's private setter methods
@interface NSManagedObjectContext ()
+ (void)MR_setRootSavingContext:(NSManagedObjectContext *)context;
+ (void)MR_setDefaultContext:(NSManagedObjectContext *)moc;
@end
@implementation AppDelegate
@erica
erica / pggrep.swift
Last active November 30, 2018 08:52
Find files in playgrounds, which are otherwise not indexed by spotlight
//
// main.swift
// pggrep - updated 12/4/15
// Created by Erica Sadun on 6/17/15.
// Copyright © 2015 Erica Sadun. All rights reserved.
//
import Foundation
extension String {
import Cocoa
// Note: use of enumeration var in generic is instadeath
// Note: use of static var in generic is not yet supported
public protocol EnumConvertible: Hashable {
init?(hashValue hash: Int)
static func countMembers() -> Int
static func members() -> [Self]
}
@ryanmaxwell
ryanmaxwell / ryan-objc.cfg
Last active June 26, 2019 16:41
Objective-C Uncrustify Config
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.2 (140)
#
# Alignment
# ---------
## Alignment