First step in configuring ubuntu

Some things to install when getting a brand new and fresh installation of Ubuntu. This is a reminder for myself for future times.

No Windows option in GRUB

sudo update-grub

Show git branch name in ubuntu terminal

Color Calibration

After experiencing some issues with the way the colours were displayed, I found a decent solution to add this command to the autostart applications:

xcalib -blue 0.9 0.0 80.0 -alter

Install Chrome


Install java

sudo apt-get install default-jdk

Install clojure

Install scala & sbt

sudo apt-get remove scala-library scala
sudo wget
sudo dpkg -i scala-2.11.8.deb
echo "deb /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp:// --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
sudo apt-get update
sudo apt-get install sbt

Install Erlang

Install Intellij

sudo tar xf ideaIC-2017.2.5.tar.gz -C /opt/
cd /opt/idea-IC-172.4343.14/bin/


Install Franz, Viber & Skype

  • Download Franz for your distribution from
  • change into the same directory as the downloaded file, then sudo tar -xf Franz-linux-x64-0.9.10.tgz -C /opt/franz
  • (optional) wget "*v86tTomtFZIdqzMNpvwIZw.png" -O franz-icon.png then sudo cp franz-icon.png /opt/franz
  • (optional) sudo touch /usr/share/applications/franz.desktop then sudo vim /usr/share/applications/franz.desktop

paste the following lines into the file, then save the file:

[Desktop Entry]

view raw
hosted with ❤ by GitHub

sudo dpkg -i viber.deb

sudo dpkg -i skypeforlinux-64.deb

Add more languages for keyboard

Free linux-like command on Mac OS


Use fish-shell and install the free plugin:

After installing, just run in your terminal


then do:

fisher free

and voila, it is installed! Now you can just type


in the fish-shell. It will only display the memory in GB. Output looks like this:


Setup Jenkis job to run on every git commit

# Source:

Install Hudson Post Build Task Plugin in Jenkins:

Create access token in Github:

create access token

This will create an access token. Copy the value (because afterwards it will not be available)

Create Github web hook for your repo:


The Jenkins Job:

  1. Set the name and the url to your project on github


2. Source Code Mgmt – add your repo url, credentials if needed and sent the branch to any.


3. Build Triggers – choose Poll SCM


4. Add task that will put the status to pending on github

curl -XPOST -H "Authorization: token OAUTH TOKEN"$(git rev-parse HEAD) -d "{
  \"state\": \"pending\",
  \"target_url\": \"${BUILD_URL}\",
  \"description\": \"The build is pending!\"


5. Post-build actions:

5a. Add a Post Task Plugin that always put success

curl -XPOST -H "Authorization: token OAUTH TOKEN"$(git rev-parse HEAD) -d "{
  \"state\": \"success\",
  \"target_url\": \"${BUILD_URL}\",
  \"description\": \"The build has succeeded!\"


5b. Add a Post Task Plugin that will put failure if “marked build as failure”

curl -XPOST -H "Authorization: token OAUTH TOKEN"$(git rev-parse HEAD) -d "{
  \"state\": \"failure\",
  \"target_url\": \"${BUILD_URL}\",
  \"description\": \"The build has failed!\"


Autocomplete with acts-as-taggable-on and rails-jquery-autocomplete in Rails

In this small guide you will find out how to set up autocomplete for tag using acts-as-taggable-on and rails-jquery-autocomplete gems.

How to set up acts-as-taggable-on: Implement tags in Rails

This guide will focus on autocomplete functionality.
A little bit of background. I have the startup model which can have many fields of activity, like IT, design etc.

In Gem file add the following gems:

gem 'rails-jquery-autocomplete'
gem 'jquery-ui-rails'

I’ve added jquery-ui-rails because in the new version of jquery-rails the ui part was removed and some functionality is missing.

In assets/javascripts/application.js

//= require jquery-ui
//= require jquery_ujs
//= require jquery-ui/autocomplete
//= require autocomplete-rails

In assets/stylesheets/application.css.scss, at the top of the file

*= require jquery-ui

My file was applicaton.scss initially, I had to rename it to css.scss. If you have .css file, you should be fine 🙂

In routes.rb

resources :startups do
  get :autocomplete_field_name, :on => :collection

In startup_controller.rb

autocomplete :field, :name, :class_name => 'ActsAsTaggableOn::Tag'


You have to add :class_name => ‘ActsAsTaggableOn::Tag’ for this to work.

In views
For new.html.haml

f.input :field_list, :url => autocomplete_field_name_startups_path, :as => :autocomplete, :input_html => { :data => { :delimiter => ', '}}

For edit.html.haml is:

f.input :field_list, :url => autocomplete_field_name_startups_path, :as => :autocomplete, :input_html => { :value => @startup.field_list.join(","), :data => { :delimiter => ', '}}

Upvotes in Rails

I will implement Like/Unlike functionality as it is working in Facebook.
There will be no downvote/dislike nor rating.

Let’s suppose we have the following models:

Startup(id, …)
Upvote(id, user_id, startup_id)

In upvote.rb:

class Upvote < ActiveRecord::Base
  belongs_to :user
  belongs_to :startup

In user.rb

class User < ActiveRecord::Base
  has_many :upvotes

  def already_upvoted?(startup)
    User.joins(:upvotes).where(:upvotes => {:startup_id =>}).size > 0

In startup.rb

class Startup < ActiveRecord::Base
  has_many :upvotes

In routes.rb

resources :startups do
  member do
    get "upvote"
    get "undo_upvote"

Probably you can find a more proper name for undo_upvote functionality 😀

In startup_controller.rb:

def upvote
  @startup = Startup.find(params[:id])
  upvote = @startup.upvotes.find_or_create_by(user: current_user)
  redirect_to startups_path

def undo_upvote
  @startup = Startup.find(params[:id])
  upvote = @startup.upvotes.find_by(user: current_user)
  redirect_to startups_path

In Startup view

-if current_user.already_upvoted?(startup)
 = link_to "Unlike",undo_upvote_startup_path(startup)
 = link_to "Like",upvote_startup_path(startup)

Now a user can like/unlike a startup.

Rails: Authenticate with Google and Devise

This is a small guide that will help you setup Google authentication in your rails app (with Devise).

Isert these lines in your Gem file

gem 'devise'
gem 'omniauth-ouath2'
gem 'omniauth-google-oauth2'

!Note: When using gem omniauth I got a nasty error when user tried to authenticate:

Authentication failure! invalid_credentials:
OAuth2::Error, redirect_uri_mismatch:
  "error" : "redirect_uri_mismatch"
Processing by Users::OmniauthCallbacksController#failure as HTML
Parameters: {"state"=>"bb02b2af24f91c9878bf168f5721dfe78dd686b73286fbe0", "code"=>"4/7ylzDJRjHGCeTPmNMeD7CAEj3l0CKBubPes8UhABzFs"}

After hours of trying to solve the problem, the solution I found was to user gem “omniauth-oauth2” instead. Everything worked as a charm.


bundle install

If you haven’t integrated Login with other providers, you need to run these 2 lines:

rails g migration AddProviderToUsers provider:string uid:string
rake db:migrate

You need now an client id and client secret. Go to

And create your app


Some set ups

You must ensure that “Contacts API” and “Google+ API” are enabled.
Click on your project, then in the right side menu choose “API Manager”


In the search bar type the name of the API you want to enable, select it and click “Enable”. You’re done.

Get your client id and client secret
In API manager, go to Credentials and hit “Add Credentials” and select “Oauth 2.0 client ID”


Select web application, write your app’s name, and also include two links:

Authorized JavaScript Origins: http://localhost:3000
Authorized redirects URI: http://localhost:3000/users/auth/google_oauth2/callback

The second link is crucial to set up in order for everything to work.


Once you click create, you will get the client_id and client_secret of your application.
Go to config/application.yml and add the following lines:


Go to config/secrets.yml and add the following lines for every environment:

google_client_id: <%= ENV["GOOGLE_CLIENT_ID"] %> 
google_client_secret: <%= ENV["GOOGLE_CLIENT_SECRET"] %>

Go to config/initializers/devise.rb and include the following lines in your code

OmniAuth.config.full_host = Rails.env.production? ? '' : 'http://localhost:3000' 
 config.omniauth :google_oauth2, 
   :skip_jwt => true 

In config/routes.rb add the following:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

Go to controllers folder and create a new folder called users. There create a file named omniauth_callbacks_controller.rb

Copy paste the following content:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController  
   def google_oauth2 
   # You need to implement the method below in your model (e.g. app/models/user.rb) 
   @user = User.connect_to_google(request.env["omniauth.auth"]) 
   if @user.persisted? 
     flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google" 
     sign_in_and_redirect @user, :event => :authentication 
     session["devise.google_data"] = request.env["omniauth.auth"] 
     redirect_to new_user_registration_url 

In your user.rb file add the following changes:
for devise add

 :omniauth_providers => [:google_oauth2]

It should look like this

 devise :database_authenticatable, :registerable, 
             :recoverable, :rememberable, :trackable, :validatable, 
             :omniauthable,:omniauth_providers => [:google_oauth2]

Add the needed functions. You can adjust them and extract the data you need.

def self.connect_to_google(auth) 
 data = 
 where(provider: auth.provider, uid: auth.uid).first_or_create do |user| = data["email"] 
   user.password = Devise.friendly_token[0,20] 
   user.first_name = data["first_name"] 
   user.last_name = data["last_name"] 
   user.avatar = process_uri(data["image"]) 

#This one is needed to process the link you will get for your image. Y

def self.process_uri(uri) 
 avatar_url = URI.parse(uri) 
 avatar_url.scheme = 'https' 

In the devise views there is one /shared/_links.html.erb
There you should have

<%- if devise_mapping.omniauthable? %> 
 <%- resource_class.omniauth_providers.each do |provider| %> 
 <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br /> 
end -%>

This will show the link on the sign up/sign in pages that will allow you to sign in with Google and other providers you are going to set up.

Have fun!

How to show git branch name in terminal Ubuntu

For the branch name to appear in your terminal, go to home directory and do

vim .bashrc

and add the following at the end

function parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
PS1="$GREEN\u@\h$NO_COLOR:\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ "