Accessing an SMB share in iOS using Swift

As you might guess from my Books page, I read/listen to a lot of books. It became apparent that I needed a way to track all of these books, basically just for my own sanity. I’m not sure if you are like me but when you read this many books, I really don’t remember all of them (most of them?). There are a lot of series in there that span years, so I often forget which ones I’ve read.

To alleviate this problem, I wrote a book database app for iOS/iPhone, using Swift and SwiftUI. It’s super simple, only has a couple of screens but as important as tracking my books, it allows me to search them. This is invaluable. Here are a couple of screenshots:

Since friends and family will ask what I’m reading, I decided to add the ability to post my list of books read to this website. It’s just a json file that lives on my server and is read by a script. The catch was when I first wrote the app, my website was hosted and the only way to push files to the server was via FTP. iOS supported FTP upload a long time ago and while depreciated, it still worked. And once you have something working, you tend to forget about it. When I moved to self hosting my website, FTP was quick and dirty to get going and I only had to change the login data inside the app.

But all the depreciated warnings bugged me, so I set out to move to SMB, as my server has a bunch of shares on it for various other things. iOS added native support for SMB way back in iOS 13 but it was pretty low level and I could never find any good example code on the web to work from. Fast forward to this week and I finally have tackled the problem thanks to a super easy SMB client library I found on GitHub.

The readme has very clear instructions, although I think he changed the fileName property to name in all instances and just forgot to update it. It really was as simple as adding the library via the Swift Package Manager (SPM), importing the library into my helper swift file that deals with saving the data, and then following the code examples under “Usage”. The author doesn’t use any do {...} catch {...} blocks to deal with errors in the example code but they are easy enough to implement. If you incorporate this functionality using a function, you’ll need to mark it as asynchronous and use a Task to call it, again pretty straight-forward. I commented out the old FTP code, tested, and everything worked. Sweet!

I’m not sure it’s worth providing more code here, given the extent of code in the readme on the GitHub page but if you have any questions, feel free to contact me or leave a comment.

Updated:
Uploading a file using this client will not overwrite an existing file but will cause a name collision error. You can however, delete the file prior to uploading, which worked find.

Favourite Books of 2023

While I wouldn’t call this year’s reading pace sedate, it definitely felt more relaxed, so that was great. Almost all the books I read this year were continuations of a series I had already started. The challenge with reading book 3 or 4 of whatever, is it’s often been years since I started the series and I can’t remember anything that happened. The price of reading a book or 2 a week on average I guess. My solution this year was to reread all the previous books in the series before reading the new one, which really helped in the “picking a new book” department. I also decided to go back and reread a few of my favorite books from the past, which I really enjoyed.

Sci-fi books continue to be a big genre for me. I read Wool by Hugh Howey, which was made into an AppleTV+ series called Silo, as well as “newer” science fiction titles from Emily St. John Mandel (a Canadian!) and Christopher Paolini’s 2020 award winning To Sleep in a Sea of Stars. The follow up book, Fractal Noise, was not as good. I reread Martha Wells Murderbot series but was disappointed with the new addition, System Collapse. Amazon did two original series of sci-fi shorts: a third installment of The Dispatcher series, which I really liked, and then the more traditional offering called The Far Reaches collection. How It Unfolds and Slow Time Between the Stars were very good. Sadly, I’m still eagerly waiting Dune part 2.

I read Bad Luck and Trouble by Lee Child. I liked season one of the Amazon series “Reacher” and have already started in on season 2. I saw Christoper Nolan’s, Oppenheimer. Interesting. I thought it was well done. Long, probably spent too much time on the interviews that ended in his security clearance being revoked but still good.

No real blockbusters I was looking forward to this year, although new books from Dennis E. Taylor, Jason Kasper, Andrew Mayne, and Jeremy Robinson, who wrapped up his crazy 15 novel crossover thingy, were all good. If there was a disappointment this year it would probably be James Rollins’ Tides of Fire. I just wasn’t interested in the science behind this novel (although it’s been in the news a fair bit) as much as prior novels and the “Sigma Force” spark seems to be dwindling. The Bobiverse books continue to be my go to, feel good books and I read (all!) of them a lot this year. I have to say, book 4, Heaven’s River, is growing on me.

I spent some time updating my book database app. It’s an iPhone app that drives all the data you see on the Books page. I added each book’s comment section to the data stored, which has been invaluable for “remembering” what books were about. I also converted its backend storage to SwiftData, a new database framework from Apple. I still save json files, as one of those is read by custom php to produce the Books page.

