Skip to content

Instantly share code, notes, and snippets.

@jamztang
jamztang / 0_reuse_code.js
Created September 25, 2013 04:37
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jamztang
jamztang / UIImage+Retina4.h
Created September 14, 2012 16:05 — forked from bstahlhood/UIImage+Retina4.h
Swizzled UIImage imageNamed for iPhone 5
//
// UIImage+Retina4.h
// StunOMatic
//
// Created by Benjamin Stahlhood on 9/12/12.
// Copyright (c) 2012 DS Media Labs. All rights reserved.
//
#import <UIKit/UIKit.h>
@jamztang
jamztang / nsincrementalstore.markdown
Created May 9, 2012 04:24 — forked from chriseidhof/nsincrementalstore.markdown
Accessing an API using CoreData's NSIncrementalStore

Accessing an API using CoreData's NSIncrementalStore

Note: the original location of this article is on my blog, however, it is posted here too for better readability.

In this article, we will see how to use Core Data for accessing your API. We will use the Bandcamp API as our running example. I've only been experimenting with this code for a few days, so there might be mistakes in there.

//
// NSObject+PropertyListing.h
// PropertyFun
//
// Created by Andrew Sardone on 8/27/10.
//
#import <Foundation/Foundation.h>
@jamztang
jamztang / UIColorFromHex.m
Created May 7, 2012 14:53 — forked from dstnbrkr/UIColorFromRGB
Convert hex value to UIColor
UIColor* UIColorFromHex(NSInteger colorInHex) {
// colorInHex should be value like 0xFFFFFF
return [UIColor colorWithRed:((float) ((colorInHex & 0xFF0000) >> 16)) / 0xFF
green:((float) ((colorInHex & 0xFF00) >> 8)) / 0xFF
blue:((float) (colorInHex & 0xFF)) / 0xFF
alpha:1.0];
}
@jamztang
jamztang / gist:2587002
Created May 3, 2012 16:28 — forked from lxcid/gist:2586763
Based on https://gist.github.com/2215212, a method helper to unit test AFNetworking operations in SenTestingKit.
// Call theResume() to stop the semaphore from blocking/waiting.
// Failure to call theResume() will cause the test to hang.
// This is needed to test asynchronous operations. See https://gist.github.com/2215212
- (void)dispatchSemaphoreInBlock:(void (^)(void (^theResume)(void)))theBlock {
dispatch_semaphore_t theSemaphore = dispatch_semaphore_create(0);
theBlock(^{ dispatch_semaphore_signal(theSemaphore); });
while (dispatch_semaphore_wait(theSemaphore, DISPATCH_TIME_NOW)) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
}
dispatch_release(theSemaphore);
@jamztang
jamztang / api_spec.json
Created November 3, 2011 17:00 — forked from pinglamb/api_spec.json
damn-api sample spec
{
"host": ["api.example.com", "api-staging.example.com"],
"headers": {
"X-EXAMPLE-DEVICE-TYPE": ["iphone", "android"],
"X-EXAMPLE-DEVICE-UUID": {
"value": "mock",
"optional": true
},
"X-EXAMPLE-APP-ID": ["com.example.iphone.app1", "com.example.iphone.app2", "com.example.android.app1"]
},