(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
// Taken from http://PSPDFKit.com. This snippet is under public domain. | |
#define UIKitVersionNumber_iOS_7_0 0xB57 | |
BOOL PSPDFIsUIKitFlatMode(void) { | |
static BOOL isUIKitFlatMode = NO; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
// We get the modern UIKit if system is running >= iOS 7 and we were linked with >= SDK 7. | |
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) { | |
isUIKitFlatMode = (NSVersionOfLinkTimeLibrary("UIKit") >> 16) >= UIKitVersionNumber_iOS_7_0; | |
} |
static UIView *PSPDFViewWithSuffix(UIView *view, NSString *classNameSuffix) { | |
if (!view || classNameSuffix.length == 0) return nil; | |
UIView *theView = nil; | |
for (__unsafe_unretained UIView *subview in view.subviews) { | |
if ([NSStringFromClass(subview.class) hasSuffix:classNameSuffix]) { | |
return subview; | |
}else { | |
if ((theView = PSPDFViewWithSuffix(subview, classNameSuffix))) break; | |
} |
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); |
;;;; Super top secret talk stuff nobody should ever see. Shhh. | |
(in-ns 'user) | |
(defmacro bench [& body] | |
`((re-find #"\"(.*)\"" (with-out-str (time (do ~@body)))) 1)) | |
*ns* | |
(require 'clojure.walk) |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
// | |
// CollectionViewDataSource.swift | |
// Khan Academy | |
// | |
// Created by Andy Matuschak on 10/14/14. | |
// Copyright (c) 2014 Khan Academy. All rights reserved. | |
// | |
import UIKit |
Copyright 2015 Chris Eidhof | |
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 furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHE |
import UIKit | |
// This class allows the "presentedController" to receive touches | |
// https://pspdfkit.com/blog/2015/presentation-controllers/ | |
class PSPDFTouchForwardingView: UIView { | |
var passthroughViews: [UIView] = [] | |
override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? { | |
guard let hitView = super.hitTest(point, withEvent: event) else { return nil } |
Taught by Brad Knox at the MIT Media Lab in 2014. Course website. Lecture and visiting speaker notes.