Okay, my favourite books of 2023. Like last year, I wouldn’t really put any of these books ahead of the other, they are all about the same. I thought Emily St. John Mandel’s trilogy, Station Eleven (now an Amazon series, which I have not watched), The Glass Hotel, and Sea of Tranquility were great. My only regret is that I read Sea of Tranquility first, as it is the closest to science fiction and it was on Obama’s 2022 best books list. They were definitely more “literary” than I usually read but they were great and I loved the Canadiana. If you plan to read them, please read them in order! Bonnie Garmus’ Lessons in Chemistry was fantastic. Of course, it’s also been made into a TV series (on AppleTV+). This seems to be true of so many books now.

There you have it. I hope 2024 is filled with exciting new books for everyone out there.

Favourite Books of 2022

After last year, I wanted to slow my reading progress and hopefully find more joy in it, rather feeling like a hamster on a wheel. Of course, that’s not really how it turned out. For whatever reason, I flew through quite a few books early in the year and things just went from there.

Like last year, I read a lot of series, so that helps to really stack up the number, and for the most part, I enjoyed them. It does make picking “favourite” books harder though, as you can’t really pick one book from a series as a favourite. I suppose I could pick a series, like I did last year but…

I read a few “classic” sci-fi books this year in Dune and The Peripheral. Interestingly, both have found their way onto a screen, one as (finally!) a very good movie and the other as an Amazon Prime series. The finale of The Peripheral Amazon series was way out there, so while I’m somewhat interested to see where they go with it, I’m not as invested as I was early on. Eagerly waiting Dune part 2.

No real blockbusters I was looking forward to this year, although new books from James Rollins, Steven Konkoly, Jeremy Robinson, and Andrew Mayne were all good. If there was a disappointment among this year’s reads, I would have to say it was Starry Messenger by Neil deGrasse Tyson. I’ve really like some of his earlier work, and while this one was “okay”, it just felt too “both sides ism” for me.

I didn’t read Dennis E. Taylor’s new singleton book, Roadkill? I don’t even know the title, yikes! Bobiverse books 1-3 were still strongly represented though. I’ve even started to write a few posts about the books, trying to explain some of the science. The other thing you may notice is the Pinterest widget/embeds are now gone, replaced by something I coded myself. The Books page now shows all books read every year (instead of only the last 50) and the covers conveniently like to their Amazon Kindle page.

Okay, my favourite books of 2022. Despite being the much smaller percentage of my reading volume, non-fiction titles continue to dominate. I wouldn’t really put any of these books ahead of the other, they are all about the same. The Emerald Mile by Kevin Fedarko was fantastic. It had an unfair advantage as one of the trips I took this year was rafting the Colorado, so this book was such a great setup for that. American Prometheus, by Kai Bird was also great. A bit detailed at times but a very interesting perspective on Oppy. Christoper Nolan is making a movie, Oppenheimer, based on this book, really interested to see how that turns out. Also interesting that Oppenheimer was finally “cleared” of all wrongdoing and/or suspicion this year and issued an apology for his treatment and the stripping of his security clearance in 1954. Finally, Blake Crouch continues to impress, this year with Upgrade. Interesting idea and very interesting perspective.

There you have it. I really don’t want to read over 100 books again next year, I need to savior them, and hopefully remember more of them, although that is probably asking too much. May all your reading dreams for 2023 come true.

Post 1b – Bob’s Trip From Earth to Saturn

I thought I might do a smaller/quicker post about Bob’s trip from Earth to Saturn before he heads out to Epsilon Eridani. Since Bob isn’t moving very fast, no relativistic physics is required, you can get away with go ol’ Newtonian mechanics (kinematics really, we aren’t considering forces here).

The relevant excerpts are:
Chapter 13: Bob – August 17, 2133 – Enroute

“The side trip would take a bit over six days at a constant two-g acceleration”

“I was travelling at over 5000 km/s by the time I reached the second-largest planet in the solar system.”

Excerpts From: We Are Legion (We Are Bob) Copyright © Dennis E. Taylor 2016

The trickiest part of this calculation is to determine the distance from the Earth to Saturn in August of 2133. The Jet Propulsion Lab (JPL) puts out large data sets, called ephemerides, that provide high precision location and motion information for the planets and their moons (among other data). I used DE440, which is the most recent dataset, published in February of 2021. This article in The Astronomical Journal discusses the dataset and is pretty dense. Here’s a download link to DE440 and some other datasets.

