Skip to content

Instantly share code, notes, and snippets.

View bryanluby's full-sized avatar

Bryan Luby bryanluby

  • Palatine, IL USA
View GitHub Profile
@bryanluby
bryanluby / CdToXcodeProject.txt
Last active December 25, 2015 10:58
Change Terminal directory to frontmost Xcode project window.
# Works best when an Xcode project is already open.
# Full Terminal command:
cd `osascript -e "tell application \"Xcode\" to get project directory of front project"`; pwd;
# Optional: Add this as an alias to .bash_profile. Then type "xt" in Terminal to invoke the command.
alias xt='cd `osascript -e "tell application \"Xcode\" to get project directory of front project"`; pwd;'
@bryanluby
bryanluby / gist:6615647
Created September 18, 2013 21:01
Objc: Switch with ternary operator
void ConditionalSwitchUsingNumber(int number);
int main(int argc, const char * argv[])
{
@autoreleasepool
{
ConditionalSwitchUsingNumber(0);
ConditionalSwitchUsingNumber(1);
ConditionalSwitchUsingNumber(2);
ConditionalSwitchUsingNumber(6);
@bryanluby
bryanluby / gist:6615506
Last active December 23, 2015 09:38
Objc: Autolayout debugger trace
// Pause app and enter into debugger
// Any ambiguous layouts will be labeled
po [[UIWindow keyWindow] _autolayoutTrace]
@bryanluby
bryanluby / gist:6615420
Last active December 23, 2015 09:38
Objc: Alternate the background color of a UITableViewCell.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row % 2 == 0) {
UIColor *altCellColor = [UIColor colorWithWhite:0.7 alpha:0.1];
cell.backgroundColor = altCellColor;
}
}
@bryanluby
bryanluby / gist:6615028
Last active December 23, 2015 09:29
Objc: Simple code timing block
NSTimeInterval start = [[NSDate date] timeIntervalSince1970];
// Code to execute.
NSTimeInterval finish = [[NSDate date] timeIntervalSince1970];
NSLog(@"Execution took %f seconds.", finish - start);