Skip to content

Instantly share code, notes, and snippets.

View casspangell's full-sized avatar

mondousage casspangell

View GitHub Profile
@casspangell
casspangell / gist:bfd8180c808f143cd1a0
Last active August 29, 2015 14:19
Rename Filename Loop Bash
#!/bin/bash
# Rename files in dir to slide_##.pdf with two numerals
# Exampe filename: UMB_AR App_AN_041515_FA.33.pdf
foo = 0
for f in *.pdf
do
@casspangell
casspangell / gist:185ce843496f72a71e3f
Last active August 29, 2015 14:19
Rotate UIView 360 Degrees
- (void)animate {
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotate.byValue = @(M_PI*2); // Change to - angle for counter clockwise rotation
rotate.duration = 5.0;
rotate.repeatCount = HUGE_VALF; //rotates infinitely. Can be finite value.
[self.view.layer addAnimation:rotate forKey:@"myRotationAnimation"];
}
@casspangell
casspangell / viewcontroller.m
Last active August 29, 2015 14:11
AVAssetsLibrary fetching stored images on phone
// ViewController.h
@interface ViewController : UIViewController
@property(nonatomic, strong) NSArray *assets;
@end
//
@protocol NavBarDelegate <NSObject>
@optional
- (void)changeDashboardButton :(NSString*)fromSegue;
@end
@property (nonatomic,strong) id<NavBarDelegate> navbarDelegate;
- (BOOL)validateEmail:(NSString *)emailStr {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:emailStr];
}
@casspangell
casspangell / programming
Last active January 4, 2016 21:19
write a function that prints a rating between zero and four stars. ratings can be half stars (two and a half for example). full stars should be represented by an asterisk (*) and half stars should be represented by a period (.)
(NSString*)ratingFunction(int):rating{
int halfStars = rating - floor(rating);
int fullStars = floor(rating);
NSString *rateString;
while(fullStars > 0){
rateString = [rateString stringByAppendingString:@"*";
fullStars --;
}
- (NSManagedObjectContext *)managedObjectContext {
NSManagedObjectContext *context = nil;
id delegate = [[UIApplication sharedApplication] delegate];
if ([delegate performSelector:@selector(managedObjectContext)]) {
context = [delegate managedObjectContext];
}
return context;
}
//Saving data with Core Data
-(void)saveLocationData:(double)lat :(double)lon :(NSString*)name {
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *locationData = [NSEntityDescription insertNewObjectForEntityForName:@"Location" inManagedObjectContext:context];
[locationData setValue:[NSNumber numberWithDouble:lat] forKey:@"latitude"];
[locationData setValue:[NSNumber numberWithDouble:lon] forKey:@"longitude"];
[locationData setValue:name forKey:@"name"];
NSError *error = nil;
@casspangell
casspangell / shake.m
Created November 19, 2013 18:13
Detect Shake in iOS
- (void)viewDidLoad
{
[super viewDidLoad];
[self becomeFirstResponder]; // set this view as first responder
}
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if(event.type == UIEventSubtypeMotionShake){
NSLog(@"SHAKE");
}
@casspangell
casspangell / dict
Created November 18, 2013 23:16
NSLog NSDictionary
for (id key in dictionaryName) {
// NSLog(@"key: %@ value: %@", key, [dictionaryName objectForKey:key]);
}