Skip to content

Instantly share code, notes, and snippets.

@jkhowland
jkhowland / PresentationViewController.m
Created February 12, 2015 09:36
PresentationViewController viewDidLoad
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.dataSource = [PageViewControllerDataSource new];
self.pageViewController.dataSource = self.dataSource;
[self.pageViewController setViewControllers:@[[self.dataSource initialViewController]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
// We need to add the pageViewController as a childViewController (so that the lifecycle methods get called together. And then we can add the main view of the pageViewController to this viewController's main view.
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
@jkhowland
jkhowland / PageViewControllerDataSource.m
Created February 12, 2015 09:18
PageViewControllerDataSource
- (UIViewController *)initialViewController {
ContentViewController *viewController = [ContentViewController new];
viewController.index = 0;
viewController.name = [[ContentController sharedInstance].content[0] description];
return viewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
@jkhowland
jkhowland / TableViewDataSourceMethods
Created January 30, 2015 07:17
OnTheLine-TableViewDataSource
- (IBAction)takePhoto:(id)sender {
self.photoCount++;
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
PhotoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PhotoCell"];
@jkhowland
jkhowland / TakeSaveAccessPhotos
Created January 30, 2015 07:16
OnTheLine-TakeSaveAccessPhotos
- (void)savePhoto:(UIImage *)photo completion:(void (^)(void))completion {
CGSize scaledSize = CGSizeMake(512, 512);
if (photo.size.width > photo.size.height) {
CGFloat ratio = photo.size.height / photo.size.width;
scaledSize.height = round(scaledSize.width * ratio);
} else {
CGFloat ratio = photo.size.width / photo.size.height;
scaledSize.width = round(scaledSize.height * ratio);
@jkhowland
jkhowland / RARecipes.h
Last active August 29, 2015 14:05
RARecipes Model Files
//
// RARecipes.h
// Recipe App
//
// Created by Joshua Howland on 5/22/14.
// Copyright (c) 2014 DevMountain. All rights reserved.
//
#import <Foundation/Foundation.h>
@jkhowland
jkhowland / Data Methods
Last active August 29, 2015 14:05
GitReference - Data Methods - Objective-C
static CGFloat margin = 15;
static NSString * const Command = @"command";
static NSString * const Reference = @"reference";
- (NSArray *)gitCommands {
return @[@{Command: @"git status", Reference: @": shows changed files"},
@{Command: @"git diff", Reference: @": shows actual changes"},
@{Command: @"git add .", Reference: @": adds changed files to the commit"},
@jkhowland
jkhowland / Data Functions
Created August 10, 2014 16:44
GitReference - Data Methods - Swift
func gitCommands() -> Array<[String: String]> {
var commands = [[String: String]]()
commands.append([Command: "git status", Reference: ": shows changed files"])
commands.append([Command: "git diff", Reference: ": shows actual changes"])
commands.append([Command: "git add .", Reference: ": adds changed files to the commit"])
commands.append([Command: "git commit -m \"notes\"", Reference: ": commits the changes"])
commands.append([Command: "git push origin _branch_", Reference: ": pushes commits to branch named _branch_"])
commands.append([Command: "git log", Reference: ": displays progress log"])
@jkhowland
jkhowland / Stack.h
Last active March 31, 2020 13:43
Simple Core Data - Stack.m
//
// Stack.m
//
// Created by Joshua Howland on 6/12/14.
// Copyright (c) 2014 DevMountain. All rights reserved.
//
#import <Foundation/Foundation.h>
@import CoreData;
@jkhowland
jkhowland / gist:715845b34014aa7f54ef
Last active August 29, 2015 14:02
Code to check if tic tac toe game has been won
// See tic tac toe by Lenli https://github.com/lenli/tictactoe
-(BOOL)isGameOver {
NSArray *winCombinations = [[NSArray alloc] initWithObjects: @[@1,@2,@3], @[@4,@5,@6], @[@7,@8,@9],
@[@1,@4,@7], @[@2,@5,@8], @[@3,@6,@9],
@[@1,@5,@9], @[@3,@5,@7], nil];
for (NSArray *winCombination in winCombinations) {
BOOL isWinner = TRUE;
for (NSNumber *winIndex in winCombination) {
- (NSArray *)data {
return @[
[self fruits],
[self liquids],
[self desserts]
];
}