Skip to content

Instantly share code, notes, and snippets.

View odrobnik's full-sized avatar

Oliver Drobnik odrobnik

View GitHub Profile
@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 / 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: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 / 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 / AppDelegate.m
Created August 7, 2013 13:35
replacing HTML entities with libxml2's SAX HTML Parser
#import "AppDelegate.h"
#import "ViewController.h"
#import "DTHTMLParser.h"
@interface AppDelegate () <DTHTMLParserDelegate>
@end
@implementation AppDelegate
@odrobnik
odrobnik / BCKEAN13Code.m
Last active December 20, 2015 20:49
First progress on making a modern EAN13 Barcode generator ...
//
// BCKEAN13Code.m
// BarCodeKit
//
// Created by Oliver Drobnik on 8/9/13.
// Copyright (c) 2013 Oliver Drobnik. All rights reserved.
//
#import "BCKEAN13Code.h"
(lldb) po [self.view recursiveDescription]
<UIScrollView: 0x8b96320; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8b990c0>; layer = <CALayer: 0x8b96530>; contentOffset: {0, 0}>
| <_UILayoutGuide: 0x8b96720; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x8b96790>>
| <_UILayoutGuide: 0x8b96ac0; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x8b96b30>>
| <UIImageView: 0x8b98b70; frame = (316.5 561; 3.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x8b98c50>>
| <UIImageView: 0x8b98330; frame = (313 564.5; 7 3.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x8b986c0>>
| <ContentView: 0x8b99eb0; frame = (0 0; 2000 2000); layer = <DTTiledLayerWithoutFade: 0x8b95c80>>
(lldb) po self.view.constraints
<__NSArrayM 0x8a67630>(
<_UILayoutSupportConstraint:0x8b96f10 V:[_UILayoutGuide:0x8b96720(20)]>,
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
CGFloat topInset = 0;
CGFloat bottomInset = 0;
if ([self respondsToSelector:NSSelectorFromString(@"topLayoutGuide")])
{
id topLayoutGuide = [self valueForKeyPath:@"topLayoutGuide"];
@odrobnik
odrobnik / gist:6421605
Created September 3, 2013 09:26
Why does setting the diameter cause the size to go to {0,0}?
@implementation ExpandButton
{
NSLayoutConstraint *_widthConstraint;
}
- (id)initWithFrame:(CGRect)frame
{
CGFloat smallerDim = MIN(frame.size.height, frame.size.width);
self = [super initWithFrame:frame];
@implementation DTProgressReportingURLProtocol
{
NSURLConnection *_connection;
dispatch_semaphore_t _semaphore;
}
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
NSLog(@"%@", [self propertyForKey:@"UserAgentSet" inRequest:request]);