Ubuntu – Display Current GIT Hub Branch Name in Terminal

Copy Below script and paste in .bashrc or .bash_profile file.
You can find these files at /home/

parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
if [ "$color_prompt" = yes ]; then

Run Rails Development Server with HTTPS

1.   Install thin as web server instead of webrick. Write below line in gemfile and do bundle install.

gem 'thin'

2.  In environments/development.rb file write below lines

config.force_ssl = true
config.ssl_port = 3001 # port will be your choice

3.  Now start server using below command

thin start --ssl -p 3001

Now go to web browser and start your localhost:3000 with https://localhost:3000

Rails and RubyZip – Create zip file and delete it after download using send_data

We are not using send_file method because it will get deleted before rails actually starts sending it


filename = “#{Rails.root}/public/invoices.zip”
temp_file = Tempfile.new(filename)
input_filenames = Dir.entries(“#{Rails.root}/public/Invoices_pdfs”).select {|f| !File.directory? f}
folder = “#{Rails.root}/public/Invoices_pdfs”

#This is the tricky part
#Initialize the temp file as a zip file
Zip::OutputStream.open(temp_file) { |zos| }

#Add files to the zip file as usual
Zip::File.open(temp_file.path, Zip::File::CREATE) do |zipfile|
input_filenames.each do |file|
zipfile.add(file,  File.join(folder, file))

#Read the binary data from the file
zip_data = File.read(temp_file.path)

#Send the data to the browser as an attachment
#We do not send the file directly because it will
#get deleted before rails actually starts sending it
send_data(zip_data, :type => ‘application/zip’, :filename => “#{Time.now.to_date}”)
#Close and delete the temp file

Rails and RubyZip – Create zip file and download using send_file

def make_zip

# Path where your pdfs are situated (‘my_pdf’ is folder with pdfs)
folder = “#{Rails.root}/public/my_pdfs”
input_filenames = Dir.entries(“#{Rails.root}/public/my_pdfs”).select {|f| !File.directory? f}

zipfile_name = “#{Rails.root}/public/myfirstzipfile.zip”

Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
input_filenames.each do |filename|
# Two arguments:
# – The name of the file as it will appear in the archive
# – The original file, including the path to find it
zipfile.add(filename,  File.join(folder, filename))
zipfile.get_output_stream(“success”) { |os| os.write “All done successfully” }
send_file(File.join(“#{Rails.root}/public/”, ‘myfirstzipfile.zip’), :type => ‘application/zip’, :filename => “#{Time.now.to_date}.zip”)
# Remove content from ‘my_pdfs’ folder if you want


Prevent submit event of remote => ‘true’ Rails form which open in Modal

We can not directly prevent the form which submit using remote => true

This example show how to prevent submit event of ajax  form which open in modal

   var checked = $(".project-modal-form input:checked").length > 0
   if (!checked){
     $("#warning_notification-project-modal").text("Warning.").slideDown(70         0).delay(7000).slideUp(700);
     return false; 
      return true;

How to solve conflicts?

When there’s a conflict, Git marks them for you in the files. You’ll see sections like this:

<<<<<<< HEAD
* Daniel Pass <daniel.antony.pass@googlemail.com>
* Kieran Moore
* Kermit the Frog
* Miss Piggy
>>>>>>> upstream/unmergeable-branch

The first section, HEAD is what you have in your version. The second section, upstream/unmergeable-branch is what Git found in the version you were trying to pull in.

Make up to date Development machine For Ruby on Rails

1) Install Ruby On Rails


2) Install Sublime


3) just cut/paste following line: (RVM IS NOT A FUNCTION ERROR)


To permanently resolve this just put following line:

[[ -s “$HOME/.rvm/scripts/rvm” ]] && source “$HOME/.rvm/scripts/rvm”

into: ~/.bash_profile, ~/.bashrc and in ~/.profile file

4) Install MySQL


5) Install git & Configuring git

sudo apt-get install git

Configuring git

git config –global user.name “YOUR NAME”
git config –global user.email “YOUR@EMAIL.com”



6) Install PostgreSQL

Setting Up PostgreSQL

For PostgreSQL, we’re going to add a new repository to easily install a recent version of Postgres 9.3.

sudo sh -c “echo ‘deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main’ > /etc/apt/sources.list.d/pgdg.list”
wget –quiet -O – http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add –
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.3 libpq-dev

The postgres installation doesn’t setup a user for you, so you’ll need to follow these steps to create a user with permission to create databases. Feel free to replace chris with your username.

sudo -u postgres createuser chris -s

# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password chris

REF: https://gorails.com/setup/ubuntu/14.04

7) Install Redis Server


8) Install ImageMagick


9) Set up Sublime for Rails Environment

Package Controll: https://packagecontrol.io/installation#st3

User Pref: https://mattbrictson.com/sublime-text-3-recommendations#packages

For ERB: https://github.com/eddorre/SublimeERB#add-keybinding

For .rb and .erb: https://github.com/CraigWilliams/BeautifyRuby

then: gem install htmlbeautifier

type: which ruby

set that path in preferences > package settings > beautify ruby > settings default

type: “ruby”: “/home/user_name/.rvm/rubies/ruby-1.9.3-p551/bin/ruby”,

10) Install Java

sudo apt-get update

sudo apt-get install default-jdk

11) Install DBeaver – Free Universal SQL Client


12)  Chrome Extension