Sunday, 30 June 2013

Hello world with Vagrant

Hello everyone!

Not long ago I wrote a review of Vagrant: Up and Running. This time, I'd like to post some tutorial on using Vagrant for those, who are totally new to it. Let me just remind you that Vagrant is a useful tool for managing virtual machines and their settings of resources used, network and others. In most cases, people use to create VMs for VirtualBox, but there is also possibility to set up Amazon EC2 machines directly from Vagrant.

Setting up

After installing Vagrant (and VirtualBox), to create new virtual machine, you just need to type in your terminal:

This means creating new settings for a VM that will be based on ubuntu 12.04. In your current directory new file will be created: Vagrantfile. It's a text file with all the settings of your VM. Actually, it contains just a Ruby source code, but don't think you need to know Ruby to use Vagrant efficiently.

Initially created Vagrantfile contains some default settings and huge amount of settings that are commented out, just to give you some idea about what else can be configured here. But for know let's just keep the defaults.

Starting the machine

To start your newly defined virtual machine you just need to type:

If it's the first time you run it, the VM will be created. If base image for a vm (clean ubuntu) is needed then it will be downloaded automatically from url specified in "init" command.

To actually use the machine you need to use ssh:

Finishing work

After you finished your work, you would usually stop it by:

Or you can destroy the whole machine, so that all the resources are freed (including hard disk space).

More resources

If you need high-performance on the virtual machine, then you probably need to adjust the resources it is using. When using Vagrant with VirtualBox you need to add some additional settings in Vagrantfile. These settings are specified in format of VBox's "modifyvm" command:

Sharing a folder

When you work on guest virtual mashine, there is often need for sharing a folder between host and guest operating system. Nice thing in Vagrant is that you can just specify a single configuration file to set up this shared folder (and mount it on guest OS).

After next "vagrant up", you will be able to use the folder on guest.

Port forwarding

When you run some kind of a (web?) service on guest, you need to somehow be able to connect to it. In Vagrant, it is just another one-liner!

This line specifies that when you try connect from host to "localhost:9090", you will actually connect to the guest machine on port 9000. It's as simple as that. This way you can easily test web application running on guest, using your web browser from host.

Additional software - provisioning

Managing of software inside a virtual machine is called provisioning. There are few mechanisms available in Vagrant for this job. Here I will describe only the most basic one: shell provisioning.

Shell provisioning is just a set of shell "tasks" to be executed after machine boot. You can write exactly shell commands in Vagrant file, or point to a shell script that should be executed.

In clean ubuntu you should start with running "apt-get -f install", just to be able to install additional software using apt-get package managing tool.

To do it after each machine boot, just put following line in your Vagrantfile:

If you want to run a script, you can specify path to it, ex:

I assume that this script has instructions for installing git in the system. I'd like to point out that when using Vagrant, you should use option "apt-get install -y {package_name}", which makes apt-get assume that you answer positively on any "y/N" question.

You might wonder, what you can do to make some scripts run only once (on first boot), rather than on every "vagrant up". The simple trick is to make inside a script an if statement for presence of some file (let's say you keep logs of installing git in it):

Then only the first time you start the vm the script will be run. If you want to run it again, you need to delete particular file.


Any GUI? If you set a flag: "vb.gui = false" inside a virtualbox configuration (in Vagrantfile), you will have your GUI. But you would probably also need to install packages like Gnome to make real use of that.

More provisioning techniques? There are also ways to use provisioning tools like Puppet of Chef, but I'm not an expert on those, so you need to find something about it on your own:)

Custom base images? No problem, just look on "how to create your own box" in Vagrant documentation.

More network settings? You can do a lot - actually anything (I think) that is possible with typical VirtualBox.

More machines defined inside a Vagrantfile? Yes, that's doable. Normally you use only a single Vagrantfile per project, even if you need more virtual machines.


You can find an example definition of a Vagrant environment on my github. There is a single-machine definition of vm for scala+mongodb+play (actually +sbt) development.

Note: It's common for Vagrant users to run developed code on VM, but edit the code in your favourite IDE on host OS.

Monday, 24 June 2013

Graph Databases by Ian Robinson, Jim Webber, Emil Eifrem; O'Reilly Media

This book significantly help in understanding what graph databases are and how to use them properly. The authors introduce basic ideas behind graph databases. They write about why the need for such databases emerged, why there's a need for having database engine in which relationships are first class citizens. 

I believe that most important chapter of this book is the one that explains data modelling with graphs. The way you need to think when using graph db is totally different that in other types of db. The authors based their teachings on a set of examples, with each being discussed in detail. Various use-cases are shown, and you'll be surprised how efficient data model can be, when used properly.

You will be also able to learn basics of Cypher, which is a language that is used for querying a graph database. It's not really comprehensive introduction, so therefore it cannot be used as a reference. The book shows examples for querying Neo4j, which is probably the most popular graph database implementation. I don't think that you will be very comfortable at using Neo4j immediately after reading this book. It rather intends to make you familiar with fundamental concepts of graph databases and showing how it differs from still more popular solutions like RDBMS. 

Also, some additional topics were covered, like: overview of using graph database in agile (also tdd-based) manner, introduction to Neo4j internals (different available APIs or ways of running it) or overview of other NoSQL storage.

I really liked reading it and the book made me more interested in graph-dbs as it provided solid arguments for using it in various applications. On the other hand, after reading it, I still think there's a lot for me to learn (from other resources) before I become comfortable with Neo4j. I would recommend this book to all developers, who are new to concepts of graph databases and who wants to become familiar with its strong points, before they try start using concrete graph database solutions like Neo4j.

Graph Databases - O'Reilly Product Page

Thursday, 20 June 2013

Tricity JUG: Apache Lucene in practice

On June, 15th I was one of the participants of the workshop titled "Apache Lucene in practice". The meeting was organized by Tricity Java User Group and was lead by Dominika Puzio and Patryk Makuch, whose previous experience included building search engines for many systems that belongs to Wirtualna Polska. 

Apache Lucene is a high-performace text search engine written entirely in Java. That's the why workshop included developing simple java web application for searching through wikipedia content. The actual wikipedia's contents was already downloaded earlier by organizers and distributed before the event.

The project that was developed during the meeting is pushed to github you can access it through my fork of it. As a participant, I didn't need to spend a lot of time on writting same code as presenters. What I was really doing was just git checkout "next commit" after each step done, and I've only experimented sometimes with the given code. This way I could just listen carefully to the presenters most of the time, as they explained each step with many details. The presenters showed that they have a lot of experience in that field and shared a lot from it.

Should I mention that organizers ordered pizzas for participants? :)

