Skip to content

Instantly share code, notes, and snippets.

@ygit
ygit / Count lines of code in Xcode project
Created December 7, 2015 07:42 — forked from ccabanero/Count lines of code in Xcode project
Count lines of code in Xcode project
1. Open Terminal
2. cd to your Xcode project
3. Execute the following when inside your target project:
find . -name "*.[hm]" -print0 | xargs -0 wc -l
@ygit
ygit / Semaphore
Created December 18, 2015 10:50
Wait for an async block to complete with semaphores
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
[context performBlock:^{
//block operations
dispatch_group_leave(group);
}];
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
- (void)solution{
NSArray *list = @[@"end", @"back", @"and", @"the", @"po", @"pu", @"lar", @"face"]; //populate with any list of strings here
NSString *inputStr = @"facebackandthethethefacebackpopularlarpopu"; //or input any string here
BOOL canBeFormed = [self checkForString:inputStr.mutableCopy inList:list];
if (canBeFormed) {
NSLog(@"YES! %@ can be formed from the list.", inputStr);
NSString *fileURL = @"https://s3-ap-southeast-1.amazonaws.com/haptikdev/test/Conversation.txt";
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
delegate:self
delegateQueue:nil];
NSURLSessionDownloadTask *getFile = [session downloadTaskWithURL:[NSURL URLWithString:fileURL]
completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSError *extractErr = nil;
defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
@ygit
ygit / README-Template.md
Created March 29, 2017 09:37 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@ygit
ygit / Delete Multiple Remotes
Created December 1, 2017 07:12
Delete multiple remote branches in git
git branch -r | awk -F/ '/\/PREFIX/{print $2}'
git branch -r | awk -F/ '/\/PREFIX/{print $2}' | xargs -I {} git push origin :{}
@ygit
ygit / Persistent Store Migration
Last active March 19, 2018 10:30
Core Data Persistent Store Migration
// for custom overwrites within an entity like changing an attribute from Boolean to NSNumber, etc
- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance
entityMapping:(NSEntityMapping *)mapping
manager:(NSMigrationManager *)manager
error:(NSError **)error {
NSManagedObject *newObject =
[NSEntityDescription insertNewObjectForEntityForName:[mapping destinationEntityName]
inManagedObjectContext:[manager destinationContext]];
// do transfer of nsdate to nsstring non-lightweight operations here
@ygit
ygit / OnlyIphoneArchsFrameworkScript
Created October 26, 2018 13:22
Build only iPhone device archs(excluding simulator) framework using lipo
######################
# Options
######################
set -x
set -e
REVEAL_ARCHIVE_IN_FINDER=false
FRAMEWORK_NAME="${PROJECT_NAME}"
@ygit
ygit / RandomInt.swift
Created April 4, 2019 15:24
Random Int Generator Swift Extension
extension Int {
var arc4random: Int {
if self > 0 {
return Int(arc4random_uniform(UInt32(self)))
} else if self < 0 {
return -Int(arc4random_uniform(UInt32(abs(self))))
} else {
return 0
}
}