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

Ammonite FAQ: How do I load managed dependencies into the Ammonite REPL? What is the syntax for loading dependencies (and JAR files, too)?

Solution

If you want to import a managed dependency into the Ammonite REPL, the solution is to use its import $ivy syntax:

I initially created this “How to use Scala CLI” content for my new Scala book, Learn Functional Programming Without Fear, but when I decided to shorten what I include in the book, I also decided to put the full version of this content here.

What is Scala CLI?

Until some time in the year 2021 I would have written this book using only the Scala SDK and its scalac and scala commands to compile and run your code, respectively. (These are just like javac in Java, kotlinc in Kotlin, and java with both of those.)

But since that time the Scala CLI command project has come along, and it greatly simplifies the “getting started with Scala” experience, so I use it in this book. Scala CLI:

Datline March 22, 2014: A little personal enlightenment:

After going unconscious several times during the last few weeks, I've had conversations with doctors, nurses, friends, and even a shaman about life, death, quality of life, goals, and desires.

I had a hard time answering some of their questions, and yesterday I realized why that was:

If you're truly living in the present moment, those questions don’t make any sense! You can't think about life, death, the past, or the future if you’re fully absorbed in the present moment.

When planning for the future, live fully in that moment of planning for the future. When eating, just eat; and when writing text like this, just write. That’s all.

(In computer parlance, become single-threaded, where that one thread is only focused on HereNow.)

As a brief note today, I have been reading the Bhagavad Gita (translated by Jack Hawley) lately, and he shares this good line that relates to desire, attachment, and even addiction:

“Realizing the truth of your True Self is your principal weapon for eradicating desire.”

My short interpretation of that is that our True Self is not our physical body, but something else that you might call awareness, consciousness, the subtle body, the soul, or the Atma, AND, it is possible through yoga, mindfulness, and meditation practice to get in touch with (feel/experience) your True Self. And then, once you realize who “you” really are, your attachments to the physical world will go away.

I used to have a friend who was an addict, and I know she was always looking for anything that would help, so I hope this quote can be helpful for others.

This is an ongoing blog post about “making the switch” from Google AdSense to Ezoic in 2024. If you’re just interested in updates over time, see the “Updates” section at the bottom.

Switching from AdSense to Ezoic

For a long time I was afraid to switch to another company besides AdSense because I had not heard of Ezoic and others, but after several weeks on their platform, all is well.

I should also say that I was very busy, and I thought that “making the switch” might take a while, but if you have existing AdSense and Analytics accounts, it doesn’t seem to take too long. The actual time I spent on a computer to make the changes was probably about 4-8 hours overall, but in calendar time it took a few days because of the AdSense and Analytics integration (waiting), and a few other configuration things I had to wait for. (So, several days in calendar time, but 4-8 hours in actual time.)

It’s also important to note that Ezoic is an AdSense partner, which I discuss more below.

“Trying to find a way to love everyone in a world I don’t even like.”

As a brief note today, here is some source code for a ZIO ZLayer application using Scala 3. In this code I use the ZLayer framework to handle some dependency injection for a small application. (Note that I don’t like to use the word “simple” when writing about software, but I have tried to make this as simple as I can.)

I’ve commented the code below as multiple “parts” so you can see the thought process of creating an application that uses ZLayer. Basically the idea is that your application needs some sort of service — which might be like a database connection pool, HTTP framework, etc. — and then you make that service available to your application with ZLayer’s provideLayer function (or one of its other functions).

The ZLayer example

Given that small introduction, here’s my ZIO ZLayer example, with many notes shown in the comments inside the code:

I know that the idea of a “dream vacation” for most people is time at the beach or a beautiful place like Alaska, but once you get to a certain point in meditation, there’s nothing a person would rather do than meditate. So the dream vacation for a meditator is a peaceful, quiet place — both quiet surroundings, and not having to talk to anyone else — where they can meditate, practice yoga, make simple non-meat meals, and go for quiet walks.

