Blogs

A Christmas Story

From time to time I write little stories that have nothing to do with programming or technology; this is one of those stories. So, if you’re only here for the tech, you’ll want to skip this one.

I was at a Christmas party, making a drink in the kitchen of a friend’s house, when Angie came in and started talking about something. The details don’t matter -- we were always talking about something. We met in high school, and we’ve been talking every since.

A Salsa dancing lesson

From time to time I write little stories that have nothing to do with programming or technology. This is one of those stories, so if you’re only here for the tech, you’ll want to skip this one.

As I stretched in Utthita Parsva Konasana, I took a break from my concentration and indulged in a moment of both reflection and forethought. For five days we drank tequila and sangria, swam in the warm ocean water, and even hiked in a Mexican jungle, but tonight it would be different: we would learn how to dance Salsa.

Converting PDF content to plain text with Scala (or Java)

I recently wrote a little application to convert pages from a PDF to plain text. The GUI portion of the application looks like this:

As you can see, the application just needs the name of a PDF file to convert, along with the page you want to start at and the page you want to end at. There are several ways I could make the application more convenient to use, but since I don't plan to use it that often, I can deal with its limitations.

How to get the IP address of a Linux system from the command line

One way to to get the IP address of a Linux system from the Linux command line is this:

$ hostname -I

That’s the hostname command, followed by a capital letter i as a command line parameter. On my Raspberry Pi system, this command returns its IP address -- and only its IP address -- like this:

10.0.1.9

It’s nice that this command returns only the IP address, because that means I don’t have to pipe together several commands to get what I need.

Functional programming - A collection of good Monad tutorials

As the title of this blog post implies, this article contains a collection of Monad tutorials. I’ll only include the good ones as I find them (because there’s obviously no value in reading a bad Monad tutorial).

Here is the current list:

How to get the default system font in a Java/Swing application

I haven’t tested this with other Java components, but if you want/need to get the “system font”, this code gets the default system font from a JEditorPane component:

val outputArea = new JEditorPane
val fontFamily = outputArea.getFont.getFamily

That code is written in Scala, but as you can see, it converts easily to Java. On Mac OS X 10.10, fontFamily ends up being “Lucida Grande”.

How to convert a stack trace to a string for printing with a logger

As a quick note today, I used to get the text from a stack trace in Java or Scala 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.

But recently I learned the following technique, which does a much better job of keeping the formatting when getting the text from a stack trace, and then writing it to a file with a logger:

Syndicate content