Skip to content

Instantly share code, notes, and snippets.

View OneSadCookie's full-sized avatar

Keith Bauer OneSadCookie

View GitHub Profile
@OneSadCookie
OneSadCookie / usingchoosesdk.mk
Created September 30, 2011 04:34
how to use choosesdk.rb in make
THIN_EXES := $(patsubst %,build/%/$(APP),$(ARCHS))
build/%/$(APP): $(SOURCES) Makefile Arch.mk
./choosesdk.rb --arch=$* --min-os=10.6 --run="$(MAKE) -f Arch.mk $@ ARCH=$*"
$(EXE): $(THIN_EXES) Makefile
mkdir -p $(@D)
lipo $(THIN_EXES) -create -output $@
@implementation EWWordLayout
- (CGSize)preferredSizeOfLayer:(CALayer *)layer
{
size_t layerCount = [[layer sublayers] count];
CGFloat totalWidth = layerCount * TILE_WIDTH + (layerCount - 1) * INTERTILE_GAP;
return CGSizeMake(totalWidth, TILE_HEIGHT);
}
- (void)invalidateLayoutOfLayer:(CALayer *)layer
OneSadMBP13:Desktop keith$ cat > test.c
#include <stdio.h>
typedef struct { short a; } S;
typedef struct { char a[2]; } T;
main(){
printf("short: %zu bytes; aligned to %zu\n", sizeof(S), __alignof__(S));
printf("char[2]: %zu bytes; aligned to %zu\n", sizeof(T), __alignof__(T));
return 0;
}
OneSadMBP13:Desktop keith$ gcc test.c
- (void)setSeekTime:(int)inSeconds frame:(int)inFrame {
if (self.videoTrack) {
float fps = [self.videoTrack nominalFrameRate];
[self.playerItem seekToTime:CMTimeMake(inSeconds + inFrame / fps, 1)];
// or: [self.playerItem seekToTime:CMTimeMake(inSeconds * fps + inFrame, fps)];
} else {
[self.playerItem seekToTime:CMTimeMakeWithSeconds(inSeconds, 1)];
}
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:_vValue forKey:@"vValue"];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (!self) return nil;
void foo()
{
printf("foo\n");
#if !defined(COMBINE_FOO_AND_BAR)
}
void bar()
{
#endif
printf("bar\n");
@OneSadCookie
OneSadCookie / foo.h
Created January 3, 2012 21:34
preproc-fu
#define cat(x, y) x##y
#define A B
#define C(Foo) cat(Foo, Bar)
C(A)
@OneSadCookie
OneSadCookie / foo.m
Created January 15, 2012 19:35
closure example
- (void)check:(NSEvent *)event onCard:(void (^)(SMCardID, CGPoint))cardHandler onPile:(void (^)(SMPile, CGPoint))pileHandler
{
CGPoint where = [event locationInWindow];
[[self openGLContext] makeCurrentContext];
glBindBuffer(GL_PIXEL_PACK_BUFFER, _pbo);
uint32_t const *pickData = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
uint32_t pixel = pickData[(size_t)where.x + 1024 * (size_t)where.y];
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
@OneSadCookie
OneSadCookie / run.sh
Created January 23, 2012 23:11
arc block bug
clang -fobjc-arc -O2 -c -arch x86_64 test.m
otool -toV test.o | mate
$ clang -fobjc-arc -O2 -arch x86_64 test.m -framework Foundation
$ ./a.out b: 0x104011710
Segmentation fault: 11