Skip to content

Instantly share code, notes, and snippets.

View benvium's full-sized avatar

Ben Clayton benvium

  • www.calvium.com
  • Bristol, UK
View GitHub Profile
@benvium
benvium / Realm_Unit_Testing_Podfile
Last active August 29, 2015 14:21
Podfile demonstrating how to set up Realm for XCTest Unit Testing.
# Put then name of your main app's target here.
target 'MainApp' do
pod 'Realm'
pod 'NSDate+Calendar'
pod 'Realm+JSON'
# and any other dependencies
end
# Put the name of the Unit Testing Target here
target 'MainAppTests' do
@benvium
benvium / RealmTestCase.h
Created May 21, 2015 16:34
Inherit from this to automatically create and delete [RLMRealm defaultRealm] files between tests
#import <XCTest/XCTest.h>
// Inherit from this to automatically create and delete [RLMRealm defaultRealm] files between tests
@interface RealmTestCase : XCTestCase
@end
@benvium
benvium / JSONFromBundle.h
Created May 21, 2015 16:32
Simple class to read a json file from the bundle. Works in unit tests or a 'real' app.
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface JSONFromBundle : NSObject
// Also removes nulls
+ (id)nameNoExtension:(NSString *)name;
@end
[
{
"name":"Alice",
"age": 64
},
{
"name":"Bob",
"age": 12
},
{
@benvium
benvium / MyTabBar.m
Created March 5, 2015 11:22
UITabBarController slide animation. Slide left and right when tabs are selected. Based on code from StackOverflow (linked in code)
- (BOOL) tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController {
// http://stackoverflow.com/questions/5161730/iphone-how-to-switch-tabs-with-an-animation
NSUInteger controllerIndex = [self.viewControllers indexOfObject:viewController];
if (controllerIndex == tabBarController.selectedIndex) {
return NO;
}
@benvium
benvium / apk-change-version-number.md
Created February 20, 2015 16:14
How to change the version number on an existing APK without re-building

This requires the latest version of apktool.

apktool d $APK_PATH -o $OUTPUT_FOLDER

# Open the apktool.yml text file
# Alter the versionCode and versionName entries

# now rebuild!
apktool build $OUTPUT_FOLDER 
@benvium
benvium / android-studio-unit-test-setup
Created February 20, 2015 13:25
How to set up Android Studio for Unit Testing. Works in version 1.0 and up.
In Android Studio 1.0 the scheme has changed a little bit.
The path to a unit test source file should be (app)/src/androidTest/java/com/mycompany/myapp/HelloWorldTest.java
Here's how I set up Unit Tests in a new Android Studio project:
- Open app in Android Studio.
- Set the Project explorer (left hand window) to display 'Project' mode. Tap the little drop-down at the top left and select 'Project'.
- Right click the 'src' directory, 'New -> Directory'.
- Call new directory androidTest
@benvium
benvium / NSManagedObject+CALDeleteAll.h
Created February 13, 2015 14:41
Delete all instances of an NSManagedObject from CoreData.
@import CoreData;
#import <Foundation/Foundation.h>
@interface NSManagedObject (CALDeleteAll)
/**
* Deletes all instances of this object from CoreData (may take a while)
*/
+ (void)cal_deleteAll:(NSManagedObjectContext *)context;
@benvium
benvium / NSPointerArray+CALCompact.h
Created February 10, 2015 17:25
NSPointerArray compact method that actually works.
#import <Foundation/Foundation.h>
@interface NSPointerArray (CALCompact)
- (void)cal_compact;
@end
@benvium
benvium / CustomLogFormatter.h
Last active August 29, 2015 14:12
CocoaLumberjack Custom Log Formatter with time, log level, filename, line number, selector and message. The code `DDLogDebug(@"Enabled notification for status characteristic");` will write to the console: `12:19:13:539 V: DeviceConnector.m:101 bt_onConnected: | Enabled notification for status characteristic`
//
// Created by Ben Clayton on 23/12/14.
// Copyright (c) 2014 Calvium Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "DDLog.h"
@interface CustomLogFormatter : NSObject<DDLogFormatter>