Posts
Cards Art
I created these playing cards for Draco Calculation using Procreate and a stylus over the course of two months. Since the playing cards may appear small on a phone screen and larger on a tablet, my goal was a design that would scale well and have a playing card feel. The card lettering seen in the above collection of face cards (hi-res) is for the French deck. The game includes English lettering and also numbers with the same artwork.
Continue reading...Programming in iOS: imageNamed vs imageWithContentsOfFile
One easy way to load an image by name (from assets or from nib) is to use imageNamed method from UIImage. Without reading the UIImage reference, it may not be immediately understood that this also places the image into a cache. For single-use images, this may lead to unnecessary memory growth, especially for large images such as backdrops that the user may update several times. Here I’m loading an image named, “MarbleWhite” from a PNG file.
Checking the “Quick Help” in Xcode or the reference for “+ (UIImage *)imageNamed:(NSString *)name” reveals the cache warning:
This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method locates and loads the image data from disk or asset catelog, and then returns the resulting object.
The reference offers an alternative:
If you have an image file that will only be displayed once and wish to ensure that it does not get added to the system’s cache, you should instead create your image using imageWithContentsOfFile:. This will keep your single-use image out of the system image cache, potentially improving the memory use characteristics of your app.
If using our own cache for memory management, or for loading single-use image such as a backdrop, better to load from a file as suggested.
It always pays to check the programming documentation.
Two Calderas
Oregon is home of two notable calderas, Crater Lake and Newberry Caldera at Newberry National Volcanic Monument, both within a 80 miles of each other. Crater Lake, famous for its size at 5 miles accross and 1,943 feet deep, formed 7,700 years ago when Mount Mazama erupted. Newberry is known for its “Big Obsidian Flow” which formed 1,300 years ago, from Oregon’s youngest lava flow. The panaroma above shows Crater Lake with Wizard Island taken with iPhone 6. Click image for higher resolution. Newberry Caldera contains two lakes, Paulina Lake and East Lake as seen from Paulina Peak (elevation 7,984 feet) in the image below.
A trail alllows visitors close inspection of obsidian and pumice in the “Big Obsidian Flow” at Newberry. The photographs above and below were taken with a Canon Rebel.
The Cascade Range with Mt Bachelor and Three Sisters from Paulina Peak.
When visiting Crater Lake, I highly recommend taking a drive all the way around Crater Lake and stopping at several of the 30 viewpoints or trailheads.
Impressive are the spires of volcanic ash knowns as the “Pinnacles” and Vidae Falls.
Vidae Falls from David Shrock on Vimeo.
Crater Lake views from all sides taken with iPhone.
Problem: Validate a Phone Number
Article #4 in a 9-part series.
- 1 - Programming Problem: Determine if Two Strings Are Anagrams
- 2 - Programming Problem: Sum-Zero Triplet
- 3 - Programming Problem: Palindromes
- 4 - this article
- 5 - Programming Problem: Single-Edit Difference
- 6 - Prime Factors Problem 1: LCM
- 7 - Prime Factors Problem 2: Largest Prime Factor
- 8 - How-To: Substrings in Swift
- 9 - Programming Problem: Pangram
Validating and searching for a phone number is a common task for user entry or content searching. A person may enter their phone number in a number of formats making the task slightly more difficult, but the important part concerns recognizing a number with correct number of digits with allowed prefixes. For this task we’ll create a regular expression that can be used to validate a US phone number an entry or search for US phone numbers within a body of text.
observations
In the US, a phone number must be 10 digits (area code followed by 7 digit-number) and may be prefixed by the international or long-distance code (+1 or 1). Breaking up a US phone number into parts, we have area code of 3 digits followed by central office code (CO code, also known as exchange code) of 3 digits followed by four digits. Obviously beginning an area code or CO code with the international prefix of ‘1’ would be confusing, so these cannot begin with 1. Zero is for the operator, so that’s out as the first digit of area or CO codes. Certain prefixes are reserved in North America such as 911 and 411. What else is reserved? According this Wikipedia entry, all n11 combinations are reserved such that if the second digit is a ‘1’ then third digit cannot be a ‘1’ which makes things a bit easier for matching area and CO codes.
What about fictional characters with “555” CO code? It turns out only a range is set aside for fiction (555-0100 to 555-0199), so “555” is acceptable.
Phone numbers commonly appear with separators other than hyphen such as spaces, periods, or none at all such as (907) 555-0123, 1-907-555-0123, 907.555.0123, 907 555 0123, or 9075550123.
Continue reading...Programming Problem: Palindromes
Article #3 in a 9-part series.
- 1 - Programming Problem: Determine if Two Strings Are Anagrams
- 2 - Programming Problem: Sum-Zero Triplet
- 3 - this article
- 4 - Problem: Validate a Phone Number
- 5 - Programming Problem: Single-Edit Difference
- 6 - Prime Factors Problem 1: LCM
- 7 - Prime Factors Problem 2: Largest Prime Factor
- 8 - How-To: Substrings in Swift
- 9 - Programming Problem: Pangram
Since we had tested anagrams, it seems fair we give the palindrome check problem a go. How to check if a string is a palindrome? My solution is shown at the bottom in C#, Java, Objective-C, Swift (updated for 5), and C++.
observations
By definition a palindrome is word or phrase that is the same reversed ignoring lettercase, spaces, and punctuation. Other symbols and numbers count. Some examples:
- Madam, I’m Adam.
- Never odd or even.
- Rise to vote, sir!
- Salas
- 191