Here’s a way to ensure that only one instance of your application runs at a time. Perhaps it updates a resource and you need to prevent duplicate updates. Or, in another use, I recently wanted to make sure an application was always running. So I wrote a cron job to periodically start the program; if [...]
Continue reading about SingletonApp: How to run only one application instance at a time in Scala
Sometimes you need the top k items in a list. A naive way to do it is to sort the list, then take the first k items. The problem with that approach is that you don’t need to sort the whole list, so it’s inefficient and becomes more so as the list length, n, increases [...]
If you’ve played around with the Option class, you know that it allows you to note that no value is available and do so without nulls. For example, using getOrElse() you can access a value or a default when no value is present:
scala> val a:Option[Int] = Some(5)a: Option[Int] = Some(5)scala> val b:Option[Int] = None b: [...]
// Sum the values in a list
val sum = (0.0 /: list){ _ + _ }
// What it says: it’s an abbreviated form of
// list.leftFold(0.0) { (s,i) => s + i }
// Find the minimum value in a list
val minValue = list.reduceLeft( _ min _ )
// What it says: Note that it’s reduce, not fold. [...]
Trying to start a program created with the eclipse Scala plugin, I saw an error that the main class couldn’t be found. That was cryptic, as there was a main. Stranger still, this is a program I had run successfully before.
The first part of solving the problem was to look for clues in the [...]
Continue reading about Scala Eclipse Plugin Error: Scala Signature
In NetBeans, creating a runnable jar for your Scala program is even easier. It’s done automatically when you build your project. The compile output even reminds you how to run the jar file.
The first time I did it, I saw an error about finding a Scala object. Solve that by adding the scala-library.jar to your [...]
Continue reading about Creating Single-file Runnable Jars in Scala with NetBeans
How do you create a single runnable jar that contains all the files it needs to run? This is one of those questions that should be easier to answer. Here’s how to do it in eclipse and NetBeans.
First, eclipse, following the post here:1. Create a Java class to run your Scala main:
package scala.loader;
import java.util.*;
public class [...]
Continue reading about Creating Single-file Runnable Jars in Scala with eclipse
It’s easy to use and update the git version of Configgy and other code hosted at github. If you don’t have git, you can use MacPorts to install it:
$ sudo port install git
Then clone the Configgy repository with
$ git clone git://github.com/robey/configgy.git
Then cd into the top-level directory and build as described below.
When you want [...]
Continue reading about Using git to update Configgy and other github-hosted code
Configgy is a great configuration and logging library for Scala. You can read info/examples on the release page or git the current repository.
To install, just download and, in its directory, type
$ant package
( The ‘$’ is your terminal command-line prompt. Don’t type it.)
If you see the following errors:
[scalac] Compiling 16 source files to /Users/Gary/Development/scala/configgy/target/classes [scalac] [...]
Nice talk about alternatives to shared-state concurrency on the JVM. Notice the gradual acceptance by the community that shared-state concurrency is too hard to get right and must be abandoned. Alternatives are being sought; this talk discusses STM, Actors, and Dataflow. I also hear more death knells for Java. Due to the required language integration [...]
Continue reading about Think Java shared-state concurrency is hard? That’s ok; it’s dead.