Color Me Crazy (or “When a Color Isn’t Just a Color”)
Ever need to use an image as a background, but can’t figure out how? It’s quite simple — colors aren’t always colors:
UIImage *patternImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"patternImage" ofType:@"png"]]; [myView setBackgroundColor:[UIColor colorWithPatternImage: patternImage]];
We are a Billion Fragments (or “Removing URL Fragments with NSURL”)
NSURL is a wonderfully powerful Cocoa object, bet there is at least one thing it leaves out, but I’ll show you how to fix that. URLs are composed of several distinct parts. Given the example URL of http://www.example.com:80/path/to/file/page.htm?key=val#foo this is broken into these parts:
- scheme (http://)
- authority (www.example.com:80)
- path (/path/to/file/page.htm)
- query (key=val)
- fragment (foo)
You can read more about all of this in RFC3986. Today I’m just focusing on the fragment part.
Frequently, you have an NSURL object and may just want the URL without the fragment, to find distinct pages in a site for example.
This Objective-C category on the NSURL object does just that.
header:
// // PDNSURLExtras.h // // Created by Eric Vitiello on 11/5/09. // Copyright 2009 Eric Vitiello. All rights reserved. // #import @interface NSURL (PDExtras) - (NSURL *)urlByRemovingFragment; @end
implementation:
// // PDNSURLExtras.m // // Created by Eric Vitiello on 11/5/09. // Copyright 2009 Eric Vitiello. All rights reserved. // #import "PDNSURLExtras.h" @implementation NSURL (PDExtras) -(NSURL *)urlByRemovingFragment { NSString *urlString = [self absoluteString]; // Find that last component in the string from the end to make sure to get the last one NSRange fragmentRange = [urlString rangeOfString:@"#" options:NSBackwardsSearch]; if (fragmentRange.location != NSNotFound) { // Chop the fragment. NSString* newURLString = [urlString substringToIndex:fragmentRange.location]; return [NSURL URLWithString:newURLString]; } else { return self; } } @endTo use:
NSURL *url = [NSURL URLWithString:@"http://www.example.com:80/path/to/file/page.htm?key=val#foo"]; NSURL *urlWithoutFragment = [url urlByRemovingFragment];
Nice and simple. Enjoy!
Come on Baby, Light My Fire (or “My Wife is Making Wine Bottle Torches”)
My wife is making tiki torches made from wine bottles and selling them on Etsy. Check out her wine bottle tiki torch!
JCPS is crazy (or “Why We Homeschool”)
Many people ask why we homeschool our son.

An discussion I was a part of asked why homeschooling isn’t 6 hours per day and is more frequently just a couple, and how that can be effective as compared to public schooling.
The math is very simple:
Public school: average of 180 school days. 30 students per class 6 classes per day 45 minutes per class
Total time the teacher can spend with each student per day: 1.5 minutes. A total of 4.5 hours per year.
Homeschool: Younger grades: 2 hours of school per day. 1 teacher 1 student
Total time per student per day: 2 hours per day.
Total time per student per year: 360 Hours.
The argument typically then turns to “but the parent isn’t always as educated as a public school teacher.”
Even so, I have to believe that the child getting 80 TIMES the amount of time with the teacher would outweigh (in most cases) the parent’s educational deficit. And the homeschool parents I know are active in learning what is needed anyway (I understand that is anecdotal evidence).
In fact, based on Wikipedia, 8.8% of Homeschool mothers (mothers are typically the parent that teaches) have a masters degrees, compared to 4.5% nationally. The same holds true for associates and bachelors degrees — homeschool moms more frequently have a degree. The separation is even greater for homeschool fathers, where 19.8% have a Masters compared to 5.4% nationally.
In short, homeschooled children on average get much more time spent with them per child, and the parents have higher education compared to the rest of the nation.
For those parents that can do it, and live in a deficient school system, homeschool is a good option.