If you ever need to convert HTML to plain text using Scala or Java, I hope these Jsoup examples are helpful:
I have a 19" monitor on the counter between my kitchen and living room, and it’s powered by a Raspberry Pi. I use the Linux Phosphor screen saver to show a scrolling “news and stock ticker” on the display, which I’ve programmed to show news from several different sources (Atom and Rss feeds, along with other news and data sources). An old version of the display looks like this:
Today I added a new “Word of the day” feature to the display, and as with all of the other code, I wrote a Scala shell script to generate the output.
If you ever need to parse JSON stock data from alphavantage.co using Scala, here’s a test class I just wrote that uses Lift-JSON.
The JSON data format
First, here’s the JSON I get back from them:
This is a little Perl script I wrote to parse a CSV file I periodically download from Google AdSense. It does the following things:
Lately I have been thinking about writing a functional programming book, and if I decide to do that, I might include a variation of this Ward Cunningham example of how to parse HTML table tags recursively. His code is written in Java, and you can read about it here.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 15.4, “How to parse JSON data into an array of Scala objects.”
You have a JSON string that represents an array of objects, and you need to deserialize it into objects you can use in your Scala application.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.5, “How to process a CSV file in Scala.”
You want to process the lines in a CSV file, either handling one line at a time or storing them in a two-dimensional array.
Combine Recipe 12.1, “How to Open and Read a Text File” with Recipe 1.3, “Splitting Strings”. Given a simple CSV file like this named finance.csv:
Scala FAQ: How do I parse a number (
Float, etc.) from a
String in Scala?
to* methods that are available on a
String (courtesy of the Scala
My last edits to the Scala Cookbook were in June, 2013, and after all this time there aren’t many things I wish I had added to the Cookbook. Yesterday I ran into one thing that I don’t think I included in the Cookbook: How to process multiple
Option values in a Scala
for loop (for comprehension). Here’s a quick look at how to do this.
For the impatient
For those who just want to see a for comprehension that processes multiple input
Option values, here you go: