Scala, Java, Unix, MacOS tutorials (page 334)
Android/SQLite FAQ: How do I show a list of SQLite database tables from the Android command line (adb shell)?
You can show a list of SQLite tables by starting the Android adb shell (command line tool), and then properly invoking the sqlite3 command. Here's an example of how this works, with comments shown before each command:
SQLite FAQ: How do I default a SQLite datetime field to the current date and time? (Also asked as, How do I default a SQLite date/time field to now?)
Solution
Use the SQLite current_timestamp function to default a SQLite field to the current date and time, like this:
SQLite FAQ - How do I create a UNIQUE constraint on multiple fields in a SQLite database table?
Just specify the unique constraint in your create table declaration, as shown here:
SQLite FAQ: How do I list the tables in a SQLite database?
To generate a SQLite tables list, just log into your SQLite database with the sqlite3 command, and then issue the "tables" dot command:
Android FAQ: How do I start the Android command line tool (so I can interact with my Android emulator or device)?
You start the Android command line with the adb shell command:
$ adb shell
This makes at least two assumptions:
- You have the Android SDK installed.
- You have an Android emulator (or physical device) running.
When you start the adb shell, you'll see a very simple prompt that looks like this:
I haven't used Android in a little while now, in particular with my new laptop, and the first time I tried running an Android app from inside Eclipse, the Android emulator wouldn't finish starting properly and run my app.
I remember I used to look under the "all apps" icon, and could sometimes find my app was actually loaded, but in this case, it wasn't loaded at all.
While XML parsers work great for well-formed XML, out in the 'real world' internet, you can't count on HTML being XHTML, or even being well-formatted. As a result, various 'HTML cleaner' libraries for Java have appeared. They attempt to clean up the HTML so you can parse it.
While XML parsers work great for well-formed XML, out in the 'real world' internet, you can't count on HTML being XHTML, or even being well-formatted. As a result, various 'HTML cleaner' libraries for Java have appeared. They attempt to clean up the HTML so you can parse it.
Scala JavaBean FAQ: How do I create the Scala equivalent of a JavaBean in Java (a Scala JavaBean)?
There are times when you're working with Scala where backwards compatibility with Java and JavaBeans is required. I ran into this recently with the Java Snakeyaml library (see my Scala YAML parsing with Snakeyaml tutorial).
Summary: A Scala YAML parsing example using the Snakeyaml parser.
If you need some Scala YAML parsing examples using Snakeyaml parser, you've come to the right place. I just worked through some Snakeyaml issues related to Scala, in particular converting YAML to JavaBean classes written in Scala, so I thought I'd share the source code here.
As quick post here today, if you need a Scala REST client function, the following source code should be able to work for you, or at least be a good starting point. I’ve been using it in several applications today, and the only thing I think it needs is the ability to set a connection timeout and socket timeout, and I share the code for that down below.
I just worked through some Scala Lift-JSON issues, and thought I'd share some source code here.
In particular, I'm trying to parse a JSON document into Scala objects, and I'm using Lift-JSON to do so. One of the things I'm doing here is to parse some of the JSON text into an array of objects, in this case an array of String objects.
First, here's the Scala source code for my example, and then a description will follow:
If you haven't been following me on Twitter, I've been working on a Mac Siri app lately during my spare time. The app itself is actually inspired by the smart house named "SARAH" on the tv show Eureka. The app itself is written in Scala, and is free and open source.
Scala JSON FAQ: How can I parse JSON text or a JSON document with Scala?
As I continue to plug away on my computer voice control application (SARAH), last night I started working with JSON, specifically the Lift-JSON library (part of the Lift Framework), which seems to be the preferred JSON library of the Scala community.
Sometimes when I write small Scala scripts and programs I loosen the reins and use a var. When you do this and you may need to occasionally create a null variable (a var, not a val), such as when you need to declare a variable right before using it in a try, catch, finally block.
I've posted a lot of Scala source code examples out here lately, and as I keep trying to learn more about passing one function to another function in Scala (function callbacks), here's another example showing how you can use Scala's functional programming approach to clean up some Java Swing code:
While this may not be the recommended approach, here's how I currently handle class casting in Scala.
In Java you can cast a class like this:
Recognizer recognizer = (Recognizer)cm.lookup("recognizer").asInstanceOf;
As you can see, this is done with the "(Recognizer)" class cast operator.
In Scala you can't use the same syntax, but you can come close, like this:
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is one of the shorter recipes, Recipe 6.2, “The Scala equivalent of Java’s .class.”
Problem
When an API requires that you pass in a Class, you’d call .class on an object in Java, but that doesn’t work in Scala.