Ruby: Concurrent::ThreadLocalVar

Web framework behemoth Ruby on Rails is using the concurrent-ruby project for some internal book-keeping. I like that project. A bursting-packed tool bag of ready-to-use widgets and doodads – great, if you know how to use them.

One of those things is ThreadLocalVar. A variable? Local to a… thread?

Its documentation’s example is eloquent about what it does for you: In thread t1 we can read the ThreadLocalVar and have its starting value. Then, we can locally set and keep using that variable, without changing t2‘s value, nor the starting v‘s value.

Here, this is the example linked above:

v = ThreadLocalVar.new(14)

t1 = Thread.new do
  v.value #=> 14
  v.value = 1
  v.value #=> 1
end

t2 = Thread.new do
  v.value #=> 14
  v.value = 2
  v.value #=> 2
end

v.value #=> 14

I glanced at this, when Rails 6.1 is getting this new feature: being able to accept some deprecation warnings, while failing on all the other. See this Pull Request for usage in context.

I said book-keeping things, above: The only file in Rails which is currently using ThreadLocalVar is the one which manages deprecation warnings, ActiveSupport::Deprecation.

This was a short call-out of one of the Ruby Concurrency library’s many small tools, I can only invite you to explore it further. For example, by looking at these issues that are looking for a contributor.

A note on using parallel RSpec in CircleCI

Using parallel builds with RSpec in CircleCI? Yeah!

Perhaps you need a way to output what was actually run?

A ready-to-paste CLI invocation.

TL;DR: YAML example for RSpec in parallel on CircleCI with explicit --seed and reproducible CLI invocation.

What’s in the steps?

CircleCI steps start out looking a bit like these:

  • Run the tests

When CircleCI runs your tests in parallel, it offers a “split up the test suite” system based on earlier tests’ timings. The timings are gleaned from a JUnit XML format.

  • Run the tests
    • with a JUnit XML formatter

When the splitting the test suite selection now can be done by the CircleCI tool, pass the selections to RSpec.

  • Run the tests
    • with a JUnit XML-based formatter
    • on a subset of the files

When RSpec starts, you have set it to run in random order, to expose sequence-related bugs. Now, we are going to need to see this value, so in order to do that, we pick a number ourselves. Then you set the --seed to a given value, e.g. an integer between one and a million.

  • Run the tests
    • with a JUnit XML-based formatter
    • with a given ordering seed
    • on a subset of the files

Now when a test has failed, you, the human reader, needs a pasteable command-line invocation, to reproduce the error in your local computer environment.

  • Output a command of what will run
  • Run the tests
    • with a JUnit XML-based formatter
    • with a given ordering seed
    • on a subset of the files

Example YAML steps

This example is real-world: creates the necessary directories, stores artifacts.

      - run: mkdir -p test-results/rspec
      - run:
          name: run rspec tests
          command: |
            TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
              circleci tests split --split-by=timings)"
            SEED_NUMBER="$(shuf -i 1-1000000 -n 1)"
            TEST_FILES_SPACE_SEPARATED="$(echo $TEST_FILES | paste -s -d ' ' -)"
            echo "INCLUDE_SLOW_SPECS=1 bundle exec rspec --seed ${SEED_NUMBER} ${TEST_FILES_SPACE_SEPARATED}"
            bundle exec rspec \
              --seed $SEED_NUMBER \
              --format progress \
              --format RspecJunitFormatter \
              --out test-results/rspec/results.xml \
              --format progress \
              $TEST_FILES
      - store_test_results:
          path: test-results
      - store_artifacts:
          path: test-results
          destination: test-results
      - store_artifacts:
          path: coverage
          destination: coverage

Bike park infrastructure

Pollards in the shape of an inverted U, spaced widely allows two bikes to use each.

A new-to-me set of bike parking has been set up at Nobeltorget. They look ordinary, but since they were new, I wanted to show them off here.

These larger things are nice, since you don’t have to press the front wheel of the bike into anything to make it work. Just lean against the pollard and lock your bike. Ah, you need a chain or the equivalent. Always.

The short stories of Alistair MacLeod, and the difficulty of communication

Having read a handful of Alistair MacLeod short stories on the plane: he describes a hard life of the people of Atlantic Canada’s fisheries, mines and farms.

Some of these stories hit you right in the feels.

Literature is wonder.

On the way to Canada, I read the very meta novel The Hour of the Star, by Brazilian modernist Clarice Lispector. That book also describes a hard life of limited possibilities, but the authorial voice couldn’t be more different. Someone summed up Lispector’s writing as “a deep distrust of the possibilities of the novel.” A wry, ironic, acerbic commentator on the writing of the story you’re reading, Lispector never tells a story from A to Z. Recommended for the adventure.

This makes me recall a failed exchange of book excitement I had this week.

In Charlottetown, during the lunch break, as I was making my way to 84 Fitzroy, after a very good cashew stir-fry with Peter at Mad Wok, I saw a bookseller’s, and was lured in by the double stacks of books in the shelves. After asking for some impossible things, I pored over the Literature section. It had several shelves – also packed, double rows. There was a copy of McTeague, the novel silent-film director Erich von Stroheim adapted into his very long Greed. Having seen this, I turned to the long-suffering bookseller, and tried to communicate the awesomeness of that cinematographic achievement (a very, very long director’s cut is said to have existed), but failed. Booksellers have to put up with a lot of customers like me, I guess: overflowing with inspiration from the presence of books. He was gracious about it all. A pro.

See Von Stroheim on Wikipedia for more gushing about that film.

I just thought about the fact that I know nothing about MacLeod. I should read all the short stories before learning more about the MacLeod biography.

Update: the notes on the Letterists and their insistence on their own radical originality, they made me laugh out loud. Good at naming, though!

Bryan Cantrill rereads Soul of a New Machine and has excellent comments

I talked to people about blogging this weekend. Words like The Golden Age of blogging were used. (That era passed, if you hadn’t noticed.)

Is it quizzical to want to have the kinds of slow, async conversation blogging can offer? Is it tilting at windmills to just do it anyway? Even if my interlocutor group would be down to the same group of people with whom I learned of blogging, it’d still be worthwhile, for me.

One computer personality who’s made some impact on me is Bryan Cantrill. Here, I tried to link to a video in which he talks about the re-closed-sourcing of Open Solaris. But instead, here’s his Talks page, which chronicles a prolific output. Also: “Goodbye, Sun“.

Bryan blogs infrequently, but with a serious tone. (His blog is calledThe Observation Deck.) Today, I saw a tweet of his, and I went to the bio and to the blog link. I reminded myself that I ought to add his feed to my reader. But I got distracted by this post where the comments are as good as the post.

Recommended: that book, and to restart your blogging.

Fantasy Cartography

The conference, oh unconference, had sessions on diverse topics such as “Phone nerding”, “Death Café” and “Coastal preservation”. These were proposed during an agenda session, placed in a matrix on the wall, and ta-da, that’s our schedule.

The second day (today, Saturday) will have the DO theme. In a spirit of sharing, and stressing the importance of having fun, I proposed to lead a session on how to make fantasy maps. So, that was put on the schedule, and I’m preparing links to show people. If you missed the session, or are curious, here are some things online which inspire me.

People sitting in a circle, looking at Peter Rukavina organising a wall-mounted conference schedule in real-time. Ton Zylstra facilitates.
Unconference prep day 2. Theme “DO”.

Dyson does maps with felt-tip markers. Beautiful monochrome maps. Crosshatch! Here’s a printable sheet of dungeon map tutorials.

The Cartographers’ Guild is an online forum where people who make fantasy maps share techniques and tool tips. Technical, computer-oriented. More “Gimp or Photoshop?” than “Which watercolor brush?”.

The Fantastic Maps website’s Category of tutorials were good at showing individual drawing techniques.

And in the joyous spirit of DM Scotty, the video-series maker and crafter of roleplaying game materials (made from scraps and quite quickly): be sure to express your exuberance and joy of having created. Praise your own work.

Digital

Output, after-the-fact

Some snapshot photos of the thing I made during the workshop:

First, an outline, with pencil, then watercolor pencil, then a waterline using a felt-tip pen.
Lots of things added.
Pulled the watercolor of the edges into the map picture.

A bonus session

I was inspired to run the event again, after a bibimbap lunch, and was joined by seven-eight other mappers. The mountain range above came from someone asking how to draw a mountain range. “Let’s find out!”

Also, during the session, the mappers began telling stories about their different maps’ dragons, actually a pack of five wild dragons, fiercely whipped by their pirate riders, hungry for gold. The dragons were addicted to razing castles, souring the pirates’ relationships to royalty.

Here’s the latest version of the Plugh map.

Keith’s retro computers

I walked upstairs in the office I work in this week and I met familiar faces, people who knew my name since a long while. A good feeling, being somewhere and being recognized.

An Amiga 2500, with a peripheral to read disk images off a USB drive.
A fancy C-64 set-up.
Some of these are rare. The VIC 20 ENCYCLOPEDIA, or whatever it was, had a list of all the components in the machine. Complete with the name of the maker and a description of its function.

I was shown the collection. How some items were handed over in exchange for “a bottle of iced tea” or for another vintage computer. The collection was focused. A VIC 16, black. A TRS-80. VIC Cartridges.

I related a bit of the local scene. Gubbdata. Linus Åkesson.

Retro games

On nanochess.org you can see their re-issues of Retro Games. 

That is: Games re-published in the past few years, for the Colecovision platform.

Also, this charming Jeff Minter (Llamasoft) game:

Hover Bovver (Intellivision, 2018)

I learned about this because I follow amazing programmer and writer Jess Frazelle on social media. You should follow her sometimes-updated weblog. If you like.

Today, at Silverorange, I saw a Coleco Adam home computer. Never saw one before. It came with a snazzy printed manual. Was it owned by Keith? This happened on the same day that I learned about the above retro games.

PEI, again

We’re on PEI, the Gotland of Canada. We’re going to this unconference.

Lots of things have changed in the interim since my last visit. Most things stay the same.

Vegan places to eat: at least two cafés with food in them. One of them was closed for renovations, so I got to hear about the other one. Kombucha on tap.

Coffee is still good. Receiver Coffee has opened a second location.

The Farmers Market is still good. I will revisit in the weekend.

The folks at Silverorange are still there, working. Gorgeous office building, what a remodeling. These people are nice, caring and interested, generous and helpful. They’re now also a distributed workplace, with half the team in Charlottetown. Me and Steven Garrity got to catch up a little by their coffee maker, and over a lunch sandwich. (A little short of breath, having just read Nick Burka’s tribute to Martha. Found via Steven.)

Me and Luisa got to visit Fountain Pen Night at a bookstore – a wonderful group of people diving deep into their subject matter. Specialist-colored inks, striations, inkwells, writing cabinets, really good writing paper, the gift of mailing someone a letter. At the end of the circle of people talking, I was asked if I had anything to share. “Buy art supplies that are outside your comfort zone, and your practice will widen.”

I’ll try to share more what goes on here. Spring is happening. Malmö has radiant summer days, right now, but on PEI, the trees are budding.

Link: on TLA+ command-line support

This was a pointer to whet your appetite for more TLA+. It also mentions Hillel Wayne’s book on using the system.

Now following @bellmar!