Once you have the dataset, you need to figure out how to use it to calculate the data point you are interested in. Fortunately, there is an excellent Python module called Skyfield that makes it very easy to load these datasets and then use them to calculate things like the distance between planets at any given time covered by the dataset.

Here’s the Python code I used to calculate the distance to Saturn for April of 2133:

You need to setup your Python environment properly (with Skyfield installed), after that it should be pretty straight forward. Here’s a link to the code on Github.

The output of the script looks like this:

planet,date,distance
Saturn,2133-08-17,9.810694167148197
Saturn,2133-08-18,9.827132134235871
Saturn,2133-08-19,9.843605975500804
Saturn,2133-08-20,9.86011150432379
Saturn,2133-08-21,9.876644525518076
Saturn,2133-08-22,9.893200822811535

The distances are measured in astronomical units (AUs) and I ended up just using the last one, 9.893200822811535. The definition of an AU can be found here:

1 AU = 149597870700 meters (m)
9.893200822811535 AU = 1480001777500 m
Here's the setup I use to solve standard kinematics type problems:
d = 1480001777500 m
a = 2g = 2 * 9.80665 = 19.6133 m/s/s
t = ?
vi = 0 m/s
vf = ?

We determined the distance to Saturn for the correct date/time, we are told Bob was accelerating at a constant 2g, and I’m assuming he started from zero initial velocity when leaving Earth. This is not exactly true, as we know Bob was trying to avoid the missiles but we don’t know anything about the actual vectors and speeds involved in that, so this was easiest and won’t have a big impact on the final answer. The kinematics equation that relates d, a, v_i and solves for t is:

(1)   \begin{equation*} d = v_it + \frac{1}{2}at^2 \end{equation*}

Subbing in the values above gives us:

(2)   \begin{equation*} 1480001777500 = (0)t + \frac{1}{2}(19.6133)t^2 \end{equation*}

Solving this for t:

(3)   \begin{equation*} t = \sqrt{\frac{2 * 1480001777500}{19.6133}} \end{equation*}

(4)   \begin{equation*} t = 388481.8925 s \sim 4.5 days \end{equation*}

Here’s the same treatment for the variables d, a, v_i and v_f:

(5)   \begin{equation*} v_f^2 = v_i^2 + 2ad \end{equation*}

Subbing in the values above gives us:

(6)   \begin{equation*} v_f^2 = 0^2 + 2(19.6133)(1480001777500) \end{equation*}

Solving this for v_f:

(7)   \begin{equation*} v_f = \sqrt{2(19.6133)(1480001777500)} \end{equation*}

(8)   \begin{equation*} v_f = 7619411.902 m/s = 7619.4 km/s \end{equation*}

Hmm. While Dennis’ values are certainly in the same ballpark as the ones calculated above, there is some discrepancy. There are any number of explanations as to why that might be, so I’m not going to pick this apart any further.

Updated:

Here is a plot showing the positions of the planets for the same timeframe (Apr 17, 2133). Not sure if Dennis planned it this way but Saturn is in a pretty favorable position.

NB: The scale for Mercury and Venus is a little janky in order to make the Sun noticeable. Distances are accurate from the Sun’s centre.

Post 1 – Bob’s Trip to Epsilon Eridani

I’m going to keep this first post pretty simple. It’s based on these two excerpts:

Chapter 13: Bob – August 17, 2133 – Enroute

“Epsilon Eridani is 10.52 light-years away from Sol. The specs indicated that the ship could run at 2g indefinitely with no ill effects, which would get me to my target star in a little over eleven years.”

“With a mental sigh, I adjusted my heading for Epsilon Eridani and cranked the drive back up to 2 g. The trip would take just under eleven and a half years to the universe at large, but only three years ship’s time. At midpoint, I would be travelling within a hair of light speed.”

Excerpts From: We Are Legion (We Are Bob) Copyright © Dennis E. Taylor 2016

I don’t know what database or star catalogue Dennis used for his data, simply looking up Epsilon Eridani in Wikipedia provides a huge amount of astronomical data, nicely summarized down the right sidebar. That page lists Epsilon Eridani as being \text{10.475 lightyears (ly)} away with an error of only \pm \text{0.004 ly}. Hmm, this wouldn’t get you to Dennis’ \text{10.52 ly} but that doesn’t really matter given the accuracies we are dealing with in the book. There is also the question of what values Dennis used for constants, like the speed of light, c. I’ll create a post of constants and astronomical data so you know where mine came from.

So how does Dennis come up with “just under eleven and a half years” for a stationary observer, like someone on Earth and also “three years ship’s time”?

