Installing Scala on Linux

The following Scala installation steps are tested on my CrunchBang Linux 11 “Waldorf” machine.

  1. Java Environment Check:
    Scala requires the Java runtime version 1.6 or later. So before you install Scala, first make sure that you Java environment is set up correctly.

    1. To test your Java runtime environment, type java -version at your command prompt and press ENTER. If your Java environment is set up correctly, you should see something like the following:

      ~$ java -version
      OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-2~deb7u1)
      OpenJDK Client VM (build 24.65-b04, mixed mode, sharing)
      
    2. Test to see that the Java compiler is properly installed. Type javac -version. You should see the compiler version if the compiler is found.

      ~$ javac -version
      javac 1.7.0_65
      
  2. Scala Setup:
    1. Download Scala from www.scala-lang.org/download. The version I downloaded is Scala 2.11.4. You can get the binaries in tgz, deb, rpm, msi, or zip format depending on your preference and platform. I had chosen the tgz format for my installation.
    2. Unarchive the Scala binaries to a directory of your choice. I unachrive the downloaded file in my local bin directory.
      ~$ cd ~/bin
      ~/bin$ tar -zxvf ~/share/downloads/scala-2.11.4.tgz
      

      At this point, you can Start the Scala interpreter (aka the “REPL”) by launching scala from where it was unarchived, or tart the Scala compiler by launching scalac from the same location.

    3. Set Path and Environment. For quick access, add scala and scalac to your path. I do so by adding the following lines to the end of my ~/.bashrc file.
      export SCALA_HOME=~/bin/scala-2.11.4
      export PATH=$PATH:$SCALA_HOME/bin
      

      After this either open a new terminal window to activate the two new environmental variables, or reload your ~/.bashrc script with

      source ~/.bashrc
  3. Test Your Scala Installation:
    Type scala -version, and scalac -version at the command prompt to test your Scala environment. You should see something like the following:

    ~$ scala -version
    Scala code runner version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
    ~$ scalac -version
    Scala compiler version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
    
  4. Let’s try a simple command in the REPL. Invoke the REPL by typing scala, and enter the println command to say hello to your Scala installation. You can enter :help to find out more about the commands available in the REPL. Type in :q to quit the REPL when you are done.
    ~$ scala
    Welcome to Scala version 2.11.4 (OpenJDK Client VM, Java 1.7.0_65).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala> println("Hello, Scala!")
    Hello, Scala!
    
    scala> :q
    ~$
    

Change the Default Size of Terminator Terminal in CrunchBang

In CrunchBang Linux, you can open a Terminator terminal by right-clicking on the desktop and choose Terminal on the pop-up menu, or use the Super-t shortcut keys to open a new terminal.

By default, the Terminator terminal window size is too small for my taste. I want the default terminal window size to cover most of the screen.

The terminator program has a --geometry option that can set the preferred size and position of the window. Format of the option is:

--geometry=WIDTHxHEIGHT+XOFF+YOFF

Where WIDTH, HEIGHT, XOFF, and YOFF are numbers measured in pixels. XOFF and YOFF are used to specify the distance of the window from the left/right and top/bottom edges of the screen, respectively. The offsets may be specified in the following ways:

+XOFF
The left edge of the window is to be placed x-offset pixels in from the left edge of the screen. if XOFF is negative, the window’s left edge will be off the screen.
-XOFF
The right edge of the window is to be placed x-offset pixels in from the right edge of the screen. if XOFF is negative, the window’s right edge will be off the screen.
+YOFF
The top edge of the window is to be placed y-offset pixels in from the top edge of the screen. if YOFF is negative, the window’s top edge will be off the screen.
-YOFF
The bottom edge of the window is to be placed y-offset pixels in from the bottom edge of the screen. if YOFF is negative, the window’s bottom edge will be off the screen.

Offsets must be given as pairs. In other words, both must be present. Here are some examples on window placement:

+0+0 upper left hand corner.
-0+0 upper right hand corner.
-0-0 lower right hand corner.
+0-0 lower left hand corner.

So back to the task at hand. To set the default pop-up menu Terminal size, I edit the ~/.config/openbox/menu.xml file. Here’s the excerpted section that set the Terminal size:

<item label="Terminal">
  <action name="Execute">
    <command>
      terminator --geometry=1600x930+0+0
    </command>
  </action>
</item>

To set the default Super-t shortcut key Terminal size, I edit the ~/.config/openbox/rc.xml file. Here’s the excerpted section that set the Terminal size:

<keybind key="W-t">
  <action name="Execute">
    <startupnotify>
      <enabled>true</enabled>
      <name>Terminal</name>
    </startupnotify>
    <command>terminator --geometry=1600x930+0+0</command>
  </action>
</keybind>

Finally, after saving the files. I reload Openbox’s configuration with the command:

openbox --reconfigure

Adding Additional Workspaces to Ubuntu Desktop

Use the command:
gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ {hsize | vsize} n

For example:

To set 3 horizontal workspaces…

gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ hsize 3

To set 2 vertical workspaces…

gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ vsize 2

If combine the two commands above, you will have a total of 6 workspaces (3 columns and 2 rows).

OCR Text from PDF Document

Today, I had to convert a scanned 3-page PDF file back into a editable document. So, open source software to the rescue. I was able to complete the task with the help of:

  • tesseract — for OCR, and
  • imagemagick — for converting PDF pages to an image format that tesseract accepts.
  1. Installing the software

    sudo apt-get -y install tesseract-ocr imagemagick

  2. Convert PDF pages to image

    convert -density 300 -depth 8 scan.pdf[0] scan0.png
    convert -density 300 -depth 8 scan.pdf[1] scan1.png
    convert -density 300 -depth 8 scan.pdf[2] scan2.png
    

    convert is a member of the amagemagick tools. You can use it to convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

    Here, I’m only using two options:

    -density width
    to set the resolution of an image for rendering to devices. The default unit of measure is dots per inch. The default resolution is 72 dpi.

    -depth value
    to set the number of bits in a color sample within a pixel.

    The numbers between the brackets mark the page in the PDF document to be converted. Of course, as any programmer can tell you, you start counting at zero.

  3. OCR page images to text

    $ tesseract scan0.png scan0.txt
    Tesseract Open Source OCR Engine v3.02.01 with Leptonica
    $ tesseract scan1.png scan1.txt
    Tesseract Open Source OCR Engine v3.02.01 with Leptonica
    $ tesseract scan2.png scan2.txt
    Tesseract Open Source OCR Engine v3.02.01 with Leptonica
    

And then just copy the OCR text from the text files into a new document to clear up any typo and reformat the document.