Skip to content

Instantly share code, notes, and snippets.

View dhoerl's full-sized avatar

David Hoerl dhoerl

View GitHub Profile
@dhoerl
dhoerl / README.txt
Created January 28, 2012 21:52
UITableViewCells from a NIB - better than Apple's iOS 5 code
Reloading the NIB is expensive. Better to load it once, then instantiate the objects when you need a cell. Note that you can add UIImageViews etc to the nib, even multiple cells, using this method (Apple's "registerNIB" iOS5 allows only one top level object - one UITableViewCell. Bug 10580062 "iOS5 tableView registerNib: overly restrictive"
So my code is below - you read in the NIB once (in +initialize like I did or in viewDidload - whatever. From then on, you instantiate the nib into objects then pick the one you need. This is much more efficient than loading the nib over and over.
@dhoerl
dhoerl / HowTo.txt
Created January 27, 2012 13:10
Converting a NSDictionary to a Binary PList
When I posted this on Apple’s Cocoadev listserver, I never did get pointers to code to convert a NSDictionary to a binary formatted plist, but did get pointers to look at NSPropertyListSerialization - something I had already (mis)read a few times.
The description for the dataFromPropertyList class method seems confusing if you don't understand that you can create a property list with no keys: that is, you can create one with a single compliant object, and the key becomes "root".
So, in the unlikely event that some else someday has the same mental block, here is actual tested code that takes a NSDictionary and creates a binary plist file:
NSDictionary *dict;
char *payload = "This is the payload";
dict = [NSDictionary dictionaryWithObjectsAndKeys:
@dhoerl
dhoerl / LTActionSheet.h
Created January 27, 2012 13:00
UIActionSheet Subclass providing ability to set Font and Alignment for the message. Please advice if your app with it gets accepted.
/*
LTActionSheet - a UIActionSheet subclass to support customized fonts and alignment
Copyright (C) 2011 by David Hoerl
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@dhoerl
dhoerl / README.txt
Created January 27, 2012 12:48
BEST FIT NORMAL CURVE TO A HISTOGRAM
BEST FIT NORMAL CURVE TO A HISTOGRAM
I had a business need to provide the mean value of a process based on its bell-shaped histogram. Now, normally that would be an easy thing to do—there is a standard formula to get the mean and standard deviation.
However, in my case, the histogram has a skew. One side does not tail off to zero, but to some value midway between the peak value and zero.
After lots of googling, I found a paper written in 1993 by Brown and Hwang titled How To Approximate a Histogram by a Normal Density (http://www.jstor.org/pss/2685281). After purchasing a copy, I inquired if the author’s had software that implemented their algorithms. When the answer came back, I had to dig deep and turn their formulas into code, One integral had no series sum solution, so I had to really really dig deep and figure out how to do the conversion myself.
By intent I did all the conversion on my own time, and after I got everything working I sent the C Code to the authors in case anyone else ever asks.
@dhoerl
dhoerl / UIImage+WhiteImage.m
Created September 20, 2011 17:55
UIImage category to produce a new all white image from any other image. Useful to create white versions of darker icons for use in dark views.
//
// UIImage+WhiteImage.m
//
// Created by David Hoerl on 9/14/11.
// Copyright (c) 2011 David Hoerl. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@dhoerl
dhoerl / KeychainItemWrapper.h
Last active April 4, 2023 08:15
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.
/*
File: KeychainItemWrapper.h
Abstract:
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
dhoerl / Reachability.h
Created August 25, 2011 13:20
Reachability (iOS) ARCified
/*
File: Reachability.h
Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
Version: 2.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 this Apple software