Because I have lived in some sketchy places, and other places where people are constantly cutting the grass and running farm machinery, I’ll add that the location should be secure, and again quiet (or at least a place where you know that loud grass-cutting and outdoor activities happen at a certain time). At some point you need to learn to meditate with those issues, but on vacation, no thanks.

I came across this “Al’s Oasis” sign while traveling around the country. I don't remember what state it was in.

Al's Oasis sign

This is a picture of a beautiful painting named Window of the Poet, by Pyotr Konchalovsky. A friend of mine who died a few years ago liked this quite a bit, so it reminds me of her.

Window of the Poet (painting)

In this interview, the interviewer (Steph) asks Shinzen Young about his daily life, and whether he applies any sort of techniques during his normal day. That eventually leads to him saying:

The biggest change is that I don’t have a preference between enlightenment and non-enlightenment. (Note: This is a big change from when he was younger.)

Then, if I’m intending to meditate — in action, in life, like I’m talking to you now ... now I just started to intentionally meditate as we’re talking.

And I typically meditate in the external visual field, and I’m typically meditating on the process of simultaneous expansion and contraction, causing the world in front of me to arise and then disappear. So I’m now applying a formal technique (as we talk).

Interviewer: So I’m arising and disappearing right now.

(Yes) You’re arising and disappearing from the source, moment by moment. Therefore, you appear to me to be the Source. And therefore, very effortlessly, loveable.

Interviewer: I’ll take it.

At the end of this video that’s titled, Inside Shinzen’s Brain: How Shinzen Experiences his Daily Life, he talks about the one obsession he has: “How smart can I be, how creative can I be, in service of the world?”

As a note to self, I had a problem with the ZIO HTTP library, where it was throwing Netty errors/exceptions like this:

io.netty.channel.AbstractChannel$AnnotatedNoRouteToHostException: null: jsonplaceholder.typicode.com.

The solution to this was to make a couple of changes to my SBT build.sbt file, specifically adding the javaOptions setting below, and forking the running application from SBT:

Mac/macOS FAQ: How do I show a file’s character encoding?

Solution

On macOS, you show a file’s character encoding using the -I option of the file command:

As a brief note today, I was starting to look at a free JSON REST web service that to get stock information, and their JSON for a single stock looks like this:

{
    "Global Quote": {
        "01. symbol": "IBM",
        "02. open": "182.4300",
        "03. high": "182.8000",
        "04. low": "180.5700",
        "05. price": "181.5800",
        "06. volume": "3037990",
        "07. latest trading day": "2024-04-19",
        "08. previous close": "181.4700",
        "09. change": "0.1100",
        "10. change percent": "0.0606%"
    }
}

In a Buddha there has never been
Anything that could be said to be there.
Just as a magician
Does not get caught up in his illusions
And therefore by his knowledge
Is not attached to magic forms,
So also the wise in Perfect Enlightenment
Know the three worlds to be like a magic show.
Liberation is merely the end of error.

~ Gampopa

(I saw this quote in the book Be Love Now by Ram Dass.)

When using ScalaTest, Scala, and SBT, and you want to print output in a ScalaTest unit test that you can see, such as printing to STDOUT with println, I just found out that I can do it using its info function, like this:

If you’re interested in meditation and enlightenment/awakening, the book, I Am That, by Nisargadatta Maharaj, has this terrific conversation, which I have shortened slightly:

M: The Guru is concerned little with the person. His attention is on the inner watcher. It is the task of the watcher to understand and thereby eliminate the person.

Q: But the person does not want to be eliminated.

M: The person is merely the result of a misunderstanding. In reality, there is no such thing.

(later)

Q: When will this happen for me?

M: When you remove the obstacles.

Q: Which obstacles?

M: Desire for the false and fear of the true. You, the person, imagine that the Guru is interested in you as a person. Not at all. (He then clarifies what this means.)

As a brief ZIO 2 example, the end of this Scala/ZIO source code shows how to print information to the console in a ZIO application, both in the success case (STDOUT) and also in the failure case (STDERR):

My 100% FREE “Introduction to Functional Programming” online video training course is now finished! To make things a little easier, here are links to all of the free videos in the training course: