This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Cocoa | |
// I’m trying to figure out how to add a Notification observer in Swift code where the notification name is defined in a .m file. | |
// | |
// This playground won’t actually run, because it assumes an NSString named SomeNotification defined in a .m file. So it can’t actually be used to see the errors. It’s just for illustration. | |
// The errors are listed in the comments. | |
class MyClass { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Cocoa | |
// When you’re downloading objects from the web, it’s common to need to merge changes | |
// from the server to already-existing local objects. (If your data model allows for | |
// mutable objects, as with Core Data, that is.) | |
// | |
// The below is a Swift translation of how I’ve done this in Objective-C. | |
// Note that it works just fine in Swift — though it does require NSObject subclasses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Cocoa | |
var str = "Hello, playground" | |
protocol Message: class { | |
var uniqueID: String {get} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The rules outlined in Comparing Reactive and Traditional represent the business logic | |
for contacting the server: coalesce requests over a timeout period, | |
coalesce non-unique consecutive requests, and ignore requests shorter | |
than a specified length. If I’ve learnt anything in nearly 30 years | |
of writing software, it’s you don’t want to put business logic in the UI. | |
Working with UI is complicated enough without embedding your business logic there. | |
That’s why the business logic is embedded in the Fetcher object | |
– mostly in the -fetchQuery:error: method. | |
Because we’re coalescing calls, having a method with a completion handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# PBS 4 Dec. 2013 | |
# Renders HTML for all the .markdown files in the current directory. | |
# Gives each file a .html suffix. | |
# Saves them in a subfolder called HTML. | |
require 'rdiscount' | |
require 'find' | |
require 'fileutils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Cocoa | |
protocol Account: Hashable { | |
var accountID: String {get} | |
var hashValue: Int {get} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation UIResponder (RSCore) | |
- (BOOL)rs_performSelectorViaResponderChain:(SEL)aSelector withObject:(id)anObject { | |
UIResponder *nomad = self; | |
while (nomad != nil) { | |
if ([nomad respondsToSelector:aSelector]) { | |
[nomad performSelector:aSelector withObject:anObject]; | |
return YES; | |
} | |
nomad = [nomad nextResponder]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)thingWasTapped:(UIGestureRecgonizer *)gestureRecognizer { | |
[self rs_performSelectorViaResponderChain:@selector(myRealAction:) withObject:gestureRecognizer.view]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -wKU | |
# Prints the directory names and hg status output for any Mercurial | |
# repositories where hg status returns something non-nil. | |
# | |
# Assumes everything is in a Projects directory in your home folder. | |
# 12/31/2011 Brent Simmons | |
require 'find' | |
require 'open3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Cocoa | |
var aSet = Set<Int>() | |
aSet.insert(1) | |
aSet.insert(2) | |
aSet.insert(3) | |
// The rest of this code doesn't even remotely work. |