Skip to content

Instantly share code, notes, and snippets.

View brentsimmons's full-sized avatar

Brent Simmons brentsimmons

View GitHub Profile
//: 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 {
//: 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.
//: Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
protocol Message: class {
var uniqueID: String {get}
}
/* 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
#!/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'
//: Playground - noun: a place where people can play
import Cocoa
protocol Account: Hashable {
var accountID: String {get}
var hashValue: Int {get}
}
@brentsimmons
brentsimmons / gist:2975795
Created June 22, 2012 23:42
Category method for UIResponder to perform a selector via responder chain
@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];
@brentsimmons
brentsimmons / gist:2975787
Created June 22, 2012 23:39
Local method for UIGestureRecognizer Handling
- (void)thingWasTapped:(UIGestureRecgonizer *)gestureRecognizer {
[self rs_performSelectorViaResponderChain:@selector(myRealAction:) withObject:gestureRecognizer.view];
}
@brentsimmons
brentsimmons / allstatus.rb
Created January 1, 2012 04:25
Find Mercurial repositories and print status
#!/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'
//: 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.