Skip to content

Instantly share code, notes, and snippets.

View odrobnik's full-sized avatar

Oliver Drobnik odrobnik

View GitHub Profile
@odrobnik
odrobnik / gist:5712761
Created June 5, 2013 09:34
Which to prefer?
- (CGSize)sizeThatFits:(CGSize)size
{
CGSize neededSize = [self intrinsicContentSize]; // creates layout frame if necessary
if (neededSize.width>=0 && neededSize.height>=0)
{
return neededSize;
}
// 1
@odrobnik
odrobnik / gist:5705353
Last active December 18, 2015 01:39
BOOL test
// test if there is a byte trunction happening
for (int i=0; i<32; i++)
{
__unsafe_unretained id pointer = (__bridge id)(void *)(1<<i);
NSUInteger v = (int)pointer;
if (pointer)
{
@odrobnik
odrobnik / DTWeakSupport.h
Created June 3, 2013 09:54
using weak where possible ...
#import <Availability.h>
#if __has_feature(objc_arc_weak)
#define DT_WEAK_IVAR_IF_SUPPORTED __weak
#define DT_WEAK_PROPERTY_IF_SUPPORTED weak
#elif __has_feature(objc_arc)
#define DT_WEAK_IVAR_IF_SUPPORTED __unsafe_unretained
#define DT_WEAK_PROPERTY_IF_SUPPORTED assign
#endif
@odrobnik
odrobnik / gist:5691712
Created June 1, 2013 20:55
Quick and very dirty time math
// get a time stamp from a pebble time struct
long timestampFromTime(PblTm time)
{
return (((time.tm_mday * 24) + time.tm_hour) * 60 + time.tm_min) * 60 + time.tm_sec;
}
long timeintervalBetweenTimes(PblTm time1, PblTm time0)
{
long timestamp1 = timestampFromTime(time1);
long timestamp0 = timestampFromTime(time0);
@odrobnik
odrobnik / gist:5629373
Created May 22, 2013 17:35
DTSQLiteDatabase.h
//
// DTSQLiteDatabase.h
// DTFoundation
//
// Created by Oliver Drobnik on 5/22/13.
// Copyright (c) 2013 Drobnik.com. All rights reserved.
//
/**
A wrapper for SQLite databases which offers threadsafe concurrency and support for cancelling long-running operations.
@odrobnik
odrobnik / gist:5590114
Created May 16, 2013 07:53
Weird translation bug in this ...
// get source image
NSData *imageData = _picture.imageData;
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)(imageData), NULL);
CGImageRef sourceImage = CGImageSourceCreateImageAtIndex(source, 0, NULL);
CFRelease(source);
CGRect imageRect = CGRectZero;
imageRect.size.width = CGImageGetWidth(sourceImage);
imageRect.size.height = CGImageGetHeight(sourceImage);
imageRect.origin.x = -imageRect.size.width/2.0;
@odrobnik
odrobnik / WWDC_Sorry.txt
Created April 30, 2013 15:02
WWDC Sorry No Bonus Template
Hello <FIRST_NAME>,
Thank you for contacting us regarding WWDC 2013.
Enthusiasm for this year's conference has been incredible and tickets sold out in record time.
<PERSON> can still take advantage of all the great WWDC content, as we'll be posting videos of all our sessions during the conference.
If you have any further questions please let us know by sending an email to wwdc@apple.com.
- (void)drawInRect:(CGRect)rect context:(CGContextRef)context
{
CGContextDrawImage(context, rect, self.image.CGImage);
}
@odrobnik
odrobnik / gist:5412380
Created April 18, 2013 12:34
DTLoupe.podspec
Pod::Spec.new do |spec|
spec.name = 'DTLoupe'
spec.version = '1.3.0'
spec.platform = :ios, '4.3'
spec.license = 'COMMERCIAL'
spec.source = { :git => 'git@git.cocoanetics.com:parts/dtloupe.git', :tag => spec.version.to_s }
spec.source_files = 'Core/Source/*.{h,m}'
spec.frameworks = 'QuartzCore'
spec.requires_arc = true
spec.homepage = 'http://www.cocoanetics.com/parts/dtloupeview/'
@odrobnik
odrobnik / gist:5405993
Created April 17, 2013 17:01
highlight string inside attributed string
- (NSAttributedString *)attributedStringWithString:(NSString *)string highlightedwithOccurencesOfString:(NSString *)stringToHighlight inColor:(DTColor *)color
{
// build an attributed string to start with
// font
DTCoreTextFontDescriptor *fontDesc = [[DTCoreTextFontDescriptor alloc] init];
fontDesc.fontFamily = @"Helvetica";
fontDesc.pointSize = 20;
// paragraph style