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

Tina Turner talks about the power of love in this LionsRoar.com article.

Tina Turner on love

“Successful design is not the achievement of perfection but the minimization and accommodation of imperfection.”

~ Henry Petrosky

“My best teachers were not the ones who had all the answers. They were the ones deeply excited by questions they couldn’t answer.”

Chicago Cubs’ star Kris Bryant gets pranked by Hall of Famer Greg Maddux:

Here’s a link to some Effective Scala slides, as presented by Mirco Dotta in 2013.

Effective Scala slides

Via a friend on Facebook:

“My advice: Don’t let yesterday contain the greatest things you’ve ever done. Make tomorrow contain your next great goal. Because once you feel your greatest days are behind you, you begin to die.”

At the very least that quote is about the importance of having goals.

“If you think you know what the state of the payments system 10 years out you're in a state of delusion.”

~ Charlie Munger talking about AMEX

I use the Java StringTemplate library in my Android applications, and Brian Clapper has created a Scala wrapper around it that he calls Scalasti. His intro: “Scalasti is a Scala interface to the StringTemplate Java template library. It provides a subset of the features of StringTemplate, using a more Scala-friendly syntax.”

Got this in an email last week, seems appropriate for today: “Marry a person you love to talk to.”

“Conscience, when it is flawless, is the voice of our soul, whispering in our ear.”

~ B.K.S. Iyengar, in the book, Light on Life: The Yoga Journey to Wholeness

If it seems like someone is winking at you, a) they might be, it’s Valentine’s week, or, b) they may have a condition known as blepharospasm, which is a symptom of MCAS. My right eye started doing this 10-15 years ago, long before I knew anything about MCAS.

(Turns out there are ~5,000 mast cells per cubic mm of conjunctival tissue, i.e., the inside of the eyelids.)

blepharospasm, or trembling of the eye

Back in the days before global warming the winters could be cold and long, and one year on February 11th I was on a yoga retreat in Mexico, which is where this picture was taken.

In the days before global warming

“The way we experience every part of our lives is affected by the qualities of our mind and by the coloring filters of our mental attitude.”

From the book, When the Chocolate Runs Out

As a quick note, this stackexchange.com page has some good background information on how to install a deb package file from the command line on Debian Linux (which in my case is Ubuntu 16.04). The short answer is that if you have a deb file named google-chrome-stable_current_amd64.deb, you’ll want to run these two commands, one after the other, as shown:

$ sudo dpkg -i google-chrome-stable_current_amd64.deb

$ sudo apt-get install -f

The complete example

To give you some more perspective on how this works, here are those two commands shown with all of the output that they produce. Note that I put my deb file in a temporary directory before running the commands:

/home/alvin/Desktop/tmp> sudo dpkg -i google-chrome-stable_current_amd64.deb
[sudo] password for alvin:
Selecting previously unselected package google-chrome-stable.
(Reading database ... 258250 files and directories currently installed.)
Preparing to unpack google-chrome-stable_current_amd64.deb ...
Unpacking google-chrome-stable (56.0.2924.87-1) ...
Setting up google-chrome-stable (56.0.2924.87-1) ...
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/x-www-browser (x-www-browser) in auto mode
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/gnome-www-browser (gnome-www-browser) in auto mode
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/google-chrome (google-chrome) in auto mode
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160701-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...

/home/alvin/Desktop/tmp> sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-image-4.4.0-31-generic
  linux-image-extra-4.4.0-31-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

After I ran those commands to install the deb file I removed the tmp directory I used during the installation process.

For more information see that stackexchange page. This debian.org page also has a good list of apt and dpkg commands, and this debian.org page shows how to list installed packages.

If you need to dump the contents of an array to the Android Log (Logcat) output, I can confirm that this approach works, at least with simple arrays of integers and strings that know how to print themselves:

Log.i("MyAndroidClass", Arrays.toString(arr));

If you’re trying to print more complicated arrays of custom objects you’ll probably need to implement good toString methods on those objects, and then this technique should work.

As a quick note, if you need some examples of the syntax of how to write a Java method that returns a generic type, I hope these are helpful:

public static <T> T getRandomValue(List<T> listOfPossibleOutcomes, int numPossibilities) {
    int r = RandomNumberGenerator.getRandIntBetween(0, numPossibilities);
    return listOfPossibleOutcomes.get(r);
}

public static <T> T getRandomValueFromGenericList(List<T> list) {
    Collections.shuffle(list);
    return list.get(0);
}

I hadn’t written a Java generic method in a while, and I forgot you need to declare the generic type (<T>) early in the method declaration.

As a quick note, here’s the source code for a Java “approximately equal” function that I use in an Android application:

/**
 * determine whether two numbers are "approximately equal" by seeing if they
 * are within a certain "tolerance percentage," with `tolerancePercentage` given
 * as a percentage (such as 10.0 meaning "10%").
 *
 * @param tolerancePercentage 1 = 1%, 2.5 = 2.5%, etc.
 */
public static boolean approximatelyEqual(float desiredValue, float actualValue, float tolerancePercentage) {
    float diff = Math.abs(desiredValue - actualValue);         //  1000 - 950  = 50
    float tolerance = tolerancePercentage/100 * desiredValue;  //  20/100*1000 = 200
    return diff < tolerance;                                   //  50<200      = true
}

You call the function like this:

boolean closeEnough = approximatelyEqual(1000, 950, 20);

Hopefully the comments describe the function well enough, so I’ll leave it at that, except for two related notes:

I went of my diet a little last night by eating some mozzarella cheese and half a beer, and this morning I woke up extremely itchy with several bumps. That’s how I roll with my version of MCAS.

“As your practice proceeds you’ll be able to remain conscious as you transition from your normal waking state into the states of sleep ... once you can remain conscious like this, you’ll no longer sleep but merely pass through the night by going into deeper states of meditation.”

To those who know me that sounds like something I might write, but those words were published by Ram Dass in 1971.

This image shows a little more of his text. I deleted a few sentences that were repetitive or used obscure words.

(Update: Here’s a link to more information on Ram Dass’s best books.)

Ram Dass on sleep and dreaming