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 / Pixellate.swift
Created January 5, 2015 18:58
Example of pixellating an image picked from a UIImagePickerController
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet weak var imageView: UIImageView!
@IBAction func choosePhoto(sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .SavedPhotosAlbum
presentViewController(picker, animated: true, completion: nil)
}
@ryanmasondavies
ryanmasondavies / AccessControl.swift
Created November 21, 2014 22:22
Swift: UIViewController Access Control
//
// AccessController.swift
// FriendChain
//
// Created by Ryan Davies on 20/11/2014.
// Copyright (c) 2014 Ryan Davies. All rights reserved.
//
import UIKit
@ryanmasondavies
ryanmasondavies / gist:310f61000552a0957827
Created October 10, 2014 12:50
Automate build version from Git
#
# Set the build number to the current git commit count.
# If we're using the Dev scheme, then we'll suffix the build
# number with the current branch name, to make collisions
# far less likely across feature branches.
# Based on: http://w3facility.info/question/how-do-i-force-xcode-to-rebuild-the-info-plist-file-in-my-project-every-time-i-build-the-project/
# Found here: http://blog.jaredsinclair.com/post/97193356620/the-best-of-all-possible-xcode-automated-build
#
git=`sh /etc/profile; which git`
appBuild=`"$git" rev-list --all |wc -l`
@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
@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 / 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 / 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 / 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 / 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 / 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