Skip to content

Instantly share code, notes, and snippets.


Cory Alder coryalder

View GitHub Profile
coryalder / gist:6effee57a123420f2f949955f039fcee
Last active Jul 11, 2017 — forked from gavrix/gist:5054182
Script integrating OCLint into XCode. Put it in "Run script" build phase.
View gist:6effee57a123420f2f949955f039fcee
# original
source ~/.bash_profile
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
View SwizzleSafariStatusBar.swift
class Dummy: NSObject {
@objc func barStyle() -> UIStatusBarStyle {
return .LightContent
func swizzle() {
guard let safariClass = NSClassFromString("SFSafariViewController") else {
print("can't swizzle, iOS 8")
View FailableInitializerFail.swift
// This code does not compile without the following two changes
// 1. add ! to the type of expensiveThing (`String!`)
// 2. expensiveThing = nil // set expensiveThing to nil
// This doesn't really make sense to me. Why should I be forced to finish setup, if I'm going to fail?
// The swift book explains that this is required, but not the logic behind it:
// Search for "Failable Initializers for Classes"
coryalder / cgi.swift
Created Dec 3, 2015
Example linux swift cgi
View cgi.swift
import Foundation
// work around the currently missing .componentsSeparatedByString method
extension String {
func split(on: Character) -> [String] {
var segments = [String]()
var current = ""
coryalder / SuggestionController.swift
Created Nov 19, 2015
Autocomplete filter code from Rivet's autocomplete suggestion engine
View SuggestionController.swift
// depends on
class SuggestionController {
// has a couple of notable vars:
// delegate, where the inputted text is loaded from
// rawCompletions, an array of possible suggestions (unfiltered)
// autocompletions, the filtered array of suggestions we're offer up to the user
func filterAutocompletions() {
coryalder / protocol_id.m
Created Jul 31, 2015
id and protocol conformance
View protocol_id.m
// when specify id as the type, you can use NSObject methods.
// when you specify as a custom protocol, you cannot.
// UNLESS you say that your custom protocol includes <NSObject>
#import <Foundation/Foundation.h>
@protocol CustomProtocol // <NSObject> // uncommenting <NSObject> fixes the issue
coryalder / IntroToSwift.swift
Created Jul 20, 2015
a quick intro to some of the language features of swift
View IntroToSwift.swift
//: Playground - noun: a place where people can play
import Cocoa
// basic strings
var str: String = "Hello,"
let helloWorld = str + " world"
View CoreAnimation.m
-(void)viewDidAppear:(BOOL)animated {
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:(CGRect){-50,-50,100,100}];
// 0, 0 is center
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
View throw.swift
// What's the best syntax for this:
// no trailing-closures
// explicit about what's happening, but those ()'s aren't needed... can we do better?
throwActions.filter({ $0.direction == dir }).map({ $0.action() })
// all trailing closures
// weirdly looks like we're mapping the block, rather than the result of filtering throwActions using that block.
coryalder / UIImage+Invert.swift
Created Mar 12, 2015
Invert a UIImage at runtime using Core Image CIFilter + CIContext
View UIImage+Invert.swift
extension UIImage {
func invertedImage() -> UIImage? {
let img = CoreImage.CIImage(CGImage: self.CGImage)
let filter = CIFilter(name: "CIColorInvert")
filter.setValue(img, forKey: "inputImage")