This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Written by Corey Haines | |
# Scriptified by Gary Bernhardt | |
# | |
# Put this anywhere on your $PATH (~/bin is recommended). Then git will see it | |
# and you'll be able to do `git churn`. | |
# | |
# Show churn for whole repo: | |
# $ git churn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Source: Apple Developer - Understanding iOS View Compositing | |
*/ | |
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { | |
UIImage *image = [self loadImage]; | |
if (image != nil) { | |
CGSize s = image.size; | |
CGRect r = layer.bounds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
protocol Embedding: class { | |
var embeddedViewController: UIViewController? { get set } | |
} | |
enum EmbeddingAnimation { | |
case none | |
case flipFromLeft | |
case crossDissolve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
If you run loadThumbnail() in an *iPhone-only app that is installed on the iPad*, | |
the Photos framework will callback first with a degraded version of the requested asset image, | |
and then it will callback a second time with a nil image. | |
If you're not careful and you pass the nil image to your UIImageView, then you will never see the thumbnail. | |
The UIImageView will first get set with a proper UIImage, then soon after with a nil UIImage. | |
The solution is to ignore or discard any image that is nil. | |
So what happens if you try to setup PHImageRequestOptions to make sure that Photos framework only calls back once? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Source: Apple Developer - Understanding iOS View Compositing | |
*/ | |
// setup the layer | |
CALayer *layer = view.layer; | |
layer.bounds = sublayer_bounds; | |
layer.backgroundColor = random_color(); | |
// set the shadow properties on the layer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: Stanford CS193P November 16, 2010 Lecture 16 | |
// Use case: lots of Core Data changes. You want them to save once they settle down. | |
- (void)delayedSave:(NSManagedObjectContext *)ctxt | |
{ | |
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doSave:) object:ctxt]; | |
[self performSelector:@selector(doSave:) withObject:ctxt afterDelay:1.0]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: WWDC 2012 Session 216 | |
// Advanced Appearance Customization on iOS | |
// Rather useful when your button is smaller than the golden 44 points | |
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event | |
{ | |
CGFloat widthDelta = 44.0 - bounds.size.width; | |
CGFloat heightDelta = 44.0 - bounds.size.height; | |
CGRect bounds = CGRectInset(self.bounds, -0.5 * widthDelta, -0.5 * heightDelta); | |
return CGRectContainsPoint(bounds, point); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: WWDC 2013 Session 228 | |
CFMutableStringRef string = (__bridgeCFMutableStringRef)[@"Hello!こんにちは!สวสัดี!مرحبا!您好!" mutableCopy]; | |
CFStringTransform(string, NULL, kCFStringTransformToLatin, NO); | |
// Hello! kon'nichiha! swạsdī! mrḥbạ! nín hǎo! | |
CFStringTransform(string, NULL, kCFStringTransformStripCombiningMarks, NO); | |
// Hello! kon'nichiha! swasdi! mrhba! nin hao! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Extract date from natural language string | |
Source: WWDC2012 Session 215 - Text and Linguistic Analysis | |
*/ | |
NSDataDetector *dateDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeDate error:nil]; | |
NSString *dateString = @"13th September 1986 11:59pm"; | |
NSTextCheckingResult *result = [dateDetector firstMatchInString:dateString | |
options:0 | |
range:NSMakeRange(0, [dateString length])]; |