First, let’s talk about how one gets to a star system. There are basically two options:

  1. Accelerate your ship to its maximum velocity, cruise along at that maximum velocity for most of your voyage, then decelerate to arrive at your destination, at some relatively small velocity.
  2. If your ship does not have a maximum speed and is able to accelerate at some constant value indefinitely, then you just keep accelerating until you reach the midpoint of your journey, then start decelerating until you reach your destination.

Option 1 is how most of us take trips and it’s also the way NASA uses for the probes it sends to other planets. However, based on the excerpt above, it appears the Bob’s are able to use method 2. Dennis never talks about a limit to the speed a HEAVEN vessel can attain (or maintain). The challenges associated with this may be discussed in a future post but for now, we’re going to assume that we can accelerate for the first half of the trip, then decelerate for the second half.

Okay, so how do we do this calculation. You may have heard of Special Relativity, proposed by Albert Einstein in September of 1905. One aspect of Special Relativity is called time dilation, which states that time slows down when you move at very high speeds (a significant portion of the speed of light). Special Relativity typically deals with “inertial reference frames”, which are situations where objects are traveling at CONSTANT speed, not accelerating. When you have a spaceship like HEAVEN 1, it accelerates at a constant rate of 2g (2 times the rate of gravity), at least that is what the excerpt tells us. Evolving Special Relativity’s equations to work with constant acceleration involves calculus and hyperbolic functions and is beyond the scope of what I’m looking to do here. For those interested, here’s a paper that shows the derivation of uniform relativistic acceleration.

These equations are summarized on a great webpage, the Relativistic Rocket. I will use three of the equations found on this page to calculate the relevant values Dennis talks about. These equations are:

Earth time to the star system:

