Skip to content

Instantly share code, notes, and snippets.

View ryanmasondavies's full-sized avatar

Ryan Mason-Davies ryanmasondavies

  • Marks and Spencer
  • Hampshire, UK
View GitHub Profile
@ryanmasondavies
ryanmasondavies / header_substituter.rb
Created April 12, 2013 12:31
A Ruby script for replacing header files in multiple projects at once.
#!/usr/bin/env ruby
projects = %w[CSV Caboodle Transcript Recipes Mockingbird Bindings WhatsYourFine Typewriter Specify Posit Braille Handsy]
# a regular expression to identify the existing header format
# in this case, I had been using the format from the Xcode file templates
existing_format = /\/\/\n\/\/ .*\n\/\/ .*\n\/\/\n\/\/.*\n\/\/.*\n\/\/\n/
# the new format to replace the old
# in my case, I didn't want to include file names or the project name,
@ryanmasondavies
ryanmasondavies / pods.rb
Created April 21, 2013 10:09
Install pods in multiple projects.
top = Dir.pwd
Dir["**/*/Podfile"].each do |f|
dir = File.dirname(f)
Dir.chdir(dir)
puts "Installing pods for #{dir} ..."
system "pod install --verbose"
Dir.chdir top
end
@ryanmasondavies
ryanmasondavies / prefix_changer.rb
Last active December 21, 2015 22:59
Ruby script to update file prefixes recursively. Useful to quickly change filenames to match a class prefix change in an Xcode project.
#!/usr/bin/env ruby
class String
def starts_with?(prefix)
prefix = prefix.to_s
self[0, prefix.length] == prefix
end
end
old = 'RJD' # old prefix
@ryanmasondavies
ryanmasondavies / svn-revert-all
Last active December 21, 2015 22:59
Remove all changes from `svn status`
svn status --no-ignore | grep -E '(^\?)|(^\I)' | sed -e 's/^. *//' | sed -e 's/\(.*\)/"\1"/' | xargs rm -rf
@ryanmasondavies
ryanmasondavies / svn_prefix_changer.rb
Created August 29, 2013 15:41
Ruby script to update file prefixes recursively when working with a Subversion repository. Useful to quickly change filenames to match a class prefix change in a Subversion Xcode project.
#!/usr/bin/env ruby
class String
def starts_with?(prefix)
prefix = prefix.to_s
self[0, prefix.length] == prefix
end
end
old = 'RJD' # old prefix
@ryanmasondavies
ryanmasondavies / license_changer.rb
Created September 17, 2013 19:54
Substitute license text in all files in a project.
existing_format = /\/\/\n\/\/ .*\n\/\/ .*\n\/\/\n\/\/.*\n\/\/.*\n\/\/\n/
new_format = <<EOF
// The MIT License
//
// Copyright (c) 2013 Ryan Davies
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@ryanmasondavies
ryanmasondavies / MigrateCoreDataStoreType.m
Created December 27, 2013 17:17
Opens up a Core Data store using a custom atomic type and migrates the store to another type. This would be useful for importing data, e.g for opening up a CSV file using a custom type and converting it an SQLite store. However, while this is easy and makes use of in-house components, it introduces more steps than are necessary for importing dat…
// grab the model:
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"StoreMigration" withExtension:@"momd"];
NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
// create a new example store type:
NSPersistentStoreCoordinator *csvCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel];
csvCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel];
if (![csvCoordinator addPersistentStoreWithType:[SMGCSVStore type] configuration:nil URL:csvStoreURL options:nil error:&error]) {
NSLog(@"Couldn't add store: %@", [error localizedDescription]);
abort();
@ryanmasondavies
ryanmasondavies / EiffelTowerRegionMonitoring.m
Last active August 29, 2015 13:57
Using CLLocationManager and CLRegion to detect proximity to the Eiffel Tower
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
[self setLocationManager:locationManager];
// ...
CLLocationCoordinate2D eiffelTowerCoordinates = CLLocationCoordinate2DMake(48.858093, 2.294694);
CLLocationDistance radius = 20; // 20 meters
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:eiffelTowerCoordinates radius:20.0 identifier:@"Eiffel Tower"];
@ryanmasondavies
ryanmasondavies / ViewRendering.m
Last active August 29, 2015 14:00
Code snippet from blog post Snapshotting and Blurring Views in iOS 7
UIGraphicsBeginImageContext(rect.size);
[view drawViewHierarchyInRect:rect afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@ryanmasondavies
ryanmasondavies / BlurView.h
Last active August 29, 2015 14:05
Blurring a UIView in iOS 7+
@import UIKit;
@interface BlurView : UIView
@property (weak, nonatomic) UIView *backgroundView;
@end