Skip to content

Instantly share code, notes, and snippets.

View kyleturner's full-sized avatar

Kyle Turner kyleturner

View GitHub Profile
@kyleturner
kyleturner / Copy File to User Documents using Bundle
Created January 22, 2019 02:47
#ios #swift #files #bundle
public func copyFileToUserDocuments(forResource name: String,
ofType ext: String,
bundle: Bundle? = nil) throws {
let bundle = bundle ?? Bundle.main
guard
let bundlePath = bundle.path(forResource: name, ofType: ext),
let destPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,
.userDomainMask,
true).first else { return }
let fileName = "\(name).\(ext)"
@kyleturner
kyleturner / adjust-constraints.m
Last active August 29, 2015 14:06
Beam iOS Collection View Constraints Animation Adjustments
- (void)adjustConstraintsAndApplyAnimationsForCell:(NGContactCollectionViewCell *)cell
{
CGFloat imageWidth = 104.0;
CGFloat imageHeight = 104.0;
CGFloat defaultActionImageHeight = (self.editing) ? 18.0 : 27.0;
CGFloat nameLabelXOffset = (self.editing) ? 5.0 : 4.0;
CGFloat nameFontSize = (self.editing) ? 12.0 : 16.0;
BOOL contactHasImage = cell.contact.hasContactImage;
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]];
from django.forms.models import model_to_dict
model_to_dict(intance, fields=[], exclude=[])
@kyleturner
kyleturner / iOS Free HD Space
Created February 8, 2012 19:22
Find the amount of free space on hard drive
NSDictionary* fileAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/"
error:&error];
unsigned long long freeSpace = [[fileAttributes objectForKey:NSFileSystemFreeSize] longLongValue];
NSLog(@"free disk space: %dGB", (int)(freeSpace / 1073741824));
@kyleturner
kyleturner / iOS Text View Enter Return
Created February 1, 2012 05:36
TextView dismisses when enter key is pressed
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
@kyleturner
kyleturner / git new master branch
Created February 1, 2012 03:59
Override the default master branch, and take our "new" master branch as new default
git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks
@kyleturner
kyleturner / 1-RedLight.m
Created January 28, 2012 05:20
When app launches, creating red light imageView, and setting up layout
// The application launches. Then...
// This creates the red light view, sets its initial opacity to 75%, and adds to window.
_redLightView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"RedLight"]] autorelease];
_redLightView.layer.opacity = 0.75;
_redLightView.frame = CGRectMake(0, 170, 235, 417);
_redLightView.backgroundColor = [UIColor clearColor];
[self.window addSubview:_redLightView];
@kyleturner
kyleturner / CoreAnimationExample.m
Created January 13, 2012 04:55
360 Degree Rotation Animation
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 6;
fullRotation.repeatCount = 1e100f;
[myview.layer addAnimation:fullRotation forKey:@"360"];
@kyleturner
kyleturner / Table View Border.m
Created January 10, 2012 01:34
Adding a border around your entire table view - could be good for sectioned tables
[[self.tableView layer] setCornerRadius:10];
[self.tableView setClipsToBounds:YES];
[[self.tableView layer] setBorderColor:
[[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor]];
[[self.tableView layer] setBorderWidth:2.75];