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

Kotlin FAQ: How do I iterate over a Map in Kotlin?

Solution: Here’s an example that shows how to iterate over the elements in a Kotlin Map using a for loop:

val map = mapOf("a" to 1, "b" to 2, "c" to 3)

for ((k,v) in map) {
    println("value of $k is $v")
}

I saw the following image on this Twitter page:

and immediately became curious, “How can I create something like that Ruby %Q function in Scala, but where each line becomes a string in a list, i.e., a Seq[String]?”

“It is not the critic who counts; not the man who points out how the strong woman stumbles, or where the doer of deeds could have done them better.”

“The credit belongs to the woman who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually strive to do the deeds; who knows great enthusiasms, the great devotions; who spends herself in a worthy cause; who at the best knows in the end the triumph of high achievement, and who at the worst, if she fails, at least fails while daring greatly, so that her place shall never be with those cold and timid souls who neither know victory nor defeat.”

~ “The Man in the Arena” speech by Teddy Roosevelt, with a few minor changes, which I was reminded of by this article

As a brief note to self, here’s some Laminar source code that shows how to create a div in Laminar, as well as some settings/elements in that div, as well as one way to handle a reactive button click:

In my first Laminar tutorial I showed how to set up a Scala/sbt project to use Laminar to render “static” HTML code. Then in Laminar 102: A reactive “Hello, world” example, I showed how to create a small, reactive Laminar example, that sends signals from one widget to another using observables and observers.

In my experience, the next thing you’ll need to know about Laminar is routing, i.e., how to transition from one page to another in a single-page app (SPA). Therefore, in this tutorial I’ll show how to implement that for very small applications.

In my first Laminar tutorial I showed how to set up a Scala sbt project to use Laminar, and then showed a “static” example — i.e., there were no moving parts. Please see that tutorial first if you’ve never used Laminar.

BUT, because Laminar is meant for writing reactive applications with observables and observers, this tutorial begins to show its reactive concepts.

This page contains a list of my favorite “mindfulness reminder” quotes. In particular these are short, concise quotes that I think work well with my “Just Be” mobile app.

Just Be is currently an app for Android users. If you haven’t seen it before, this is what the reminders/notifications look like when you receive them on an Android phone or tablet:

[toc hidden:1]

I recently started a new Scala project that uses the Scala/Scala.js Laminar library for frontend development (i.e., as a JavaScript replacement).

Laminar is a library that’s built on top of Scala.js to let you build “reactive” web applications with observables, and in this tutorial I’ll show how to create a static “Hello, world” application from scratch. Once we get past these basics, I’ll show in Part 2 of this series how to create a reactive single-page application (SPA) with Laminar.

When I first saw Scala code like this ~12 years ago, my initial thought was, “Wow, maybe I need to think about a different career”:

def race[A, B](lh: IO[A], rh: IO[B])(implicit cs: ContextShift[IO]): IO[Either[A, B]]

But in the end, as Rocky once said, it ain’t so bad. :)

Rocky: You ain’t so bad

For many years I struggled with how to combine two of my main interests, Zen and work. I have read that the Zen mind is the mind before thinking, so it seems like Zen and work must be totally unrelated; you need your mind to work. And then over time I came to understand phrases like, when working, just work.

This article contains a collection of quotes that have been helpful to me in understanding the relationship between Zen and work. Please note that I don’t wrap each quote in double quotes, and I also try to attribute each quote to the correct author/speaker. If you’re interested in how to combine Zen and work, I hope you’ll find them helpful.

At some point somebody was like, “Let’s get a mast cell — a type of white blood cell — from a bone marrow biopsy, magnify it 1,000 times, piss it off, and see what happens.”

The result? Ka-boom! It looks like a little firework went off when it released its histamine, tryptase, serotonin, superoxide, heparin, thromboxane, PGD2, PAF, and other granules.

That’s pretty much what it feels like, lol. I used to tell doctors that it felt like I had been drugged, and indeed, I was.

(Image from this nih.org research paper.)

MCAD: What an activated mast cell looks like

Over on my Valley Programming website I wrote a little User Story Mapping Example Using Facebook. Whether people currently have a Facebook account or not, at one time almost everyone did, so it makes for a good example when running a story mapping workshop. See that link for more details.

A User Story Mapping Example Using Facebook

This is an excerpt from the Scala Cookbook, 2nd Edition. This is Recipe 3.10, Using Java Collections in Scala.

Problem

You’re using Java classes in a Scala application, and those classes either return Java collections, or require Java collections in their method calls, and you need to integrate those with your use of Scala collections.

Solution

Use the extension methods of the scala.jdk.CollectionConverters object in your Scala code to make the conversions work. For example, if you have a method named getNumbers in a public Java class named JavaCollections:

This is an excerpt from the Scala Cookbook, 2nd Edition. This is Recipe 23.9, Simulating Dynamic Typing with Union Types.

Problem

When using Scala 3, you have a situation where it would be helpful if a value could represent one of several different types, without requiring those types to be part of a class hierarchy. Because the types aren’t part of a class hierarchy, you’re essentially declaring them in a dynamic way, even though Scala is a statically-typed language.

Solution

In Scala 3, a union type is a value that can be one of several different types. Union types can be used in several ways.

In one use, union types let us write functions where a parameter can potentially be one of several different types. For example, this function, which implements the Perl definition of true and false, takes a parameter that can be either an Int or a String:

Flutter 3 was released in mid-May, 2022. You can read more about it here on 9to5google.com, and on other websites.

Flutter 3 release, May, 2022

As a brief note, SQLite doesn’t have date/time (datetime) fields, so when you want to use a datetime field with Flutter and Dart, you have to do something else.

My choice was to store my date/time data as a SQLite INTEGER field. I did this so I can query and sort that field easily myself. The benefit of storing a datetime field as a TEXT field is that you can read it easier, but I think an INTEGER field is a little easier to work with, though YMMV.

“Your ego is writing checks your body can’t cash.”

~ from the movie, Top Gun

Reporting live from Longmont, Colorado in May, 2022, I’m glad to report that I am now a Certified ScrumMaster (CSM) and Certified Scrum Product Owner (CSPO).

Sometimes this doesn’t feel like much, but in retrospect it’s amazing how much I know now compared to what I used to know. Last October I couldn’t have gotten many answers right on the practice tests and real test, but now the answers are obvious. So kudos to the Scrum Alliance for their rigorous certification training courses.

Certified ScrumMaster and Product Owner, Longmont, Colorado

I don’t watch many movies or tv shows, at least not as many as most people. The reason I don’t is because I experience lucid dreams most night that Hollywood can’t compare to. I don’t know why I have these dreams, but I have had them since I was a young child, and that’s just the way things are. This story from May 2, 2022, is just one example.

~~~

There was a bomb in the building.

Somehow I knew that.

I remember walking into a government-style building that had a parking lot directly in front of it. If you walked into the front doors, went down the hallway to the right, and then took your first left, there was a device on the floor that looked like a boxy, 1970s-style tape recorder, but it was really a bomb.

So I began working with a friend to evacuate the building. He went one way, I went the other.

As I ran around the building, Lori — my friend who died last summer — ran up to me and said in a panic, “He knows everything about you. Everything! You have to run.” I looked at her and tried to make sense of how she was here and what she was saying, but she was terrified and screamed, “RUN!” Then she ran away in the direction I had just come from.

I don’t agree with everything Nathaniel Hackett has done to start his tenure with the Denver Broncos, but I do agree with this quote about trying to create a good and happy work environment:

“You want them to feel an environment that they want to come into, and they’re excited to come into. That’s all you can do, that’s what you’re trying to create.”