Skip to content

Instantly share code, notes, and snippets.

View irace's full-sized avatar

Bryan Irace irace

View GitHub Profile
@irace
irace / ObjectToJSON.java
Last active January 12, 2019 08:16
Object-to-JSON string in Java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ObjectToJSON {
public static void main(String[] args) {
Map<Object, Object> birthday = new HashMap<Object, Object>();
birthday.put("day", 12);
birthday.put("month", 8);
@irace
irace / gist:4392713
Last active December 10, 2015 06:08
Asynchronous iOS unit testing
@interface BIAsynchronousTests()
@property (nonatomic, assign) BOOL receivedAsynchronousCallback;
@end
@implementation BIAsynchronousTests
- (void)testSomething {
[self performAsynchronousTest:^{
@irace
irace / xcodechat.css
Last active December 12, 2015 01:28 — forked from jstn/JSTN.css
/*
JSTN THEME FOR LIMECHAT 1.0
put this and the other thing in ~/Library/Application Support/LimeChat/Themes/
bg 1a2230
hlight 273146
red e44347
purps 8b84d0
fuscia c2339a
@irace
irace / gist:5035442
Last active December 14, 2015 05:29
Overloading Objective-C methods
// Duplicate method definition = won't compile
- (void)each:(void(^)(id))block;
- (void)each:(void(^)(id, int))block;
@irace
irace / gist:5216137
Last active December 15, 2015 06:28
Core Data migrations are hard. If you don't need to migrate, then don't! Here's how:
/*
Core Data is great but automatic migrations can be tricky. Migrations can take a long time, which could
result in [your app being terminated](http://stackoverflow.com/questions/13333289/core-data-timeout-adding-persistent-store-on-application-launch)
if it is happening on the main thread during application launch. Performing migrations on a background
thread is also a [bad idea](http://stackoverflow.com/a/2866725/503916), meaning your application really
needs to be able to fully launch *without a Core Data stack whatsoever* in order to safely migrate.
This can be a huge change to make to an existing app.
If you're really only using Core Data as a cache, you don't actually *need* to perform a migration.
Simply check if the existing store is compatible with your managed object model and if so, delete
@irace
irace / gist:5242906
Created March 26, 2013 03:31
Xcode testing
16:51 [jc] this article: http://www.raingrove.com/2012/03/28/running-ocunit-and-specta-tests-from-command-line.html
16:51 [jc] plus the changes I just pushed
16:51 [jc] together will bring you glory
16:51 [jc] when running
16:51 [jc] xcodebuild -workspace TMTumblrSDK.xcworkspace -scheme TMTumblrSDKTests -sdk iphonesimulator TEST_AFTER_BUILD=YES clean build
@interface UntoggleableSwitch : UISwitch
@end
@irace
irace / gist:5452693
Last active December 16, 2015 14:59
Convert exported TestFlight contact info to Hockey import format
#!/usr/bin/python
import sys
filename = sys.argv[1]
f1 = open(filename)
f2 = open(filename + '.hockey', 'w')
for line in f1:
@irace
irace / gist:5799708
Last active December 18, 2015 14:49
Ensure you're not touching a fault that can't be fulfilled
NSArray *objects = [context executeFetchRequest:fetch error:nil];
for (NSManagedObject *object in objects) {
// Object is a fault, will crash if deleted elsewhere and subsequently tries to fulfill
object = [context existingObjectWithID:object.objectID error:nil];
// Object will either be nil or fully in memory, safe to access properties
}
@irace
irace / gist:7453476
Last active December 28, 2015 05:59
I've tried lots of different Hacker News apps, but haven't found one that I really like just yet. I'm considering making one of my own but would prefer not to since Ashish Gandhi's [Simple Hacker News](https://itunes.apple.com/us/app/simple-hacker-news-simple/id563736471?mt=8) is nice and clean, though still not exactly what I'm looking for. I o…

(Obviously these are just my subjective opinions)

  • Open the front page by default: every single time I open Simple Hacker News, I want to view the front page. I've never once tapped any of the other menu items, yet I still land on the menu whenever the app first loads. I'm guessing that even users that do select the other menu items still choose the front page an overwhelming percentage of the time. As such, I think the front page should be the application's root view controller and the menu should be accessible modally via a left bar button.

  • The blue unread dot is overwhelming/distracting: Since Hacker News covers a wide range of topics, I don't think very many users expect to read all or most of the links that make the front page. As such, I think the unread indicator should be much more subtle. Instead of a blue dot, I think that stories should look the same way that they currently do by default, but the alpha of the table cell could be dropped a bit once a story has already been read. Thi