This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
David's Top 10: Do That When Writing Swift | |
1) Purchase Dash (OS X and iOS) and get Swift from SwiftDoc.org (invaluable reference, I use it daily!) | |
2) Use Enums for UIView tags and SegmentedControl segments; | |
enum MyViews: Int { case OKButton=1...} then switch MyViews(rawValue: view.tag) | |
also for states (somewhat replaces C's X-Macros, helps during debugging) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: http://stackoverflow.com/questions/2342162 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspired by https://gist.github.com/nitrag/b3117a4b6b8e89fdbc12b98029cf98f8 | |
+ (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); |
OlderNewer