I really enjoyed the workshops. I believe that I've learned a lot and I think that I'm now fully capable of building Lucene-based search engine on my own :). I'm glad that I could participate in the event and I'm looking forward to next TJUG's meetings.

Sunday, 16 June 2013

Vagrant: Up and Running by Mitchell Hashimoto, O'Reilly

Vagrant: Up and Running is a very concise book that helps you to get started with Vagrant, which is a very smart tool with growing role in software development. I believe that title of the book is very appropriate as you can hit the ground running and start using the tool comfortably for your project very soon after reading this book.

There's quite short introduction to what Vagrant is, and then the author shows exactly how to use it properly. Mitchell show how to install it and how to interact with it by the offered set of commands. You'll find there instructions for creating virtual machine, provisioning it and setting up a network, also between set of machines. The author discusses many common use cases for using every feature of this tool. Portion of the book shows usage of the plugins for Vagrant and teaches you about development of these plugins. At the end of the book, you'll also find reference chapters that describes Vagrant's options one by one.

I've really enjoyed reading this book. Mitchel Hashimoto shows how to solve most common problems - problems that most readers will encounter if the try Vagrant or virtualization in general, like automatic software installation, port forwarding, folder sharing. And he does it all with quite simple and very easy to understand examples.

I fully recommend reading it for anyone that is interested in what Vagrant offers to its users and how to make best use of it.

Thursday, 13 June 2013

Functional Programming Principles in Scala

Most of my previous posts were about functional programming and I would like to write this topic one more time - I think last time for now. This time I'd like to share my experience with one of the MOOC (massive open online course) that I've taken recently: Functional Programming Principles in Scala.

This course is offered by and is lead by Scala's inventor, prof. Martin Odersky. The course is divided into 7 weeks. Each week contains about 2 hours of video lectures and programming assignment that on average takes another few hours to complete.

In video lectures the speaker tells you about all the ideas behind functional programming and describes all concepts that FP consists of. Professor Odersky initially presents some theory (sometimes its full of math) behind some of these concepts and then he shows an example for each of them with a code that he writes in Scala. So there's actual practical application shown in the lecture part.

What you learn while watching the lectures, you can immediately try in practice by solving the problem that programming assignment describes. The assignments are sometimes challenging, however every time it is just pure fun to work on them. Let me just tell you that assignments include working on:

  • anagrams generator
  • logic game solver
  • Huffman coding
  • binary trees

I can assure you that most participants (including myself) are very pleased they could attend it. And I fully recommend you to take that course in the next available session if you are, like me, interested in functional programming. If you have any questions about the course, feel free to ask me privately or in the comments section.

You can find more details on the course page

Monday, 10 June 2013

Functional Thinking by Neal Ford, O'Reilly Media

Neal Ford in his video presents functional programming's foundations and principles as he believes that this paradigm is going to dominate software development as mainstream technologies are including its features more and more.

He believes that learning syntax of new programming language is easy, so instead teaches you about new way of thinking. Examples of code that are shown in the video present those ideas in languages like Groovy, Closure, Scala or even Java. But the speaker doesn't really try to give you comprehensive lesson about syntax of these languages. He discusses the basics of the paradigm that stands behind that new syntax.

Topics that are covered in the video include background of functional programming: immutability, higher order functions, laziness and other topics. There are also points when speaker contrasts new principles with object oriented design. I particularly liked the part where Neal teaches you that functional programming is about separating "how" and "what" needs to be done, so that you can make "how" part the problem of someone else. The lesson I learned is that you can use functional programming to minimize number things you need to worry about.

I feel that people that would benefit the most of watching this video are software developers that have already experience in object oriented technologies like Java or .NET and want to learn new concepts whose role is getting larger and larger in programming. If a developer is new to functional thinking I can definitely recommend him Neal's video .

I review for the O'Reilly Blogger Review Program

Sunday, 9 June 2013

O'Reilly Blogger Review program

I'm more than happy to announce that I've been approved for O'Reilly Blogger Review program!

Let me just remind you that O'Reilly is a well known publisher of books and other resources on information technology topics. Their blogger review program allows anyone who runs a blog to have access to free copies of books or videos in exchange for an honest review. Resources that are available include newly released books and videos.

The first resource that I've chosen to review is a video Functional Thinking by Neal Ford. You can expect me posting review quite soon!

I review for the O'Reilly Blogger Review Program

Thursday, 6 June 2013

Introduction to functional programming

This is a moment for my first real post. For start I wanted to write on some topic that I feel rather comfortable, so I went for functional programming. I'll try to give you some introduction to this interesting topic. Some concepts that will be described, will be followed by example in Scala, which is my language of choice for FP.

Functional programming can be probably defined in many ways. I'd say that it is a paradigm that enforces usage of the following two principles (I believe that they are foundations of FP):
  • usage of functions (also higher-order* ones) as first class citizens - so that they are the basic construction blocks for building a computer program.
  • avoidance of mutable state, side-effects or assignment statements.

Firstly I'd like to focus on the first one. This principle is very attractive to me, as my favourite programming principle is:

Encapsulate what varies

I believe that many people identify encapsulation with the process of hiding representation of some object's data. I think that's a mistake, as hiding behaviour is at least as important as hiding data representation. Easy way to create/pass/use functions helps you achieve that in a pretty convenient mannner.

Scala's way to work with functions is very effective, which is typical for a FP language. But in some other languages like Java you usually need to explicitly create a separate interface. One can think that it takes a bit more effort than it actually should.

I believe that usage of functions is particulary useful when you work with collections. In Scala you can easily process them as they offer you following operations:

  • map - translates from one representation to another
  • filter - selects only elements that match given predicate
  • reduce/fold - combines elements of the collection to a single object 

There are people that call them the functional operators, as these ideas are very common in functional programming. Theirs example usage is shown in the snippet below.

Another principle that is at the very core of functional programming is:


Data immutability means that one object, once created, will not have its state changed. This is particular useful if you try to write some parallel, multi-threaded code. You see, when data is never going to change, there is no need for synchronizing access to this data. And when synchronization oriented concerns disappear, developer has a lot less to worry about.

In FP language, it is feasible to work on immutable data as there are useful techniques available to create copies of the object that differs with some specified property. This is illustrated below.

When you do a functional programming you might think that recursion is closer to those principles than iteration. The latter is usually connected with mutable state, while recursion avoids it as much as it can. One can argue that iteration is more effective than recursion, but there's a technique that allows recursion to match iteration's performance. This technique is called tail-recursion and is offered in Scala. I am not going to describe its specifics now, as it is quite far from intended topic of the post.

People can question, like I do, if you can totally avoid mutable state in programming. I'd say that in real-world applications you can't (or shouldn't). But if there is actually genuine need for it, then there are tools to support you with that. One such tool is an actor (or whole actor system) that would allow you to synchronize access and operations on some data. Actors are often used in Scala with a library called Akka. One day I'll definitely write about Akka.

There is still more

In this post I've described the principles that I believe are fundamental to functional programming. Particular FP languages like Scala offers other features that I feel support FP even more, like: Option type, pattern matching, lazy evaluation and implicit parameters/conversions. If you are interested in the topic, I would encourage you to try those things as well.

*higher-order functions are functions that take other functions as arguments or return them

Tuesday, 4 June 2013

About me

Hello everyone! My name is Krzysztof Ropiak. This is my first post on newly created blog. As I'm a software developer, I intend to post on my professional experiences which are usually programming oriented. My past experience includes building Java or .NET systems and also creating mobile applications based on iOS.

I think in the future you'll be able to find here some texts about concepts such as object-oriented design or functional programming. Some of my other professional interests are scalability of computer systems or cloud computing - I will be more than happy to post about it as well, as these things are really exciting. I also expect to write about stuff with more scientific nature - like natural language processing or machine learning. But then again - probably every post here will be written from developer perspective. I also predict to write some kind of reviews of technical books or other sources of knowledge.

I'd like to publish new text at least once in month. This way I can keep my readers satisfied and avoid going out of practice. I believe I will start posting really soon. I think next post will cover introduction to functional programming, which is becoming more and more important in enterprise applications and one can predict big future of it in cloud computing market - that's quite handy topic for start, isn't it?

I hope you will enjoy reading my blog and that you'll come back here time and time again!