(1)   \begin{equation*}   t = \sqrt{\left(\frac{d}{c}\right)^2 + \frac{2d}{a} \end{equation*}

Ship's time to the star system:

(2)   \begin{equation*}   T = \frac{2c}{a} cosh^{-1} \left( \frac{ad}{2c^2} + 1 \right) \end{equation*}

Speed at the midpoint to the star system:

(3)   \begin{equation*}   \upsilon = \frac{at}{\sqrt{1 + \left(\frac{at}{c}\right)^2}} \end{equation*}

Where the various values are: d = distance to the star system c = the speed of light a = the ship's acceleration t = stationary/earth time to the star system (from equation 1)

There are two tricks to actually doing these calculations, one is to make sure you get the units for the various values correct. If we use lightyears (ly) for distance and years (y) for time, then speed will be lightyear / year (ly / y) and acceleration will be lightyear / year^2 (ly / y^2). The other is to realize that for the earth time equation, that’s the time if we accelerate all the way there. In order to stop at the star system, we have to calculate the earth time to the midpoint and then double that time to get the total time to the system. This is not required in the ship’s time calculation, as it was already taken into account in the formula.

Please note: a lightyear is a measure of distance not time. It’s the distance light travels in one year.

Using the units outlined above, these values become:
d = 10.475 ly
c = 1 ly / y
a = 2g = 2.0645816 ly / y^2
t = 11.4026586 y

I was going to write out the above equations, substituting the values above but writing out equations in WordPress is clumsy at best, so I don’t really feel like doing that. You could plug those values into your calculator, that works. To calculate the results here, I decided I’d write a small python script and embed it below. The best part about this solution is the code is interactive, so you can play around with the values, like the ship’s acceleration, to see what effect that has on the results. Any changes you make aren’t saved, so if you change some things and want to go back to the original values, click on the menu button on the top left and then select “Reset”, then click “Yes, I Am sure”. Clicking the play button below runs the code. Let’s do that now.

NB: The above code is now available on GitHub here.

Here's a summary of the results, rounding to 3 decimal places:
Earth time: 11.403 years
Ship's time: 3.062 years
Speed at midpoint: 0.996 fraction of c

Comparing the results to the Dennis’ excerpt above, you can see that his values are right on the money.

These formulae and the python script can be used to calculate times and speeds for any of the trips Dennis outlines in the book, just by updating the distance and ship’s acceleration. For example, the colony ships travel from Earth to \text{Omicron}^2 Eridani (also known as 40 Eridani), which is a distance of 16.34 ly and their acceleration is only 1g. If you plug these into the script above, you get:

Earth time: 18.174 years
Ship's time: 5.686 years
Speed at midpoint: 0.994 fraction of c

These numbers line up reasonably well with Dennis’, given here:

Chapter 58: Riker – April 2171 – Sol

“The colony ships had a maximum sustained acceleration of 1 g, so the trip would take slightly longer than it would have for a version 1 Bob. They would be on the road for a little over eighteen years. About six years would pass on-board, but no time at all for the colonists in their stasis pods.”

Excerpts From: We Are Legion (We Are Bob) Copyright © Dennis E. Taylor 2016

That’s all for this post. Let me know what you think. See you in the funny papers 🙂

Introduction

Welcome to The Bobiverse – Explained. I, like you, am a big fan of Dennis E Taylor’s Bobiverse books, well, the first three at least. Since Dennis writes in the genre known as hard science fiction, I thought it would be fun to write a series of blog posts that explore the science behind the novels and to provide some detail by showing calculations for some of the values Dennis describes (e.g. how long it takes to get to a certain star system). Most of these posts confirm of Dennis’ accurate work although I will occasionally raise some questions regarding some of the science. Future posts may veer off into more conjecture but I’ll try to keep those to a minimum.

Please note this is not meant to be a critique or criticism of Dennis’ work in any way, I LOVE these books, have read them MANY times, and continue to reread them. It’s simply an exercise for me to brush up on some Physics and has been something I’ve been thinking of doing ever since a made a post in the Fans of the Bobiverse Facebook group (please note, this is a private group) about Dennis’ use of tau ( \tau).

I don’t plan to cross post these on FB except for this introduction with some slight modifications, so if you’d like to comment, discuss or have a suggestion, please feel free to do so on any of the posts. Also, if have a question about some aspect of the science in any of the books, add a comment or contact me via the Contact page and I’ll do my best to answer.

I’d like to write one new post per week but we’ll see how that goes. And now, on to the first post, examining Bob’s flight to Epsilon Eridani.

NB: I am uploading most code found in the subsequent posts to GitHub, which can be found here.

Favourite Books of 2021

While 2021 was another sucky year with respect to all that’s happening in the world, it will definitely go down as my all-time book reading record, with well over 100 books read this year.

Sadly, the Pinterest widget only displays the last 50 pins in a board, so you’ll see less than half the books I read but it’s the only easy option for now.

I powered through quite a few series this year, which is one of the reasons for the high book count. Not having to think about/find the next book to read is a big deal when you are reading 2-3 books a week.

Many of the series were entertaining and I definitely recall wanting to “get back” to them to see what happened next. Having said that, when I think back over the year, only one series really stood out as a favourite. Singletons continue to dominate my favourites.

Like last year, this year’s big disappointment was a highly anticipated book, Infinite 2, by Jeremy Robinson. Infinite was one of my favourite books in 2019 and I reread it in preparation for the sequel. Unfortunately, Infinite 2 just didn’t work for me. The fact that I can barely remember the plot line as I type this speaks volumes. Also like previous years, I continue to reread the Bobiverse books, albeit only books 1 through 3. They never get old.

Okay, here are my favourites from 2021. Andy Weir continues to be one of my favourite authors and while Artemis was good, The Martian, and this year’s addition, Project Hail Mary, were GREAT! Walter Isaacson also continues to be one of my favourite authors, his biographies are amazing and The Code Breaker, which features the story of Jennifer Doudna, is no exception. The bulk of the book was written before it was known that she would share the 2020 Nobel Prize in Chemistry for her work on gene editing and CRISPR. Finally, the series I was most excited about this year was “Season 2” of Dean Koontz’s Nameless. Season 2 was a fitting conclusion to what was an excellent Season 1. I think it would have been very interesting if Koontz had decided to write this as a full novel as opposed to a bunch of short stories but the result is still great.

I hope you had a great reading year and I’m looking forward to 2022, with lots of releases already on the calendar.

Favourite Books of 2020

2020 was another good reading year for me with 64 books read. While this post comes late, better late than never in some cases.

It was challenging to choose 3 favourites from the past year. While there were many good books, not as many stood out strongly as they had the year before. Possibly the biggest disappoint was the release of the much anticipated Bobiverse Book 4, “Heaven’s River” by Dennis E Taylor. The first 3 Bobiverse books continue to be my all time favourites and I reread them frequently. Sadly, Book 4, while I understand the evolution of the narrative, took a completely different path from the previous 3 and went far more dystopian. The Bobiverse has always been an uplifting, escape for me and Book 4 was definitely not. In fact, I recently reread the series but only the first 3 books, excluding the 4th.

Enough chatter, here are my 3 favorites from 2020. The most interesting aspect of these picks is they are all non fiction, which makes up a small percentage of the books I read each year.