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
# assumes control of all hosts in /Local/Default/Hosts | |
# https://gist.github.com/1062860 | |
hostoggle() { | |
if (( ${#*} == 0 )); then | |
# no host given, print current list of hosts banned | |
dscl . -ls Hosts | |
fi | |
for host in "$@"; do | |
if $(dscl . -read Hosts/$host >&- 2>&-); then | |
# delete existing host records (raw and www-less) |
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
require 'open-uri' | |
# monkey patching, but we're still cool right? | |
class Fixnum | |
def to_proc | |
->(obj) { obj[self] } | |
end | |
end | |
class Hash |
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
class << Motion::Project::App | |
real_setup = instance_method(:setup) | |
define_method :setup do |&block| | |
real_setup.bind(self).call(&block) | |
# run after hook here | |
end | |
end |
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
framework 'CoreData' | |
# Create a minimal model | |
$thing = NSEntityDescription.alloc.init | |
$thing.name = 'Thing' | |
$model = NSManagedObjectModel.alloc.init | |
$model.entities = [$thing] | |
# Create the custom store class | |
class CustomStore < NSIncrementalStore |
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
class AppDelegate | |
def application(application, didFinishLaunchingWithOptions:launchOptions) | |
a = NSEntityDescription.new | |
a.name = 'A' | |
b = NSEntityDescription.new | |
b.name = 'B' | |
bs = NSRelationshipDescription.new | |
bs.name = 'bs' | |
bs.destinationEntity = b | |
bs.ordered = true |
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
CGRect CGRectIntegralScaledEx(CGRect rect, CGFloat scale) | |
{ | |
return CGRectMake(floorf(rect.origin.x * scale) / scale, floorf(rect.origin.y * scale) / scale, ceilf(rect.size.width * scale) / scale, ceilf(rect.size.height * scale) / scale); | |
} | |
CGRect CGRectIntegralScaled(CGRect rect) | |
{ | |
return CGRectIntegralScaledEx(rect, [[UIScreen mainScreen] scale]); | |
} |
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
module UncaughtThrowError | |
def self.===(ex) | |
ArgumentError === ex && ex.message =~ /uncaught throw/ | |
end | |
end | |
begin | |
throw :foo | |
rescue UncaughtThrowError | |
puts 'Success: Rescued UncaughtThrowError' |
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
[[[signal | |
// Map YES to 1, NO to -1 | |
map:^(NSNumber* b) { | |
return @(b.boolValue ? 1 : -1); | |
}] | |
// Running sum of yes/1's and no/-1's | |
startWithScan:@0 combine:^(NSNumber* running, NSNumber* next) { | |
return @(running.intValue + next.intValue); | |
}] | |
// A 0-sum means equal number of YES/NO's; Map 0 to YES |
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 casperjs | |
# | |
# Example: ./github-users.coffee Greenville | |
# | |
{Casper} = require 'casper' | |
class GitHubUserScraper extends Casper | |
USER_AGENT: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' |
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
- (NSArray *)mapConcurrent; | |
{ | |
NSArray *originals = self.listOfObjects; | |
NSUInteger count = originals.count; | |
NSMutableArray *collected = [[NSMutableArray alloc] initWithCapacity:count]; | |
for (NSUInteger i = 0; i < count; i++) { | |
[collected addObject:[NSNull null]]; | |
} |
OlderNewer