How to display the git last commit of every file in a list with ruby

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You want to display the last commit of every file that you have in a list.

Solution

Let’s say that you have the following file list in an array:

in order to be able to get the last commits of each of the files in ruby do the following:

Ruby on Rails and Django

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

There was a need recently to start a new web application using Python as the development language.

Having spent most of the last few years developing using Ruby with Ruby on Rails, this presented a nice challenge.
So the first thing, that needed some research was to be able to find a web framework in Python that is as close as possible to Ruby on Rails.

A quick web framework comparison and some web searches, indicated that the closest framework to Ruby on Rails, was Django.

So here I intend to list the similarities and the differencies of the two frameworks, as I go along the route and discover new things. The initial impression after a couple of days is that there is a surprising similarity between them, which hopefully will make the road smoother.

  • MVC In the Ruby on Rails we have Models, Views and Controllers. In Django that becomes Models, Templates and Views.
  • Package installation While in Ruby on Rails we have gem install in Django that becomes pip install
  • RVM(rbenv) To keep ruby versions and gems in different environments in Ruby we could use RVM or rbenv. On Python that is virtualenv
  • In Ruby on Rails we have an application but in Django we have a project that can contain multiple applications
  • Create a new application Because of the note above in Rails we create a new application with rails new app_name, where in Django we create the project first with django-admin.py startproject project_name and then the application with python manage.py startapp app_name
  • Database configuration In Ruby on Rails the database configuration can be found in the config/database.yml. In Django the database configuration, among other configuration options, is in the file project_name/settings.py
  • Starting the development web server With Ruby on Rails is rails s, on Django is python manage.py runserver
  • Running the console In Rails we can use rails c, and in Django python manage.py shell
  • Route information While in Ruby on Rails we set the routes in config/routes, in Django that takes place in project_name/urls.py and in app_name/urls.py
  • Deployment automation Capistrano for Ruby on Rails and Fabric for Django
  • Dependencies file is the Gemfile in Ruby on Rails and requirements.txt in Python’s virtualenv

Book Review: Exploring Everyday Things with R and Ruby by Sau Sheong Chang (O’Reilly)

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Exploring Everyday Things with R and Ruby, as the title suggests, is a book about data exploration, written in a very easy and very unusual way, that will make it hard to put down.

In the beginining it starts with a short introduction to the two languages used to achieve its purpose.

It gives a short explanation about the reason of using Ruby, followed by installation instructions and some basic ruby information. After that there is a short introduction to Ruby’s UI toolkit called Shoes.

The second initial part covers the other language to be used in the examples to follow, R. There are again the reason for picking R, installation instructions and a brief introduction to the capabilities of the language and especially the data analysis and graphing abilities.

Following the first two parts, is where the book starts to get really interesting and fun and it will certainly make you want to try the examples worked on.
Subjects like ‘Offices and Restrooms’ which is about deternining the correct people-to-restrooms ratio, ‘How to Be an Armchair Economist’ about a market economy simulation, ‘Discover Yourself Through Email’ dealing with email data mining, ‘In A Heartbeat’ for measuring the hearbeat, including a homemade digital stethoscope, ‘Schooling Fish and Flocking Birds’ a simulation of the Boids algorithm in Ruby, and finally ‘Money, Sex and Evolution’ an entire artificial world populate by the roids of the previous example.

All of the examples are fascinating, something that I would never imagine it would be possible to simulate before reading this book, and also include information about their specific fields.

So in conclusion, it is a very enjoyable, interesting and out of the ordinary book, helped greatly by the author’s unique writing style, and one that I would recommend to anyone with an interest in Ruby or R to read.

rails `require’: cannot load such file — mysql2/mysql2 (LoadError)

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You want to use a different ruby version from the one you have initially installed and build your application with, but when you change it in your rvm installation you get the following error:

Solution

To make it work again you will have to uninstall the mysql2 gem and install it again in the new ruby version with the option –platform=ruby.

Capistrano recipe to restart standalone passenger server

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem
You want to be able to use different ruby versions with passenger and by following the article here, you have set up your server to server the second version with a standalone passenger version. If you do that you cannot use the ‘touch tmp/restart.txt’ command to restart the standalone passenger server.

Solution
What you would need to do in your config/deploy.rb file, and assuming that your standalone passenger runs on a port (4000) different from the default (3000), is to replace the following:

with

Using named gemsets with rvm

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You want to be able to use different gems/rails version for your application after installing the latest rails version, without having to use bundle exec.

 

Solution

You can use the named gemsets with rvm.

More instructions are here: http://beginrescueend.com/gemsets/basics/

so you can install two gemsets for example ruby-1.9.3-p0@rails3_0_11 and another with ruby-1.9.3-p0@rails3_2_1

you could then do :

you could then also use some aliases in your ~/.bashrc file to be able to use the gemsets by using only one command as for example in ($ rvm3011):

Could not open library ‘libgtkmm-2.4.so’: libgtkmm-2.4.so: cannot open shared object file: No such file or directory.

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

If you have setup guard with your Rails project and you are trying to run it in an (K)Ubuntu installation you get the following message:

Solution

Install the missing library with the following: