Skip to content

Instantly share code, notes, and snippets.

View brentsimmons's full-sized avatar

Brent Simmons brentsimmons

View GitHub Profile
@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 / 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];
//: Playground - noun: a place where people can play
import Cocoa
protocol Account: Hashable {
var accountID: String {get}
var hashValue: Int {get}
}
#!/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'
/* 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
//: Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
protocol Message: class {
var uniqueID: String {get}
}
//: 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
// 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 {
@brentsimmons
brentsimmons / googleSearchString.py
Created August 1, 2012 04:32
A script that generates a Google search URL and pastes it to the Mac OS X clipboard
#!/usr/bin/python
import sys
import os
from urllib import urlencode
import subprocess
# setClipboardData is from <http://www.macdrifter.com/2011/12/python-and-the-mac-clipboard/>*/
def setClipboardData(data):
@brentsimmons
brentsimmons / headerview.m
Created April 26, 2014 22:09
UITableView header issues
#pragma mark - Class Methods
+ (BOOL)requiresConstraintBasedLayout {
return YES;
}
#pragma mark - Init
- (id)initWithFrame:(CGRect)frame {