Scala, Java, Unix, MacOS tutorials (page 150)

Dateline October 20, 2017: I’ve renamed my book about Scala and functional programming. The original name was, “Learning Functional Programming in Scala,” but I don’t think that sets the tone of the book quite right, so I renamed it to “Functional Programming, Simplified (Scala edition).”

You can preview and buy the book in two places:

Here’s the new “Rampaging Lambda” book cover:

Functional Programming, Simplified book cover

“Now the Sun’s gone to hell
And the Moon riding high
Let me bid you farewell
Every man has to die.

But it’s written in the starlight
And every line in your palm
We’re fools to make war
On our brothers in arms.”

Today’s song of the day is Brothers in Arms, by Dire Straits.

I got to spend some more quality time in the hospital last week, and the CT scan results are almost comical: scar tissue where 99.9% of people won’t have scar tissue, body parts have been removed, four of my internal organs are enlarged, etc. Today I saw that I posted this on Facebook a year ago and I thought, well, it’s good to know that at some point my body will no longer be a problem. :)

(I don’t remember which book I found this page in, but I’ll update this post when I figure it out.)

The vajra body and tantric practice

The Fairbanks, Alaska ArcticCam shows snow on the ground this morning, October 19, 2017. The high today is 24 degrees (F), the low is 12. The high/low is 32/16 in Talkeetna as well.

The Fairbanks, Alaska ArcticCam (snow)

“Show me your flowcharts (source code), and conceal your tables (domain model), and I shall continue to be mystified; show me your tables (domain model) and I won’t usually need your flowcharts (source code): they’ll be obvious.”

~ Fred Brooks, “The Mythical Man Month

The Mythical Man Month

zdnet.com reports that Samsung is developing an Android app that will let you use your Galaxy phone as a Linux desktop computer. Samsung’s “Linux on Galaxy” announcement is here.

If you’ve never heard of the story of The Two Wolves, here’s a good, short, illustrated version of the story.

The Two Wolves

NPR reports that a new version of Google’s AlphaGo Zero software became a Go master by learning to play the game only by playing itself, i.e., only by using reinforcement learning (as opposed to supervised learning). Per the report in Nature.com, “AlphaGo Zero achieved superhuman performance, winning 100–0 against the previously published, champion-defeating AlphaGo.”

In case you want to know about squirrel behaviors, especially in the fall, National Geographic has this short article and video.

As a quick note today, I’ve been trying to build my own Amazon Kindle eBook using HTML and CSS, and yesterday I learned that I also need an OPF file as part of the process of creating both the eBook and the Table of Contents (TOC).

This morning I found that Amazon has a collection of sample books that you can use with Kindlegen, and the “Guide” project specifically includes the following example OPF file, which is well-documented.

An example Kindle OPF file

As mentioned, this example Kindle OPF file is well-documented, and comes with Amazon’s eBook samples, as part of their Kindlegen documentation. I include it here because it was the only way I was able to create an OPF file for my own Kindle eBook:

<?xml version="1.0" encoding="utf-8"?>
<!--
  The unique identifier in <package unique-identifier=”XYZ”> is a reference to
  the identifier specified in <metadata> as <dc:Identifier id=”XYZ”>.
-->
<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="BookId">

<!--
    Metadata:
    The required metadata element is used to provide information about the publication
    as a whole.
    
    For detailed info visit: http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html#Section2.2
-->
    
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
  
  <!-- Title [mandatory]: The title of the publication. This is the title that will appear on the "Home" screen. -->
  
    <dc:title>Kindle User's Guide</dc:title>
  
  <!-- Language [mandatory]: the language of the publication. The language codes used are the same as in XML
  and HTML. The full list can be found here: http://www.w3.org/International/articles/language-tags/
  Some common language strings are:
  "en"    English
  "en-us" English - USA
  "en-gb" English - United Kingdom
  "fr"    French
  "fr-ca" French - Canada
  "de"    German
  "es"    Spanish
  -->
    <dc:language>en-us</dc:language>

  <!-- Cover [mandatory]. The cover image must be specified in <manifest> and referenced from
  this <meta> element with a name="cover" attribute.
  -->
  <meta name="cover" content="My_Cover" />
  
  <!-- The ISBN of your book goes here -->
  
    <dc:identifier id="BookId" opf:scheme="ISBN">9781375890815</dc:identifier>
  
  <!-- The author of the book. For multiple authors, use multiple <dc:Creator> tags.
       Additional contributors whose contributions are secondary to those listed in
       creator  elements should be named in contributor elements.
  -->
    <dc:creator>Amazon.com</dc:creator>
  
  <!-- Publisher: An entity responsible for making the resource available -->
  
    <dc:publisher>Amazon.com</dc:publisher>
  
  <!-- Subject: A topic of the content of the resource. Typically, Subject will be
           expressed as keywords, key phrases or classification codes that describe a topic
           of the resource. The BASICCode attribute should contain the subject code
       according to the BISG specification:
       http://www.bisg.org/what-we-do-20-73-bisac-subject-headings-2008-edition.php
   -->
    <dc:subject>Reference</dc:subject>
  
  <!-- Date: Date of publication in YYYY-MM-DD format. (Days and month can be omitted).
       Standard to follow: http://www.w3.org/TR/NOTE-datetime
  -->
    <dc:date>2009-11-17</dc:date>

  <!-- Description: A short description of the publication's content. -->
  <dc:description>An overview of all the Amazon Kindle features and how to use them. 3rd Edition.</dc:description>
    
</metadata>

<!--
    Manifest:
    The required manifest must provide a list of all the files that are part of the
    publication (e.g. Content Documents, NCX table of contents, image files, CSS style sheets).
  Kindlegen however does not require CSS and images to be specified in the manifest if they
  are referenced from the content HTML.
    The manifest element must contain one or more item elements with the following media-type attributes:
  
  text/x-oeb1-document      HTML content files
  application/x-dtbncx+xml  NCX table of contents
  image/jpeg                JPEG image
  image/GIF                 GIF image
  
    For detailed info visit: http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html#Section2.3
-->

<manifest>
  <!-- HTML content files [mandatory] -->
    <item id="item3" media-type="application/xhtml+xml" href="UG-C2.html"></item>
    <item id="item4" media-type="application/xhtml+xml" href="UG-C3.html"></item>
    <item id="item5" media-type="application/xhtml+xml" href="UG-C4.html"></item>
    <item id="item6" media-type="application/xhtml+xml" href="UG-C5.html"></item>
    <item id="item8" media-type="application/xhtml+xml" href="UG-C7.html"></item>
    <item id="item1" media-type="application/xhtml+xml" href="UG-C1.html"></item>
    <item id="item14" media-type="application/xhtml+xml" href="toc.html"></item>
    <item id="item15" media-type="application/xhtml+xml" href="UG-C6.html"></item>
    <item id="item13" media-type="application/xhtml+xml" href="Welcome.html"></item>
    <item id="item16" media-type="application/xhtml+xml" href="UG-C8.html"></item>
    <item id="item18" media-type="application/xhtml+xml" href="UG-C9.html"></item>
    <item id="item19" media-type="application/xhtml+xml" href="UG-C10.html"></item>
    <item id="item20" media-type="application/xhtml+xml" href="Specifications.html"></item>

    <item id="GraphicsC5_C5Screen-rating" media-type="image/gif" href="GraphicsC5/C5Screen-rating.gif"/>
    <item id="GraphicsC5_C5Screen-Storefront" media-type="image/gif" href="GraphicsC5/C5Screen-Storefront.gif"/>
    <item id="GraphicsC5_C5Screen-Details" media-type="image/gif" href="GraphicsC5/C5Screen-Details.gif"/>


    note from Al: these items go on for about 85 lines ...


    <item id="GraphicsC3_C3Screen-blognextarticle" media-type="image/gif" href="GraphicsC3/C3Screen-blognextarticle.gif"/>
    <item id="GraphicsC3_C3Screen-newspaper" media-type="image/gif" href="GraphicsC3/C3Screen-newspaper.gif"/>
    <item id="GraphicsC3_C3Screen-readermenu" media-type="image/gif" href="GraphicsC3/C3Screen-readermenu.gif"/>
    
  <!-- table of contents [mandatory] -->
    <item id="My_Table_of_Contents" media-type="application/x-dtbncx+xml" href="KUG.ncx"/>
  
  <!-- cover image [mandatory] -->
  <item id="My_Cover" media-type="image/gif" href="GraphicsWelcome/WImage-cover.gif"/>
