Skip to content

Instantly share code, notes, and snippets.

View lawrencelomax's full-sized avatar

Lawrence Lomax lawrencelomax

View GitHub Profile
@lawrencelomax
lawrencelomax / gist:1670617
Created January 24, 2012 15:09
Simple progressive image loading
UIView * view = [[UIView alloc] initWithFrame:CGRectMake( 0.0f, 0.0f, kAffirmationThumbnailWidth, kAffirmationThumbnailHeight )];
view.backgroundColor = [UIColor grayColor];
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kAffirmationThumbnailWidth, kAffirmationThumbnailHeight)];
imageView.backgroundColor = [UIColor clearColor];
imageView.alpha = 1.0;
[view addSubview:imageView];
// Background getting of small image and loading into memory
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
NSString * imagePathSmall = [NSString stringWithFormat:@"%@_small.jpg",[[affirmation imagePath] stringByDeletingPathExtension]];
@lawrencelomax
lawrencelomax / gist:4617449
Last active December 11, 2015 14:58
Variadic Macros for Pushing and Popping GL State
extern void bilContext_glClientState(dispatch_block_t contextBlock, GLenum clientState, ... )
{
va_list arguments;
GLenum value;
va_start(arguments, clientState);
for (value = clientState; value > 0; value = va_arg(arguments, GLenum))
{
glEnableClientState(value);
}
@lawrencelomax
lawrencelomax / gist:4704470
Last active December 12, 2015 03:08
Enumeration of NULL terminated Varargs
#define ENUMERATE_NULL_TERMINATED_VARARGS(firstArgument, type, argumentName, operation) \
{ \
va_list arguments; \
va_start(arguments, firstArgument); \
type argumentName = firstArgument; \
while (argumentName) \
{ \
{ \
operation \
} \
@lawrencelomax
lawrencelomax / gist:4711119
Last active December 12, 2015 03:58
ARC Retain/Release overhead in tight loops
/**
An inline (read: no overhead) function that will perform the physics increment for a given particle
@return A boolean for whether the particle has expired and needs to be removed
*/
extern inline BOOL updateParticle(BILParticleAtomConventional * atom, BILParticleModel * model, NSTimeInterval deltaTime)
{
// Time to Live
atom->atom.timeToLive -= deltaTime;
#define recursiveBlock(type_out__, name__, type_in__, block__) \
typedef type_out__ (^type_in_out__##name__)type_in__;\
__weak __block type_in_out__##name__ name__;\
type_in_out__##name__ temp__##name__;\
name__ = temp__##name__ = ^type_out__(type_in__) block__
Pod::Spec.new do |s|
s.name = "ReactiveCocoa"
s.version = "2.0.0-RC3"
s.summary = "A framework for composing and transforming sequences of values."
s.homepage = "https://github.com/blog/1107-reactivecocoa-is-now-open-source"
s.author = { "Josh Abernathy" => "josh@github.com" }
s.source = { :git => "https://github.com/ReactiveCocoa/ReactiveCocoa.git", :tag => 'v2.0-RC3' }
s.license = 'Simplified BSD License'
s.description = "ReactiveCocoa offers:\n" \
"1. The ability to compose operations on future data.\n" \
@lawrencelomax
lawrencelomax / cat_list.json
Last active December 24, 2015 11:28
JSON Sample data for Unit Test demo
[
{"name" : "grumpy", "image_url" : "http://i.imgur.com/llerBCQ.jpg"},
{"name" : "long", "image_url" : "http://i.imgur.com/SkSNqfB.jpg"},
{"name" : "bullet", "image_url" : "http://i.imgur.com/djCifni.jpg"},
{"name" : "ceiling", "image_url" : "http://i.imgur.com/W86UhUT.png"}
]
@lawrencelomax
lawrencelomax / rac_testing.md
Created April 30, 2014 15:38
RAC Testing abortive blogpost

layout: post title: "ReactiveCocoa Unit Testing Tips" date: 2013-09-22 20:45 comments: true categories:

  • Testing
  • iOS
  • Patterns
  • Xcode
@lawrencelomax
lawrencelomax / scanner.swift
Created July 10, 2014 16:47
Word Scanner in Swift
// Playground - noun: a place where people can play
import Cocoa
let str = "Foo Bar bannana' basa fist ada-2@🚅 afa2-ff 👍🎭-asd👍 adsa😃da\ndas🎉d"
let whitespaceSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
enum ScanResult<T> {
case Append(T)
@lawrencelomax
lawrencelomax / gist:00ea2c00c9b6ca5bb4ab
Created September 5, 2014 11:30
Return Early vs Nested Imperative Parsing in Swift
static func decodeImperative<X: XMLParsableType>(xml: X) -> Result<Animal> {
if let type = XMLParser.parseChildText("type")(xml: xml).toOptional() {
if let name = XMLParser.parseChildText("name")(xml: xml).toOptional() {
if let urlString = XMLParser.parseChildText("url")(xml: xml).toOptional() {
return Result.value(self(type: type, name: name, url: NSURL.URLWithString(urlString)) )
}
return Result.Error(decodeError("Could not parse 'urlString' as a String"))
}
return Result.Error(decodeError("Could not parse 'name' as a String"))
}