Skip to content

Instantly share code, notes, and snippets.

@boredzo
boredzo / gist:1363410
Created November 14, 2011 06:57
New CPU Usage object cache mechanism
New CPU Usage cache
Currently: Parallel C arrays of Cocoa text system objects, colors, etc.
drawRect: looks up the objects it needs in those arrays, indexed by the CPU usage percentage, and creates and caches whatever it doesn't already have.
Problem: drawRect: has a slow path where the cache does not contain the needed objects yet, so it must create them. Even the check itself slows down every pass through drawRect:.
Solution: A single array containing blocks.
Initially, this would be filled with all the same block, each of which creates the needed objects, creates a block that captures those objects and does the drawing, and replaces itself in the cache with the new block.
drawRect: simply calls the appropriate block in the array, unconditionally. The slow-path block will move itself out of the way when it's no longer needed.
#import <Foundation/Foundation.h>
@interface Foo: NSObject
- (void) takeBool:(BOOL)yorn;
- (void) takeDouble:(double)d;
@end
int main(int argc, char **argv) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@boredzo
boredzo / gist:1572986
Created January 6, 2012 23:30
Initialization code
@interface AutoScrollView ()
- (id) commonInit __attribute__((objc_method_family(init)));
@property(nonatomic, assign, getter=isAutoScrolling) BOOL autoScrolling;
@property(nonatomic, retain) NSTimer *autoScrollTimer, *delayedStartScrollingTimer;
@property(nonatomic, retain) UIGestureRecognizer *tapRecognizer;
@end
@boredzo
boredzo / gist:1696100
Created January 28, 2012 22:57
Creating font(s) from a URL
//Core Graphics method
CGDataProviderRef provider = CGDataProviderCreateWithURL((__bridge CFURLRef)fontURL);
CGFontRef graphicsFont = CGFontCreateWithDataProvider(provider);
CTFontRef coreTextFont = CTFontCreateWithGraphicsFont(graphicsFont, fontSize, /*matrix*/ NULL, /*attributes*/ NULL);
if (coreTextFont) {
NSFont *font = (__bridge NSFont *)coreTextFont;
[fonts addObject:font];
CFRelease(coreTextFont);
}
CGFontRelease(graphicsFont);
@boredzo
boredzo / gist:1934476
Created February 28, 2012 19:15
Boom
#import <Foundation/Foundation.h>
static NSString *getString(void);
int main(int argc, char **argv) {
@autoreleasepool {
NSLog(@"%@", getString());
}
return EXIT_SUCCESS;
}
@boredzo
boredzo / SSEnumeratorWithBlocks.m
Created March 17, 2012 06:57
Blocks for NSEnumerator
// Copyright (c) 2012 Colin Barrett, Springs & Struts <colin@springsandstruts.com>
// Released under the MIT license. http://www.opensource.org/licenses/mit-license.html
#import <Foundation/Foundation.h>
@interface NSEnumerator (SSEnumeratorWithBlocks)
- (void)ss_enumerateObjectsUsingBlock:(void (^)(id obj, BOOL *stop))enumBlock;
@end
@implementation NSEnumerator (SSEnumeratorWithBlocks)
@boredzo
boredzo / Makefile
Created April 20, 2012 02:04
dispatch_once is not reentrant
CC=clang
CFLAGS+=-std=c99 -g
LDFLAGS+=-framework Foundation
dispatch_once_reentrancy_test: dispatch_once_reentrancy_test.o
@boredzo
boredzo / PRH2Vector.h
Created April 22, 2012 21:34
Hypothetical 2-vector class
#import <Foundation/Foundation.h>
#if TARGET_OS_IPHONE
# import <UIKit/UIKit.h>
#else
# import <AppKit/AppKit.h>
#endif
@interface PRH2Vector: NSObject
@property(readonly) CGPoint pointValue;
@boredzo
boredzo / cmpcs.m
Created July 22, 2012 19:25
Comparing character sets
#import <Foundation/Foundation.h>
int main(int argc, char **argv) {
@autoreleasepool {
NSCharacterSet *charactersInWord = [NSCharacterSet characterSetWithCharactersInString:@"secretagogue"];
NSMutableCharacterSet *guessedCharacters = [NSMutableCharacterSet characterSetWithCharactersInString:@""];
[guessedCharacters addCharactersInString:@"s"];
[guessedCharacters addCharactersInString:@"e"];
[guessedCharacters addCharactersInString:@"c"];
[guessedCharacters addCharactersInString:@"r"];
@boredzo
boredzo / gist:3224675
Created August 1, 2012 07:40 — forked from scottburton11/gist:3222152
Audio Compression for Voiceover

About compression

Audio compression is used to reduce the dynamic range of a recording. Dynamic range is the difference between the loudest and softest parts of an audio signal. It was originally used to guard against defects when cutting wax and vinyl phonograph records, but generally became useful as a way of increasing the loudness of an audio recording without achieving distortion.

The goal of most compression applications is to increase the amplitude of the softest parts of a recording, without increasing the amplitude of the loudest parts.

Compressor anatomy

Compressors generally all have the same conceptual parts. However, not all compressors present variable controls for all parts to the user. If you don't see all of your compressor's controls here, there's a chance it either has a fixed value (and no control), or is named something else: