| Andrew Cooke | Contents | Latest | RSS | Twitter | Previous | Next


Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.

Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.

Personal Projects

Lepl parser for Python.

Colorless Green.

Photography around Santiago.

SVG experiment.

Professional Portfolio

Calibration of seismometers.

Data access via web services.

Cache rewrite.

Extending OpenSSH.

Last 100 entries

British Words; Chinese Govt Intercepts External Web To DDOS github; Numbering Permutations; Teenage Engineering - Low Price Synths; GCHQ Can Do Whatever It Wants; Dublinesque; A Cryptographic SAT Solver; Security Challenges; Word Lists for Crosswords; 3D Printing and Speaker Design; Searchable Snowden Archive; XCode Backdoored; Derived Apps Have Malware (CIA); Rowhammer - Hacking Software Via Hardware (DRAM) Bugs; Immutable SQL Database (Kinda); Tor GPS Tracker; That PyCon Dongle Mess...; ASCII Fluid Dynamics; Brandalism; Table of Shifter, Cassette and Derailleur Compatability; Lenovo Demonstrates How Bad HTTPS Is; Telegraph Owned by HSBC; Smaptop - Sunrise (Music); Equation Group (NSA); UK Torture in NI; And - A Natural Extension To Regexps; This Is The Future Of Religion; The Shazam (Music Matching) Algorithm; Tributes To Lesbian Community From AIDS Survivors; Nice Rust Summary; List of Good Fiction Books; Constructing JSON From Postgres (Part 2); Constructing JSON From Postgres (Part 1); Postgres in Docker; Why Poor Places Are More Diverse; Smart Writing on Graceland; Satire in France; Free Speech in France; MTB Cornering - Where Should We Point Our Thrusters?; Secure Secure Shell; Java Generics over Primitives; 2014 (Charlie Brooker); How I am 7; Neural Nets Applied to Go; Programming, Business, Social Contracts; Distributed Systems for Fun and Profit; XML and Scheme; Internet Radio Stations (Curated List); Solid Data About Placebos; Half of Americans Think Climate Change Is a Sign of the Apocalypse; Saturday Surf Sessions With Juvenile Delinquents; Ssh, tty, stdout and stderr; Feathers falling in a vacuum; Santiago 30m Bike Route; Mapa de Ciclovias en Santiago; How Unreliable is UDP?; SE Santiago 20m Bike Route; Cameron's Rap; Configuring libxml with Eclipse; Reducing Combinatorial Complexity With Occam - AI; Sentidos Comunes (Chilean Online Magazine); Hilary Mantel: The Assassination of Margaret Thatcher - August 6th 1983; NSA Interceptng Gmail During Delivery; General IIR Filters; What's happening with Scala?; Interesting (But Largely Illegible) Typeface; Retiring Essentialism; Poorest in UK, Poorest in N Europe; I Want To Be A Redneck!; Reverse Racism; The Lost Art Of Nomography; IBM Data Center (Photo); Interesting Account Of Gamma Hack; The Most Interesting Audiophile In The World; How did the first world war actually end?; Ky - Restaurant Santiago; The Black Dork Lives!; The UN Requires Unaninmous Decisions; LPIR - Steganography in Practice; How I Am 6; Clear Explanation of Verizon / Level 3 / Netflix; Teenage Girls; Formalising NSA Attacks; Switching Brakes (Tektro Hydraulic); Naim NAP 100 (Power Amp); AKG 550 First Impressions; Facebook manipulates emotions (no really); Map Reduce "No Longer Used" At Google; Removing RAID metadata; New Bike (Good Bike Shop, Santiago Chile); Removing APE Tags in Linux; Compiling Python 3.0 With GCC 4.8; Maven is Amazing; Generating Docs from a GitHub Wiki; Modular Shelves; Bash Best Practices; Good Emergency Gasfiter (Santiago, Chile); Readings in Recent Architecture; Roger Casement; Integrated Information Theory (Or Not); Possibly undefined macro AC_ENABLE_SHARED; Update on Charges

© 2006-2013 Andrew Cooke (site) / post authors (content).

Starting a Scala Project

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 15:35:39 -0400

I just decided to do a quick + dirty project - I want to run through
my mp3s, read the tags, store everything in a database, and then pull
tags from the last.fm API so that I can automatically construct
playlists of related music.

I also decided the time has come to learn Scala.  I could do this
easily in Python, but I've been postponing Scala for too long.

I looked at Scala yesterday and downloaded the port of processing,
which used sbt (Simple Build Tool).  I was thinking about looking at
ant+ivy (something else I need to learn), but I *think* sbt uses ivy
under the hood (or uses Maven, or all share the same basic
infrastructure).  So for now I am going with sbt.
http://code.google.com/p/simple-build-tool/ (which I had installed

So, first step was to create a new directory and run sbt.  It asked if
I wanted to create a new project and I said yes, and gave it a name.
Now it seems to be downloading stuff.

OK, so that left me with some basic directories:

spu63 uykfd: ls
lib  project  src  target

OK, now how do I make that work with Eclipse?  No idea.
suggests using IvyDE (note - I have already installed the Scala plugin
in Eclipse).  So I install this via

reload + deliver-local in sbt (following instructions at
IntegrationSupport link above).

I still don't get this.  I think I need to create the Scala project
first in Eclipse, so move the directories generated with sbt above out
of the way, create the Scala project from within Eclipse, and then
move the sub-directories back.

But Eclipse is using Scala 2.7.6 and sbt is using 2.7.5

So delete those and in the project directory created by Eclipse run
sbt again, giving the correct Scala version.

That gives an error "unknown resolver sbt-chain" which I am going to
ignore, and otherwise seems to have worked.

F5 to refresh Eclipse and we seem to be cool.

Run reload and deliver-local again in sbt.  F5 again in Eclipse and
add library as described in link above.  Looks good.

Next I create a HelloWorld class in the main.scala package, based on
http://www.scala-lang.org/node/166 but when I try to run it in Eclipse
it is treated as "HelloWorl" (no final "d") and so fails!

If I fix that in the run configurations I then get
Exception in thread "main" java.lang.NoSuchMethodError: main
which sucks somewhat.

This is not looking good.

Running via sbt gives something similar.  Does the "main" have to have
a special name?

I checked with the example and had "class" rather than "object";
fixing that doesn't seem to change anything in Eclipse, but now sbt

> run main.scala.HelloWorld
[info] == copy-resources ==
[info] == copy-resources ==
[info] == compile ==
[info]   Source analysis: 1 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling main sources...
[info] Compilation successful.
[info]   Post-analysis: 2 classes.
[info] == compile ==
[info] == run ==
[info] Running main.scala.HelloWorld ...
hello world
[info] == run ==
[success] Successful.
[info] Total time: 2 s

Trying with the syntax at http://www.scala-lang.org/node/94 also works
with sbt, but not with Eclipse.

Looking at the comments for Application (via Eclipse F3) it seems it's
not recommended.  So revert to earlier syntax:

package main.scala

object HelloWorld {
  def main(args: Array[String]) {
    println("hello world")

Which seems identical to the example.


Scala Bug Report

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 16:01:55 -0400



Trying Again (New Instructions)

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 18:35:59 -0400

OK, as you can see via the bug report, it's not clear what went wrong,
but the following appears to work:

- First, install all software (sbt, Eclipse plugins for Scala and Ivy)
- Next, start Eclipse with a new workspace
- Create the project from inside Eclipse using the "new Scala project" wizard
- In the project directory, run sbt and create a new project with a
matching name (so that you end up with the "src" directory Eclipse
created matching the "src" directory sbt would also create)
- F5 in Eclipse to pick up new files
- At this point I created a HelloWorld object in main.scala, which
worked just fine
- run main.scala.HelloWorld in sbt also runs the hello world
- inside sbt, "reload" and "deliver-local" to generate the ivy file
- F5 again in Eclipse, then projects settings, Java build path,
libraries, and add the Ivy file (in the target directory)

The above creates a project that works both in Eclipse and sbt.

To add a dependency you need to open the ivy xml file using the
dedicated editor.  For example, right click on the ivy xml file in the
build part of the project explorer (NOT the file in target) and select

The edit the dependency (the values seem to be as for Maven).  So, for
example, to include Empire DB -
http://incubator.apache.org/empire-db/downloads/latest.htm - I added:
  <dependency org="org.apache.empire-db" name="empire-db"
and when I saved the file, it went off and downloaded that and a pile
of supporting libraries (not very quickly - I am in S America and the
net is not that fast, so perhaps that's the reason - but it did work).


Scala in More Detail

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 19:35:30 -0400

So now I'm at the point where I need to understand Scala more.  This
is a good overview of the main language features:
(as I read it, I realised that some examples assume familiarity with
ideas from functional programming, so it may not be for everyone).

There's also more specific details (scroll down to the "table of
contents") on individual features here -

One thing that has already puzzled me is the use of "object", which is
illuminated by the first link: "In fact, every Java class is seen in
Scala as two entities, a class containing all dynamic members and a
singleton object, containing all static members."

There's a nice clear separation between Value and Reference types
(which in Python would help clarify things for newbies and in Java
helps unify equality).  And explicit Nothing and Null (reference)

Oh and operators are methods (and vice versa!) with fixed precedence
(right associative if they end in a colon, which just happens to give
a sweet syntax for list consing!).  Parameterless methods are
possible.  And "override" is a modifier, not an annotation (ie it's

Whoa.  Pass by name exists (lazy evaluation).  The syntax is a little
odd (a "=>" precedes the type).  Ah, because it's a think that "goes
to" a value, I guess.  Evaluated each time they are used (implemented
as parameterless function).

Mixins!  called traits.

I need to go cook dinner, but this is awesome :o)


More on Scala

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 21:06:34 -0400

Continuing with notes from

Anonymous (using => again), curried and generally first class
functions.  And closures.  And partial evaluation:
  forall(row, 0 ==)
page 6

Functions implemented via generic FunctionN classes.

Wow - arrays are treated as functions over integers (special handling
of assignment to functions via "update").

Sequences and list comprehensions.

Good discussion of co + contra variance.  Helps clarify some problems
I have had with generic types in Java.

Surprisingly, "new" still seems to exist.  I thought it was
unnecessary, so why keep it?

Enough type discussion to make my head explode.

Aha.  Traits must have empty constructor arguments.  That's a very
nice way to keep mixins clean.

The "case" modifier gives you constructor-like matching.

Native XML support including queries.

Hmmm.  Seem to have stalled at views.  Try again tomorrow.


Revised Instructions for Adding Dependencies

From: andrew cooke <andrew@...>

Date: Mon, 28 Sep 2009 09:09:43 -0400

The notes above on adding dependencies are incorrect.  The problem is
that the ivy file is generated by sbt.  So extending it is not
permanent.  It exists only as a mechanism to communicate from sbt to
Eclipse.  The actual configuration of dependencies is done in sbt.

It turns out that sbt is configured by writing a scala class:

- Under the project directory add a "build" directory
- In the build directory create a class named after your project (in
my case uykfd):

import sbt._

class uykfdProject(info: ProjectInfo) extends DefaultProject(info)
  lazy val hi = task { println("Hello World"); None }
  val empire_db = "org.apache.empire-db" % "empire-db" % "2.0.5-incubating"

- The "hi" above defines an action, so inside sbt you can type "hi"
and it will print "Hello World" (pointless, but a good test that
things are working)
- The "empire_db" defines a dependency.  The name of the value doesn't
matter and the various strings are as above (ie as Maven).
- If sbt is still running you need to "reload" to pick this up
- You then MUST do "update" to download
- After that "compile" should work.  For example, I altered my test class to be:

package main.scala

import org.apache.empire.db.DBDatabase

object HelloWorld extends Application {
    object db extends DBDatabase {

- To get this working in Eclipse you then use the ivy xml file, so
"deliver-local" and then click around in Eclipse to get the ivy.xml
file to be added to the build path
- It's not at all clear, but you can also delete the ivy build path
thing via the Eclipse build path dialog (under libraries).
- Once that is done, the libraries downloaded by sbt/ivy appear in the
Eclipse project too.


Switched to Emacs

From: andrew cooke <andrew@...>

Date: Tue, 6 Oct 2009 09:02:43 -0400

This page is getting a few hits, so I should add that I have given up
on Eclipse and switched to emacs (for Scala - I still use Eclipse for
Python and Java). So much was broken that emacs does the same and uses
much less memory on my laptop.

To set up emacs follow the instructions at http://scala.sygneca.com/tools/emacs

Despite that having an sbt window, I use sbt in a separate console
(the emacs window shows some strange control characaters and I need to
exit sbt regularly to kill the in-memory database I am using).

In short, Scala tooling is not that great, still.  The language itself
appears to be fine, however.


Comment on this post