Skip to content

Instantly share code, notes, and snippets.

View ninthspace's full-sized avatar

Chris Aves ninthspace

View GitHub Profile
@ninthspace
ninthspace / init.m
Created April 26, 2012 15:17
Simple UITableViewController initializer
- (id)init {
self = [super initWithStyle:UITableViewStyleGrouped];
return self;
}
@ninthspace
ninthspace / initSVPullToRefresh.m
Created April 26, 2012 15:20
UITableViewController initializer with support for SVPullToRefresh
- (id)init {
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
// add the handler to the UITableView
[[self tableView] addPullToRefreshWithActionHandler:^{
// do something, in this case add a new item to our data source
[self addNewItem:nil];
// tell pull-to-refresh to stop animating
[[[self tableView] pullToRefreshView] stopAnimating];
}];
@ninthspace
ninthspace / CACoreData.h
Created May 11, 2012 15:38
Class for generating singleton Core Data artifacts
//
// CACoreData.h
// Alisto
//
// Created by Chris Aves on 09/05/2012.
// Copyright (c) 2012 Junctionbox Media. All rights reserved.
//
#import <Foundation/Foundation.h>
@ninthspace
ninthspace / MyStoreClass.m
Created May 11, 2012 16:21
Hooking up a NSFetchedResultsController
+ (NSFetchedResultsController *)fetchedResultsController:(id <NSFetchedResultsControllerDelegate>)delegate {
NSManagedObjectContext *context = [CACoreData sharedManagedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"MyModel" inManagedObjectContext:context]];
// must have a sort key
NSSortDescriptor *anySortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"someSortKey" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObjects:anySortDescriptor, nil]];
@ninthspace
ninthspace / SettingsViewController.h
Created May 18, 2012 16:13
SettingsViewController
#import <UIKit/UIKit.h>
@interface SettingsViewController : UITableViewController
typedef enum {
AlistoPrefKeyTypeShowTaskNumbers = 0,
AlistoPrefKeyConfirmDeletion = 1
} AlistoPrefKeyType;
@property (nonatomic, retain) IBOutlet UITableViewCell *showTaskNumbersCell;
@ninthspace
ninthspace / setWithTaskItem.m
Created May 19, 2012 15:57
Setting the content of a UITableViewCell
- (void)setWithTaskItem:(TaskItem *)task {
// set the text which displays the title of the task
NSString *text = [task title];
UILabel *titleLabel = [self taskTitleLabel];
[titleLabel setText:text];
// create a checkbox appropriately set according whether the task is completed or not
NSString *completedString = @"";
@ninthspace
ninthspace / cellForRowAtIndexPath.m
Created May 19, 2012 15:59
Choosing between XIBs
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TaskItem *task = [fetchedResultsController objectAtIndexPath:indexPath];
TaskItemCell *cell;
// check display settings
if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"%d", AlistoPrefKeyTypeShowTaskNumbers]]) {
cell = [tableView dequeueReusableCellWithIdentifier:@"TaskItemCellWithID"];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:@"TaskItemCell"];
@ninthspace
ninthspace / deleteCompletedTasks.m
Created May 19, 2012 16:59
Deleting tasks, with optional confirmation
- (void)deleteCompletedTasksWithConfirmation:(id)sender {
if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"%d", AlistoPrefKeyConfirmDeletion]]) {
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Delete completed tasks?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete tasks" otherButtonTitles:nil];
[sheet showFromToolbar:[[self navigationController] toolbar]];
} else {
[self deleteCompletedTasks];
}
}
@ninthspace
ninthspace / gist:4360267
Last active November 9, 2018 12:03
How I migrated from rbenv to chruby, and kept per-project gems nice and tidy.

Remove rbenv and any rubies, gems etc.:

$ rm -rf ~/.rbenv

Uninstall rbenv if installed via Homebrew

$ brew uninstall rbenv

Remove references to rbenv in ~/.bash_profile etc.

@ninthspace
ninthspace / php.yml
Created May 16, 2020 15:48
Tests and Code Coverage with GitHub Actions
name: Tests
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
tests: