A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

URLs open in Safari instead of Chrome from Mac OSX Terminal

To set the correct default browser on OSX, go to System preferences | General | Default web browser.

If the default browser is correct but Terminal is still not behaving correctly, then change the default browser, and change it back again.

TIOA-TIOA FTW

(source)

Detailed Ruby notes

A list of somewhat advanced Ruby topics:
  • Scope of constants, and namespace: link, link.
  • Keyword arguments: link.

How to apply a stash by name in git

1) In git it's easy to retrieve stashes by number like this:

git stash apply stash@{5}

But that number changes as you add more stashes to the list.

2) Instead you could perform some jiggery-pokery in bash to look up the stash by name:

git stash apply $(git stash list | grep "$NAME" | cut -d: -f1)

You can apply multiple stashes as long as they don't overlap.

3) Or you could save the commit and refer to it by tag:

git commit -m'The usual changes to aid debugging'
git tag foo
git reset --hard HEAD^
git cherry-pick -n foo

(-n is --no-commit)

This way if they overlap you can use git's merging/conflict mechanism.

(source)

Adventures in Scala 1.0

Mac OSX:

brew install sbt@1

Try the "Hello, World" example from scala-lang.org:

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}

Run it:

Go [15:46:  learning-scala$] sbt run
[warn] No sbt.version set in project/build.properties, base directory:~alt/learning-scala
[info] Set current project to learning-scala (in build file:~/alt/learning-scala/)
[info] Compiling 1 Scala source to ~/alt/learning-scala/target/scala-2.12/classes ...
[info] Non-compiled module 'compiler-bridge_2.12' for Scala 2.12.4. Compiling...
[info]   Compilation completed in 11.024s.
[info] Done compiling.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:~/.sbt/boot/scala-2.12.4/org.scala-sbt/sbt/1.1.0/protobuf-java-3.3.1.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of com.google.protobuf.UnsafeUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[info] Packaging ~/alt/learning-scala/target/scala-2.12/learning-scala_2.12-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[info] Running HelloWorld 
Hello, world!
[success] Total time: 16 s, completed 9 Feb 2018, 15:47:03


Well, it worked. But that's a helluva lot of warnings for very little code!

A colleague informs me how to set up another Hello World that's known to work:

sbt new https://github.com/scala/scala-seed.g8
(enter name: hello)
cd hello
sbt run

...but I still get the warnings, although the code does output "hello" as expected.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:~/.sbt/boot/scala-2.12.4/org.scala-sbt/sbt/1.1.0/protobuf-java-3.3.1.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of com.google.protobuf.UnsafeUtil

It seems I've just joined Scala at a time when 1.0 has recently been released, and lots of existing code does not exactly make the compiler happy yet.

Note: The warning was not displayed the second time I ran the program. Somehow it remembers.

To do:
  • Find out how to avoid the warning.
  • Find out how to repeat the warning!