Tag Archives: Apache Spark

Lets get functional around GTK+

Object oriented programming makes code understandable by encapsulating moving parts. Functional programming makes code understandable by minimizing moving parts.

Scala

Scala provides excellent support for functional programming and probably the biggest reason I ABSOLUTELY LOVE IT is that its so concise and yet has full interoperability with Java.

Read more here.

Hello GNOME  World! ❤

sahilsareen@sahilsareen:~$ sudo apt-get install libjava-gnome-java

sahilsareen@sahilsareen:~$ sudo apt-get install scala

sahilsareen@sahilsareen:~$ scala -cp /usr/share/java/gtk.jar
Welcome to Scala version 2.11.6 (OpenJDK 64-Bit Server VM, Java 1.8.0_121).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import org.gnome.gtk._
scala> Gtk.init(Array())
scala> new InfoMessageDialog(null, "Hello GNOME World! ❤", "Functional programming is amazing!").run
And here is the shiny GTK dialog

*Distro: Ubuntu 16.04.2 LTS

There is tonnes of content online about why functional programming makes sense and how it helps so I’m not going to bore you with the details. Lets get on to a really simple but a real world example.

Introducing Apache Spark

Apache Spark is undoubtably the most well-known open source cluster computing solution, written in Scala. “Big Data” folks absolutely love it (Well that’s me!).

Spark and Scala together make my days brighter almost every day! ^_^

To get started, download it from the Apache Spark downloads page. The Apache Spark quick start guide gives a kick start into the basic concepts.

Putting it all together with an example

Before I begin, I’d like to clarify that the goal of this demonstration is to just show an interesting integration of all the three: GTK+, Scala & Apache Spark. I only want to demonstrate that you can build really cool stuff on the backend with Scala and still use GTK+, the finest development toolkit available worldwide.

I wanted to build something interactive so I chose to demo a twitter live stream to GTK dialog box.

The code can be downloaded from GitHub |  GNOMETweetsOfLove. Follow the instructions on the README to get your own deployment of this app.

Basically, I setup a twitter application to authenticate to twitter and read tweets and wrote (really prototypey) code using Apache Spark and GTK+. All in Scala.

Here is a sample dry run of this app:

My tweet Twitter | SahilSareen1

And the lovely GTK+ dialog appearing on Ubuntu

Now that you know this works, put the three together to good use. Extend the backend to do more interesting analysis, scale it up as much as you wish to and change your GUI acccordingly.

Only your imagination sets the limits on how far you can take this.