Skip to content

Instantly share code, notes, and snippets.

View karnlund's full-sized avatar

Kurt Arnlund karnlund

View GitHub Profile
@karnlund
karnlund / CircularQueue.h
Created March 1, 2021 01:28 — forked from werediver/CircularQueue.h
Simple implementation of circular queue in Objective-C (for ARC-enabled environment).
//
// CircularQueue.h
//
// Created on 9/21/13.
//
#import <Foundation/Foundation.h>
@interface CircularQueue : NSObject <NSFastEnumeration>
//
// ViewController.swift
// KeyboardTest
//
// Created by Adam Śliwakowski on 01.12.2015.
// Copyright © 2015 Adam Śliwakowski. All rights reserved.
//
import UIKit
typealias AnimationClosure = (() -> Void)
@karnlund
karnlund / Example.swift
Created February 27, 2017 08:21 — forked from IanKeen/Example.swift
Small utility methods to simplify dealing with Reusable items i.e. table/collection view cells
//`UITableViewCell` and `UICollectionViewCell` are `Reusable` by defaut
//Use the extension method to dequeue an instance of the appropriate `Reusable`
class MyVC: UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
tableView
.registerReusable(FooCell.self)
.registerReusable(BarCell.self)
}
CGRect CGRectIntegralScaledEx(CGRect rect, CGFloat scale)
{
return CGRectMake(floorf(rect.origin.x * scale) / scale, floorf(rect.origin.y * scale) / scale, ceilf(rect.size.width * scale) / scale, ceilf(rect.size.height * scale) / scale);
}
CGRect CGRectIntegralScaled(CGRect rect)
{
return CGRectIntegralScaledEx(rect, [[UIScreen mainScreen] scale]);
}
static void dispatch_async_repeated_internal(dispatch_time_t firstPopTime, NSTimeInterval intervalInSeconds, dispatch_queue_t queue, void(^work)(BOOL *stop))
{
dispatch_after(firstPopTime, queue, ^{
BOOL shouldStop = NO;
work(&shouldStop);
if(!shouldStop)
{
dispatch_time_t nextPopTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(intervalInSeconds * NSEC_PER_SEC));
dispatch_async_repeated_internal(nextPopTime, intervalInSeconds, queue, work);
}
//
// AppDelegate.m
// AnimationExamplesiPhone
//
// Created by Eric Allam on 10/05/2014.
#import "AppDelegate.h"
#pragma mark - UIColor Additions
@karnlund
karnlund / ExtendedManagedObject.h
Created November 21, 2012 21:32 — forked from vl4dimir/ExtendedManagedObject.h
Added traversal reset that allows a single managed object graph to be converted -(NSDictionary*)toDictionary twice. This is essential if your app is optimized to not fetch the same graph twice.
@interface ExtendedManagedObject : NSManagedObject {
BOOL traversed;
}
@property (nonatomic, assign) BOOL traversed;
- (NSDictionary*) toDictionary;
- (void)resetTraversal; /* allows toDictionary to be called twice on the same managed object graph */
- (void) populateFromDictionary:(NSDictionary*)dict;
+ (ExtendedManagedObject*) createManagedObjectFromDictionary:(NSDictionary*)dict