Skip to content

Instantly share code, notes, and snippets.

range: {0, 0}
newString: [ㅅ]
original newCharCount: 1
new newCharCount: 1
count: 1 graphemeCount: 1
range: {1, 0}
newString: [ㅅㅅ]
original newCharCount: 2
new newCharCount: 2
count: 1 graphemeCount: 1
@mlaster
mlaster / gist:3896122
Created October 15, 2012 22:39
Korean-aware character length limiting
- (void)textViewDidChange:(UITextView *)inTextView {
NSUInteger count = [[self text] length];
__weak __typeof__(self) blockSelf = self;
if (count > self.characterLimit) {
NSMutableString *newString = [NSMutableString string];
__block NSUInteger blockCount = 0;
[inTextView.text enumerateSubstringsInRange:NSMakeRange(0, [inTextView.text length])
options:NSStringEnumerationByComposedCharacterSequences
#import "CustomAnnotationView.h"
#import <QuartzCore/QuartzCore.h>
@interface CustomAnnotationView()
- (CAAnimation *)rotationAnimation;
- (CAAnimation *)scaleAnimation;
@end
- (CLLocationCoordinate2D)locationFromLocation:(CLLocationCoordinate2D)initialLocation course:(CLLocationDirection)course distance:(CLLocationDistance)distance {
CLLocationCoordinate2D retValue = initialLocation;
static const CLLocationDistance EarthRadius = 6371000; // avg radius of the Earth in meters
CLLocationDegrees newLat = 0.0;
CLLocationDegrees newLong = 0.0;
newLat = asin(sin(initialLocation.latitude * M_PI/180.0) * cos(distance/EarthRadius) +
cos(initialLocation.latitude * M_PI/180.0) * sin(distance/EarthRadius) * cos(course * M_PI/180.0) );
newLong = initialLocation.longitude * M_PI/180.0 + atan2(sin(course * M_PI/180.0) * sin(distance/EarthRadius) * cos(initialLocation.latitude * M_PI/180.0),
- (void)viewDidLoad {
ChildViewController *cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ChildViewController"];
[super viewDidLoad];
[self addChildViewController:cvc];
cvc.view.frame = self.containerView.bounds;
[self.containerView addSubview:cvc.view];
[cvc didMoveToParentViewController:self];
}
@mlaster
mlaster / gist:6405290
Created September 1, 2013 15:46
- (void)testWeak { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-repeated-use-of-weak" NSString *strong = @"foo"; __weak NSString *weak = strong; NSLog(@"weak: %@", weak); strong = nil; NSLog(@"weak: %@", weak); #pragma clang diagnostic pop }
- (void)testWeak {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-repeated-use-of-weak"
NSString *strong = @"foo";
__weak NSString *weak = strong;
NSLog(@"weak: %@", weak);
strong = nil;
NSLog(@"weak: %@", weak);
#pragma clang diagnostic pop
@mlaster
mlaster / gist:7240660
Last active December 27, 2015 00:49
.gitignore
*
!.gitignore
!Sample.xcworkspace
let mainBundle = NSBundle.mainBundle()
let bundle = mainBundle.pathForResource("Bundle", ofType: "bundle", inDirectory: "PlugIns")
println("mainBundle: \(mainBundle)")
println("bundle: \(bundle)")
/Products/Debug/MainApp.app> find .
.
./Contents
./Contents/Frameworks
./Contents/Frameworks/Framework.framework
./Contents/Frameworks/Framework.framework/Framework
./Contents/Frameworks/Framework.framework/Headers
./Contents/Frameworks/Framework.framework/Modules
./Contents/Frameworks/Framework.framework/Resources
./Contents/Frameworks/Framework.framework/Versions
// Playground - noun: a place where people can play
struct MySet<T: Hashable> : DebugPrintable {
var store: Dictionary<T,Void>
init() {
store = [:]
}