</manifest>

<!--
    Spine:
    Following manifest, there must be one and only one spine element, which contains one
    or more itemref elements. Each itemref references an document designated
    in the manifest. The order of the itemref elements organizes the associated content
    files into the linear reading order of the publication.
    
    The toc attribute refers to the id ref of the NCX file specified in the manifest.
    
    For detailed info visit: 
        http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html#Section2.4
        http://www.niso.org/workrooms/daisy/Z39-86-2005.html#NCX
-->
    
<spine toc="My_Table_of_Contents">
  <!-- the spine defines the linear reading order of the book -->
    <itemref idref="item14"/>
    <itemref idref="item13"/>
    <itemref idref="item1"/>
    <itemref idref="item3"/>
    <itemref idref="item4"/>
    <itemref idref="item5"/>
    <itemref idref="item6"/>
    <itemref idref="item15"/>
    <itemref idref="item8"/>
    <itemref idref="item16"/>
    <itemref idref="item18"/>
    <itemref idref="item19"/>
    <itemref idref="item20"/>
</spine>

<!--
    Guide:
    Within the package there may be one guide element, containing one or more reference elements.
    The guide element identifies fundamental structural components of the publication, to enable
    Reading Systems to provide convenient access to them.
  
  For detailed info visit: http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html#Section2.6
  
  The Kindle reading system support two special guide items which are both mandatory.
  type="toc"  [mandatory]: a link to the HTML table of contents
  type="text" [mandatory]: a link to where the content of the book starts (typically after the front matter)
    
  Kindle reading platforms need both thede guid items to provide a consistent user enxperience to the user.
  
  It is good practice to include both a logical table of contents (NCX) and an HTML table of contents
  (made of hyperlinks). The NCX enables various advanced navigation features but the HTML table of
  contents can easily be discovered by the user by paging through the book. Both are useful.
    
-->
    
<guide>
    <reference type="toc" title="Table of Contents" href="toc.html"></reference>
    <reference type="text" title="Welcome" href="Welcome.html"></reference>
</guide>

</package>

Discussion

Amazon also has their Kindle Publishing Guidelines PDF document, but seeing this sort of OPF file example was the only way I was able to piece together what should go in an OPF file when you’re creating a Kindle eBook from your own HTML and CSS. The documentation in this file is priceless if you’re trying this process on your own.

In the “Good News” department, apparently a long time ago when I was pretty sick with the MCAS, I wrote a series of Scala scripts to help convert a LaTeX document into an Amazon Kindle eBook. As a result, my book on functional programming in Scala should be available as a Kindle eBook later this week.

Unix/Linux shell script FAQ: How do I write a Unix or Linux shell script where I “do something” for every line in a text file?

Solution: A simple way to process every line in a text file is to use a Unix/Linux while loop in combination with the Linux cat command, like this:

In an effort to “Get rid of the crap,” I asked my editor if we could delete an entire chapter from the Scala Cookbook, and she said yes. I didn’t know if they’d allow that since the advance they paid me is based on a proposal of X chapters, but they’re all-in on just trying to create a good book, which is nice.

“The path is the goal.”

~ Gandhi

When life gives you cream, make a White Russian. Dude.

The Big Lebowski playing in Boulder, Colorado, 2011

Um, I’m pretty sure he plays tight end ...

Jake Butt, tight end