Skip to content

Instantly share code, notes, and snippets.

David Hoerl dhoerl

  • New Jersey, USA
View GitHub Profile
dhoerl / KeychainItemWrapper.h
Last active Jul 30, 2020
KeychainItemWrapper ARCified. Added the ability to manage a dictionary in place of just a string - the #define PASSWORD_USES_DATA in the .m file switches the mode.
View KeychainItemWrapper.h
File: KeychainItemWrapper.h
Objective-C wrapper for accessing a single keychain item.
Version: 1.2 - ARCified
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
dhoerl / gist:c4b62696496f4a644239a950a1320cef
Last active Apr 26, 2020
Process Image Data in any orientation and make a UIImage in an "up" orientation
View gist:c4b62696496f4a644239a950a1320cef
// Based on
func image(data: Data, orientation: UIImage.Orientation = .up) -> UIImage? {
let context: CGContext
let width: CGFloat
let height: CGFloat
func defaultImage() -> UIImage? {
return UIImage(data: data)
dhoerl / gist:3acfadfa3de1fc97f2bb5c737ebb3d75
Last active Mar 31, 2020
Combine Complex Publisher for Medium
View gist:3acfadfa3de1fc97f2bb5c737ebb3d75
struct UpperCasePublisher: Publisher {
typealias Output = [Character]
typealias Failure = Error
let upstreamPublisher: AnyPublisher<Output, Error>
init(upstream: AnyPublisher<Output, Error>) {
self.upstreamPublisher = upstream
dhoerl / gist:ec6c3688ed42f95989e52d007a66ed5c
Last active Mar 31, 2020
Combine Subscriber for Medium
View gist:ec6c3688ed42f95989e52d007a66ed5c
final class StringSubscriber: Subscriber {
typealias Input = [Character]
typealias Failure = Error
var subscription: Subscription?
var count = 0
func receive(subscription: Subscription) {
self.subscription = subscription
dhoerl / gist:57fe946f95b647184c38b5c3942fc32c
Last active Mar 31, 2020
Combine Sample Publisher for Medium Article
View gist:57fe946f95b647184c38b5c3942fc32c
enum SPErrors: Error {
case inputStringWasEmpty
struct StringPublisher: Publisher {
typealias Output = [Character]
typealias Failure = Error
private let data: [Character]
dhoerl / gist:ea583ed8e9e94a6a44e276dc2ba55390
Last active Feb 14, 2020
Screenshot a UIView subsection in an UIImage
View gist:ea583ed8e9e94a6a44e276dc2ba55390
// Inspired by
+ (UIImage *)imageFromView:(UIView *)view subsection:(CGRect)subRect
// Image will be sized to the smaller rectangle
UIGraphicsBeginImageContextWithOptions(subRect.size, YES, 0);
// The primary view needs to shift up and left so the desired rect is visible
// But the rect passed below needs to be sized to the view, otherwise the image is compressed
CGRect drawRect = CGRectMake(-subRect.origin.x, -subRect.origin.x, view.bounds.size.width, view.bounds.size.height);
dhoerl / Asymmetric.swift
Last active Dec 23, 2018
Implement asymmetric cryptography for distributed app where keys can both be stored as strings
View Asymmetric.swift
// Asymmetric.swift
// Created by David Hoerl on 12/23/18.
// Copyright © 2018 David Hoerl. All rights reserved.
This is the portion you need in the distributed app, which uses the public key that can appear in plain text
dhoerl / AppDelegate(category).m
Created Jul 26, 2012
Keychain Wrapper for dictionary (NSData) not a single NSString
View AppDelegate(category).m
static NSString *kcIdentifier = @"MyApp";
@implementation LTAppDelegate (KeyChain)
- (void)keychainInit
self.keychainDict = [NSMutableDictionary dictionaryWithCapacity:7];
KeychainItemWrapper *item = [[KeychainItemWrapper alloc] initWithIdentifier:kcIdentifier accessGroup:nil];
[self.keychainDict setObject:@"" forKey:kcEmailAddress];
dhoerl / freeDiskSpace.m
Created Jun 20, 2012
Getting the Free Disk Space on an iOS device
View freeDiskSpace.m
- (uint64_t)freeDiskspace
uint64_t totalFreeSpace = 0;
__autoreleasing NSError *error = nil;
NSString *path = [self applicationDocumentsDirectory];
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error: &error];
if (dictionary) {
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
dhoerl / README.txt
Created Jan 29, 2012
std::string using printf style format strings
View README.txt
Prefer printf to the C++ iosstream methods? Now you can create a string using printf style format strings, and also append formatted string to existing strings.
Inspired by:
You can’t perform that action at this time.