Skip to content

Instantly share code, notes, and snippets.

View mingsai's full-sized avatar
🎯
Focusing

Tommie N. Carter, Jr. mingsai

🎯
Focusing
View GitHub Profile
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2013 Peter Steinberger. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#import <objc/runtime.h>
#import <objc/message.h>
// Compile-time selector checks.
//
// PSPDFThreadSafeMutableDictionary.m
//
// Copyright (c) 2013 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
//
// NSURL_Networking.swift
// swiftTools
//
// Created by Zachry Thayer on 6/3/14.
// Copyright (c) 2014 Zachry Thayer. All rights reserved.
//
import Foundation
@venkatperi
venkatperi / KVOTest
Created August 11, 2014 18:38
KVOTests
//
// KVOTests.swift
// SwiftStuff
//
// Created by Venkat Peri on 8/11/14.
// Copyright (c) 2014 vperi. All rights reserved.
//
import Cocoa
import XCTest
let array = ["P","Q","R","S","T","P","R","A","T","B","C","P","P","P","P","P","C","P","P","J"]
extension Array {
func unique<T: Equatable>() -> [T] {
return self.reduce([T](), combine: { (array, value) -> [T] in
var result = array
let valAsT = value as T
if (!contains(array, valAsT)) {
result.append(valAsT)
}
@john-07
john-07 / gist:07f1615ec6a55bc676d2
Created April 24, 2015 07:27
Core Data helpers
func fetchAll<T:NSManagedObject>(type:T.Type, predicate:NSPredicate?, sorts:[AnyObject]?=nil)->[T]{
let entityName = NSStringFromClass(type);
let request = NSFetchRequest(entityName:entityName);
request.predicate = predicate;
request.sortDescriptors = sorts;
var error:NSError?=nil;
if let rows = context.executeFetchRequest(request, error:&error) {
return rows as [T];
}else{
DDLogError("\(error)");
@venkatperi
venkatperi / CGContextExt.swift
Created April 24, 2015 20:54
CGContext Syntactic Sugar
// CGContextABCD(context!, ...) becomes context?.ABCD(...)
import Cocoa
extension CGContext {
func saveGState() { CGContextSaveGState(self) }
func restoreGState() { CGContextRestoreGState(self) }
func scaleCTM( sx: CGFloat, sy: CGFloat) { CGContextScaleCTM(self, sx, sy) }
func translateCTM( tx: CGFloat, ty: CGFloat) { CGContextTranslateCTM(self, tx, ty) }
func rotateCTM( angle: CGFloat) { CGContextRotateCTM(self, angle) }
@mz2
mz2 / NSArray+UniqueObjects.h
Created March 21, 2010 23:12
NSArray+UniqueObjects.h: get unique objects from an NSArray, whilst maintaining sort ordering
#import <Foundation/Foundation.h>
@interface NSArray (UniqueObjects)
-(NSArray*) uniqueObjects;
-(NSArray*) uniqueObjectsSortedUsingSelector: (SEL)comparator;
-(NSArray*) uniqueObjectsSortedUsingFunction: (NSInteger (*)(id, id, void *)) comparator
@jeffmccune
jeffmccune / repair_mac_ruby_links.sh
Created December 1, 2011 17:26
Repair Mac OS X Ruby Symlinks
@markd2
markd2 / log.m
Created June 25, 2012 15:27
QuietLog, and a little demonstration
#import <Foundation/Foundation.h>
// clang -fobjc-arc -Wall -Wformat -Weverything -Wno-format-nonliteral -framework Foundation -o log log.m
// Compiler likes explicit function prototypes prior to first use.
// Add an attribute to get additional checking from the compiler
extern void QuietLog (NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
// !!! The attribute above isn't warning like it should, but NSLog's _is_ working.
// This is NSLog's attribute. I'm currently baffled.