(If you have no idea what "Markdown" and "Swift" are, you can just stop reading now.)
Apple's new Swift programming language isn't really a functional programming language. However, it does support generic types and functional-programming patterns, so many FP aficionados are implementing their favorite functional idioms and libraries from other programming languages in Swift.
I've been a functional-programming enthusiast for a couple of decades, and I'm playing with this myself. A feature I like in the F# programming language is its pipe-forward operator,
|>, which helps to write readable functional code. This article explains what that operator is, why you would want to use it, and how to do it in Swift.
Disclaimer: The code in this article is based upon the version of Swift in Xcode 6 beta 7. Future changes to Swift syntax or its standard library may render all of this incorrect or obsolete.
As an experiment in using Apple's new Swift programming language, I whipped up a simple tip-calculator app for iOS 8.
Yes, the world really needs Yet Another Tip Calculator, and it also really needs Yet Another Swift App Example.
In addition to using Swift, the app also uses an embedded framework, which is a new feature of iOS 8. The framework contains functions and classes for converting between numbers and text, and it might be useful in other apps.
Source is available on GitHub: https://github.com/kristopherjohnson/KJTipCalculator
If you actually want to use this app, you'll have to build it yourself. But if you have iOS 8 on your phone now, you should know how to do that.
A little over a year ago, I published A Web Page for Reformatting JSON Text, which is a simple web page for pretty-printing JSON data. I'm now learning AngularJS, so as an exercise I reimplemented the page using Angular rather than the original's jQuery.
This version is a little nicer than the original in the following ways:
- You can type or paste text into the top box and the formatted JSON immediately appears in the lower box. There is no longer a need to press a Format button because Angular's data-binding mechanism takes care of automatically updating the output whenever the input changes. (This is possible with jQuery too, but takes more work.)
- You can control the indentation width of the formatted JSON.
- When the input is not valid JSON, the output panel changes its background color to red when displaying the error message.
Here it is: JSON Formatter with AngularJS
Short link: http://bit.ly/formatjson
You can look at the full source here: Gist
or as a fiddle: http://jsfiddle.net/oldmankris/qK9LK/
If don't know anything about AngularJS, but are curious about it, look at the source and note the following:
- The magic of Angular comes from the
ng-attributes attached to HTML elements. There is no need for a separate template language or explicit DOM manipulation.
- The ng-app attribute attached to the
htmlelement sets up the module that contains our app's code.
- The ng-controller attribute attached to the
divelement defines which controller function to use.
- The ng-model attribute attached to the first
textareaelement binds its content to the
- The ng-bind attribute attached to the second
textareaelement binds its content to the value of the
outputTextvariable, and the ng-class attribute binds its CSS class to the value of the
- The ng-options and ng-model directives on the
selectelement bind it to the
- In the controller code, we set initial values for the
selectedInputOptionvariables, and then use $scope.$watch() to update the values of
outputClasswhenever any of the inputs change.
OS X Server is now available free of charge for members of Apple's iOS Developer Program, so I have it installed on most of my machines. Unfortunately, having OS X Server installed complicates the use of the built-in local Apache web server which I use for web development. I've figured out how to make things work the way I like, and I have written this article so that I can find the information again when I need it. Maybe it will help somebody else too.
You can find my Zenburn for Xamarin theme here: https://gist.github.com/kristopherjohnson/784360f9676b59766678
To use it, download the
.json file, open Xamarin Studio, go to Preferences > Syntax Highlighting, click the Add button, and select the file.
It's not a complete rendition of Zenburn. I've only defined the colors that are used in C# and F# code, and haven't bothered with all of the subtle color distinctions between different varieties of syntax elements.
I finished a freaking marathon!
The weather was good for running a marathon. Temperatures were in the 50's, and the sky was covered with clouds. The forecast called for rain, but aside from a few sprinkles halfway through the race, we stayed dry.
I have previously run two half marathons with times around 2:10, so I was expecting my marathon time to be somewhere between four-and-a-half and five hours.
That was wildly optimistic.
The Georgia Marathon course is very hilly. The course I run when training has more hills than the average marathon course, I think, but it didn’t prepare me for this course.
For the first ten miles, I kept to my goal pace of ten and a half minutes per mile. After mile 12, I had to walk up most of the uphill stretches, and there were a lot of uphill stretches. After mile 21, I couldn’t even run on the downhill stretches anymore. My legs would cramp whenever I tried to run. I wasn’t even sure I’d be able to walk those last five miles.
My final time was 5:41, about an hour longer than I expected. I think I did everything right in terms of preparation, nutrition, hydration, and pacing. I just hadn’t built up the endurance to run 26 miles of hills.
But hey, I finished a freaking marathon.
My FitBit says I took over 54,000 steps (including steps walking to/from the marathon). I suspect that will be my daily step record for a while.
On mile 20, some spectators were handing out cups with a brownish liquid. I assumed it was iced tea, but was delighted to find that it was cold beer. I’d like to nominate those people for the Presidential Medal of Freedom.
Action photos available here: Facebook photo album
The installer puts the SDK files in the user’s home directory, and the setup guide recommends using paths like
$(HOME)/Library/SDKs/ArcGIS/iOS/ in Xcode projects to find the framework’s headers and libraries. This works fine as long as one is using Xcode as a user who has installed the SDK. However, it causes problems if one wants to set up an Xcode bot to automatically build and test the app. The Xcode service that runs bots executes under the
_teamsserver user account, and by default that user’s home directory does not exist, and you can’t log in as that user to run the SDK installer. So attempts to create a bot to build the app just result in “ArcGIS.h not found” compilation errors.
After I bit of Googling and experimentation, I came up with a solution:
- Install the SDK in my user account (or another normal account), following Esri’s installer and instructions.
- Make my
chmod 755 ~/Library
- Create the
/var/teamsserverhome directory for the
sudo mkdir /var/teamsserver
- Create the
/var/teamsserver/Librarydirectory for the
sudo mkdir /var/teamsserver/Library
_teamsserveras the owner of the directories:
sudo chown -R _teamsserver:_teamsserver /var/teamsserver/
- Set permissions on the directories:
sudo chmod -R 770 /var/teamsserver/
- Create a symbolic link to the SDK installation:
sudo ln -s ~/Library/SDKs /var/teamsserver/Library/SDKs
This works. It could be argued that it would be better to set up the symbolic links in some shared location (
/usr/local, etc.) and then use a full path in the Xcode project to find them, but I prefer this solution because it doesn’t require any extra steps for developers who don’t need to set up a bot.
Another annual State of the Kris message:
The biggest change for my family this year was moving from our little mountain cabin in Dahlonega to a house in Cumming. This puts us closer to the schools where Pebble teaches and where Bailey learns. Instead of spending two hours commuting per day, we now spend about 30 minutes.
I used to joke that we should just move to exit 14, since that’s where we spent our weekends shopping. Now we’re here.
Our five dogs love the big fenced-in wooded backyard. They get to chase deer once in a while. (I don't know what a Yorkshire Terrier would do if it caught a deer, but I'm not worried about that happening.)
I ran two half marathons this year, and I’m preparing to run a marathon in March. I’ll probably also try to run the Atlanta Marathon in October. After that, I suspect I will be finished with marathons, but will keep running twenty or thirty miles per week. I enjoy running, and like being in better shape than I have been for the past couple decades.
Pebble is now working at North Forsyth High School, teaching courses in forensics and agricultural science. She seems less stressed-out than she did while working at the middle school.
Bailey is really enjoying the marching band. His band went to a competition in New York, and they took third place. The band will be going to London in December.
I usually make a list of goals for each year. However, I rarely consult that list after making it, so I’m not going to bother this year. I hope to run two marathons, and I hope to learn to play piano, but I really just want to enjoy life in our new home.
I recently purchased a Garmin Forerunner 110 GPS watch to track my runs. I've been happy with it, but today when I plugged it into my computer after a run, the watch screen flashed "Saving activity" and then went blank. The watch was dead after that.
It had been fully charged before my run, so I was pretty sure it wasn't just out of juice. The instructions provided with the watch weren't helpful.
This blank-screen issue appears to be a common problem. The Forerunner 110 Blank Screen (Dead) thread in the Garmin forums has over 100 entries. You can browse that thread for details, but here is a summary of the suggested fixes:
- Hold down the Light, Start/Stop, and Lap/Reset buttons for about 30 seconds. (This worked for me.)
- Hold down all four buttons for about 7 seconds. (Didn't work for me.)
- Hold down the Light button for about 6 seconds. (Didn't work for me.)
- Hold down the "Power" button while plugging it into the computer. (My watch doesn't have a button labeled "Power". I tried this with the Light button, and with the Page/Menu button, but neither worked.)
- Plug it into a different USB port. (Didn't work for me.)
- Just leave it plugged in for a few days, and eventually it will spring back to life.
- Rub the contacts with a pencil eraser.
- Attach the USB clip, but don't attach the clip to a USB port, and hold the Light button for 6 seconds.
- Check whether there is a firmware update available.
- Try a master reset.
- Contact Garmin Customer Support.
- Take the watch back to where you bought it for replacement/refund.
After I got it working, i checked for a firmware update, and indeed there was a new firmware version available for the Forerunner 110. This is in the release notes:
Changes from version 2.60 to version 2.70:
Fixed an issue where the device could display a blank screen while connected to the charger.
I installed the update. I'll have to wait to see whether the problem recurs.
Update 2014-01-23: The screen went blank again. Hold down the Light, Start/Stop, and Lap/Reset buttons got it working.
Update 2014-03-09: Blank again, and the above remedies weren't working. The recharging display did appear when I connect it to USB, but it wouldn't do anything when disconnected. I let it sit disconnected for a few hours, and it sprung to life.