convert

Examples of converting Scala 2 code to Scala 3 with Dotty 0.20

Table of Contents1 - Significant indentation syntax with traits and classes2 - match expressions3 - for loops and if/else (and `do` and `then`)4 - try/catch syntax5 - A couple of braces not removed6 - More Dotty/Scala 3 changes

With the Dotty compiler you can convert Scala 2 code to the new Scala 3 syntax, and with the Dotty 0.20.0-RC1 release on November 4, 2019, I thought I’d see how some of the conversions work. Almost all of the changes shown below have to do with the elimination of curly braces and the use of “significant indentation” syntax, but in one example I also show the then and do keywords.

Scala/Java: How to convert a stack trace to a string for printing with a logger

As a quick note, I just got a little bit better about logging stack traces when writing Java or Scala code. In Scala I used to get the text from a stack trace and then log it like this:

// this works, but it's not too useful/readable
logger.error(exception.getStackTrace.mkString("\n"))

In that code, getStackTrace returns a sequence, which I convert to a String before printing it.

How to batch-convert Mac BMP, JPG, PNG image files, free

Mac batch image conversion FAQ: How can I “batch convert” images from one image format to another on a Mac, such as BMP to JPG, or PNG to JPG?

As I mentioned in my earlier Mac batch image resizing tutorial, the Mac OS X Automator application is my new best friend. Besides letting you easily batch resize images very easily, the Automator also lets you easily batch create thumbnails for images, and also lets you convert images from one image format to another (BMP to JPG, PNG to JPG, etc.).

Here’s a quick look at how to use the Mac Automator to “batch convert” images from one file format to another, including image file formats like BMP, GIF, JPEG, and PNG.

How to convert a Java array into a Stream

If you ever need to convert a Java array into a Stream, there are at least two ways to do it.

1) Converting an array to a Stream

First, to convert the entire array to a Stream, use the Stream.of static method like this:

A little Scala project to convert AsciiDoc to clean, simple HTML

Table of Contents1 - A shell script solution2 - A JavaFX GUI3 - Summary

I recently started using AsciiDoc to write a new book. A great thing about it is that unlike Markdown, you can use AsciiDoc to write a book and get all of the features you want in a book, including linking between anything, captions for tables and figures, indexes, etc. Because this got me started using AsciiDoc I thought, “Wouldn’t it be nice if I could also use AsciiDoc to write blog posts like this one?”

Sadly, I quickly ran into a problem: I couldn’t find a good way to convert AsciiDoc into HTML, or even Markdown. There are tools to convert AsciiDoc to HTML, but for some reason they take the approach of including a ton of markup in the HTML (divs, spans, and attributes), and as far as I can tell there’s no way to turn off that markup.

How to convert asciidoc to markdown

It turns out that converting AsciiDoc to HTML without including a bunch of undesired CSS is a problem, and converting AsciiDoc to Markdown is also a problem. The page I linked to shows the best way I’ve found to convert AsciiDoc to Markdown, which can then be converted to CSS-free HTML. In case that page ever disappears, the basic commands are:

Install pandoc and asciidoc:

sudo apt install pandoc asciidoc

Convert asciidoc to docbook:

asciidoc -b docbook foo.adoc

Convert docbook to markdown:

How to convert Docbook to AsciiDoc

If you ever need to convert Docbook to AsciiDoc, this Pandoc command seems to work well:

pandoc --wrap=none -f docbook -t asciidoc \
       DocbookFile.xml > AsciiDocFile.adoc

How to convert HTML to AsciiDoc with Pandoc

If you ever need to convert HTML to AsciiDoc, I just used this Pandoc command and it seems to work well:

pandoc --wrap=none -f html -t asciidoc myfile.html > myfile.adoc

The wrapping part of that command isn’t 100% necessary, but if you don’t use it, Pandoc will wrap the plain paragraph text, which I don’t like because I’ll be editing the resulting AsciiDoc text.

Here’s some of the AsciiDoc text that this command generated: