most of these require logout/restart to take effect
# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false
# Set a shorter Delay until key repeat| #import <Foundation/Foundation.h> | |
| @interface BNRDiggyDict : NSObject | |
| // React to object indexing. Would be nice to have a @protocol for this | |
| - (id) objectForKeyedSubscript: (id) key; | |
| - (void) setObject: (id) thing forKeyedSubscript: (id<NSCopying>) key; | |
| // And for fun, it also can react to scalar indexing. | |
| // Returns the N'th key of the top-level collection. |
| typedef void (^LXSResumeBlock)(void); | |
| typedef void (^LXSRunLoopBlock)(LXSResumeBlock resume); | |
| // Call resume() to stop the block from exercising the run loop and break out of the loop/block. | |
| // Failure to call resume() will cause the test to hang indefinitely. | |
| // This is useful to testing asynchronous actions like AFNetworking operations. See https://gist.github.com/2215212 | |
| // With some reference from https://github.com/icanzilb/MTTestSemaphore, I was able to simplify this method. | |
| inline void LXS_exercisesRunLoopInBlock(LXSRunLoopBlock block) { | |
| __block BOOL keepRunning = YES; | |
| block(^{ keepRunning = NO; }); | |
| while (keepRunning && [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.03]]) { |
| /* | |
| One of the first things someone new to iOS Development finds is that dealing with the keyboard is trickier | |
| than they think it should be. Simply changing the scrolling extents of a UITableView (or UIScrollView, or | |
| UICollectionView) that is partially covered by they keyboard reveals a lot about the internals of how iOS | |
| works and highlights various "gotchas" that need to be considered. | |
| There are various ways to know that a keyboard has been shown - but observing some specific notifications | |
| provides a reliable way to allow you to modify your views to deal with it. |
| // Swift Monads -- Maybe | |
| // Juan C. Montemayor (@norsemelon) | |
| // This operator can be used to chain Optional types like so: | |
| // optionalVal >>= f1 >>= f2 | |
| // where f1 and f2 have type `Any -> Any?` | |
| // | |
| // If a value is ever nil, the chain short-circuits and will result in nil. | |
| // This is a much neater way to do this than using the if syntax specified in | |
| // the Swift iBook. |
| var randomNumbers = [42, 12, 88, 62, 63, 56, 1, 77, 88, 97, 97, 20, 45, 91, 62, 2, 15, 31, 59, 5] | |
| func partition(v: Int[], left: Int, right: Int) -> Int { | |
| var i = left | |
| for j in (left + 1)..(right + 1) { | |
| if v[j] < v[left] { | |
| i += 1 | |
| (v[i], v[j]) = (v[j], v[i]) | |
| } | |
| } |
(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.
| import Foundation | |
| #if os(Linux) | |
| import Glibc | |
| #endif | |
| struct Random { | |
| #if os(Linux) | |
| static var initialized = false | |
| #endif | |
| extension UIApplication { | |
| /// The top most view controller | |
| static var topMostViewController: UIViewController? { | |
| return UIApplication.shared.keyWindow?.rootViewController?.visibleViewController | |
| } | |
| } | |
| extension UIViewController { | |
| /// The visible view controller from a given view controller | |
| var visibleViewController: UIViewController? { |