Skip to content

Instantly share code, notes, and snippets.

@CodaFi
CodaFi / TUIRefreshControl.m
Created September 26, 2012 00:47
TUIRefreshControl Refreshed
#import "TUIRefreshControl.h"
#import "TUIActivityIndicatorView.h"
#import "TUICGAdditions.h"
#import "NSColor+TUIExtensions.h"
static CGFloat const TUIRefreshTotalHeight = 350;
static CGFloat const TUIRefreshMinTopPadding = 9;
static CGFloat const TUIRefreshMaxTopPadding = 5;
static CGFloat const TUIRefreshMinTopRadius = 12.5;
static CGFloat const TUIRefreshMaxTopRadius = 16;
@CodaFi
CodaFi / gist:3880173
Created October 12, 2012 16:43
TUIScrollView+CVDisplayLink
@interface TUIScrollView : TUIView
{
CGPoint _unroundedContentOffset;
CGSize _contentSize;
CGSize resizeKnobSize;
TUIEdgeInsets _contentInset;
__unsafe_unretained id _delegate;
TUIScrollKnob * _verticalScrollKnob;
@CodaFi
CodaFi / CFIAlternatingTableView.m
Last active December 16, 2016 07:29
Used in conjunction with a Cell-Based NSTableView to draw an iTunes-11 Style table view rows, along with fake rows on the top and bottom of the Table View. The clip view mentioned in the implementation does no actual drawing, and can be eliminated in favor of another arbitrary clip view or removed entirely. This gist uses the clip view swapping …
//
// CFIAlternatingTableView.m
//
// Created by Robert Widmann on 1/6/13.
// Copyright (c) 2015 CodaFi. All rights reserved.
//
#import "CFIAlternatingTableView.h"
#import "CFIAlternatingClipView.h"
- (NSData*)dataBySnappyCompression {
size_t compressedLen = snappy_max_compressed_length(self.length);
NSMutableData *result = [NSMutableData dataWithLength:(snappy_max_compressed_length(compressedLen + 0x4))];
snappy_status opCode = snappy_compress([self bytes], [self length], [result mutableBytes], &compressedLen);
if (opCode != SNAPPY_OK) {
LEPLog(@"Failed snappy compress: tried to compress %lu bytes", result.length);
NSAssert(nil, @"Failed Snappy compress");
result = nil;
} else {
[result setLength:compressedLen + 4];
@CodaFi
CodaFi / NSIndexPath+CFIAdditions
Created February 17, 2013 07:39
Create NSIndexPaths the easy way.
@interface NSIndexPath (CFIAdditions)
#ifdef TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED <= 60000
+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section;
#endif
@end
@implementation NSIndexPath (CFIAdditions)
@CodaFi
CodaFi / Accelerando
Last active December 14, 2015 17:38
ACCELERATE(x) _mm_set1_ps((float)&x)
DECCELERATE_INTO(x, f) _mm_store_ss(&f, result)
Sample usage:
//accelerate a float into a super-fast 128 mm register
float x = 1.0f;
__m128 vecX = ACCELERATE(x);
//deccelerate a 128 mm register value back to a float
@CodaFi
CodaFi / DMArrayDivide
Last active December 15, 2015 04:19
Divide an array of Obj-C objects into an arbitrary amount of smaller arrays.
void DMArrayDivide(NSArray **slices, NSArray *inArray, NSUInteger parts) {
if (parts == 0 || parts == 1) {
*slices = inArray;
return;
}
NSMutableArray *arrays = [NSMutableArray arrayWithCapacity:parts];
for (int i = 0; i < parts; i++) {
arrays[i] = @[].mutableCopy;
}
long int idx = 0;
//
// NSArray+CFIWhere.h
// CFIArrayController
//
// Created by Robert Widmann on 4/9/13.
// Copyright (c) 2013 CodaFi. All rights reserved.
//
#import <Foundation/Foundation.h>
@CodaFi
CodaFi / CFIUniqueInstanceCheck.m
Last active December 17, 2015 16:38
Check for multiple instances of a Cocoa Application. it is recommended that this be checked for in `applicationWillFinishLaunching:`.
static NSMachPort *existancePort = nil;
/**
* Used by the CFICheckForOtherRunningInstancesOfCurrentApplication() function to
* create a unique NSMachPort object. This string *CANNOT CHANGE* in the future,
* otherwise conflicting versions of an App will run on the same machine and
* defeat the purpose of this function.
*/
static NSString *const CFIPortNameConstant = @"SomeNon-ArbitraryPortName";
void DMIndexSetDivide(NSArray **slices, NSIndexSet *inIndexSet, NSUInteger parts) {
if (parts == 0 || parts == 1) {
*slices = [NSArray arrayWithObject:inIndexSet];
return;
}
NSMutableArray *indexSets = [NSMutableArray arrayWithCapacity:parts];
for (int i = 0; i < parts; i++) {
indexSets[i] = [NSMutableIndexSet indexSet];
}