Skip to content

Instantly share code, notes, and snippets.

View jdewind's full-sized avatar

Justin DeWind jdewind

  • LifeWorks
  • Grand Rapids
View GitHub Profile
class Car
include RequireOptions
def go(opts)
gear, speed = require_options(opts, :speed, :gear)
# ...
end
end
@implementation ConfirmationAlert
+ (void)show:(NSString *)message delegate:(id<UIAlertViewDelegate>)theDelegate {
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Confirm" message:message delegate:theDelegate cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil] autorelease];
[alertView show];
}
@end
@implementation MyObject
-(void)showOneConfirmationAlert:(NSMutableDictionary *)externalState {
externalStateForOneConfirmationAlert = [externalState retain];
oneConfirmationAlert = [[ConfirmationAlert show:@"Are you sure about this?" delegate:self] retain];
}
-(void)showAnotherConfirmationAlert:(NSMutableDictionary *)externalState {
externalStateForAnotherConfirmationAlert = [externalState retain];
oneConfirmationAlert = [[ConfirmationAlert show:@"Again, are you sure?" delegate:self] retain];
}
typedef void (^ConfirmationBlock)(UIAlertView *);
+ (void)show:(NSString *)message confirmed:(ConfirmationBlock)confirmBlock canceled:(ConfirmationBlock)canceledBlock {
if(blocks == nil) {
blocks = [[NSMutableDictionary dictionary] retain];
delegate = [[BlockConfirmationAlert alloc] init];
}
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Confirm" message:message delegate:delegate cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil] autorelease];
NSDictionary *blockDict = [NSDictionary dictionaryWithObjectsAndKeys:[[confirmBlock copy] autorelease], @"confirm", [[canceledBlock copy] autorelease], @"cancel", nil];
[blocks setObject:blockDict forKey:[NSNumber numberWithUnsignedInt:[alertView hash]]];
[alertView show];
+ (void)showOneConfirmationAlert:(NSMutableDictionary *)externalState {
[BlockConfirmationAlert show:@"Are you sure about this?"
confirmed:^(UIAlertView *alertView) {
//...
NSLog([externalState objectForKey:@"Key"]);
}
canceled:^(UIAlertView *alertView) {
//...
NSLog([externalState objectForKey:@"DifferentKey"]);
}];
NSInvocation *invocation;
//set it up
@try {
objc_msgSend(obj, [invocation selector]);
}
@catch (NSException * e) {
NSLog(@"Caught exception: %@", e);
}
NSInvocation *invocation;
// Create it
[invocation setTarget:obj];
[invocation setSelector:@selector(myMethod)];
@try {
[invocation invoke];
}
@catch (NSException * e) {
NSLog(@"This exception cannot be caught");
SHKItem *item = [[[SHKItem alloc] init] autorelease];
item.shareType = SHKShareTypeText;
item.contextBlock = ^(NSString *selectedSharer, id item) {
if ([selectedSharer isEqualToString:@"SHKTwitter"]) {
[item setShareType:SHKShareTypeURL];
[item setURL:[NSURL URLWithString:@"http://www.google.com"]];
[item setTitle:@"Tweeting this! #HashTagsAreCoolForKids"];
} else {
[item setMessage:@"This is for everything else http://www.google.com"];
}
if (state == MotionState.DRAGGING) {
bottomCaliperMatrix.set(bottomCaliperSavedMatrix);
float yoffset = motionEvent.getY() - startPoint.y;
bottomCaliperMatrix.postTranslate(0, yoffset);
float[] bottomMatrix = new float[9];
bottomCaliperMatrix.getValues(bottomMatrix);
float delta = Math.abs(Math.min(bottomMatrix[5] - 79, 0));
bottomCaliperMatrix.postTranslate(0, delta);
}