Programmatically Creating a Sitemap for Your Middleman Website

In a previous post I explained the benefits of static websites and how cool Middleman is. In this post I will explain you how to programmatically create a sitemap for your Middleman website.

Middleman has a handy helper method named sitemap which returns an array of Resource items which are all the pages (including dynamic pages) and assets (JavaScript, CSS and images) that your website contains.

With that method, and a couple of extra snippets we will make Middleman to automatically create a sitemap.xml file during the $> middleman build task.

Continue Reading →

Neat Breadcrumbs With Some Ruby Magic

Breadcrumbs are the perfect tool for preventing users to get lost as they go deeper and deeper navigating a web application. They are relatively easy to code and test and you don’t have to worry about the look and feel: Twitter Bootstrap provides. The problem with breadcrums (yes, I found one) is that they require excesive markup, which you can reduce with some Ruby magic.

The following is a 4-level Twitter Bootstrap breadcrumb for a Ruby on Rails website:

<div class="breadcrumb">
  <li>
    <%= link_to "Home", a_root_path %>
    <span class="divider">/</span>
  </li>
  <li>
    <%= link_to "A page", a_page_path %>
    <span class="divider">/</span>
  </li>
  <li>
    <%= link_to "Another page", another_path %>
    <span class="divider">/</span>
  </li>
  <li class="active">
    The final page
  </li>
</div>

The above breadcrumb has a considerable amount of boilerplate code, which can lead to poor maintainability if you have many of them inside your application, which was my case.

Continue Reading →

Why you should consider using a static site generator to develop your next website

Static websites are cheaper and faster to develop than traditional websites and blogs. Static site generators allow you to easily develop static websites using the same tools used to develop dynamic websites. You should consider using this new modern web development tools whether you are going to develop a personal blog or your next company’s website with a product catalog.

Why static websites

  • Faster and cheaper to develop

  • Faster average page load time

  • Cheaper to host

Middleman

Middleman is a static site generator for Ruby programmers. It is built on top of Sinatra and Rack, which means that you can easily transform your static website into a Sinatra powered web application.

Continue Reading →

How to deploy a Neo4j instance in Amazon EC2 in 10 minutes

Neo4j is a high-performance, NOSQL graph database with all the features of a mature and robust database. In this post I will explain how to deploy a neo4j instance in Amazon EC2 web service.

For this tutorial to take you no more than 10 minutes you should be able to execute properly some bash commands like mv, tar, ssh and scp (secure copy). I also assume that you have an account in Amazon Web Services and you are familiar to the process of launching instances. If not, I strongly recommend you to follow this starting guide and complete it till you manage to connect to your instance with ssh.

Start downloading the latest stable version of neo4j. Which you can find here. The “Community Edition” fits well for development purposes. Do not forget to select the Unix version of the server. This will download a tar.gz file which you will copy to your EC2 instance later.

Continue Reading →

6 Clean implementations of Java Graph algorithms

Hi ! In this post I will share with you 6 Java Graph algorithms I had to code for a discrete mathematics final exam in college. The algorithms were presented in an Applet I built and which I also include for you to play around with them.

Before presenting the algorithms I will give a general background about Graph Theory.

What is a graph?

(from Wikipedia) A graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected objects are represented by mathematical abstractions called vertices, and the links that connect some pairs of vertices are called edges.

Type of graphs

There are many, many, many type graphs, most of them associated to maths properties. For the purpose of the API I developed for the algorithms implementations you should know the following:

In terms of representation, a graph can be represented either by an adjacency matrix or an adjacency list. In an adjacency matrix, a true/false (x,y) cell represents if exists a link between node “x” and node “y”. This is the one which I used because of its better performance. In an adjacency list, each node has an own list for storing referenced lists.

Continue Reading →