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
  PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\
   [\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$'
else
  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$'
fi
Advertisements

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”

begin
#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))
end
end

#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}”)
ensure
#Close and delete the temp file
temp_file.close
temp_file.unlink
FileUtils.rm_rf(Dir.glob(“#{Rails.root}/public/Invoices_pdfs/*”))
end

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))
end
zipfile.get_output_stream(“success”) { |os| os.write “All done successfully” }
end
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
FileUtils.rm_rf(Dir.glob(“#{Rails.root}/public/my_pdfs/*”))

end

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

$(".modal-form").live("ajax:before",function(evt,data,status,xhr){
   var checked = $(".project-modal-form input:checked").length > 0
   if (!checked){
     $("#warning_notification-project-modal").text("Warning.").slideDown(70         0).delay(7000).slideUp(700);
     $('#warning_notification-project-modal').removeClass('hide')
     return false; 
   }else{
      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

https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-on-ubuntu-14-04-using-rvm

2) Install Sublime

http://askubuntu.com/questions/172698/how-do-i-install-sublime-text-2-3

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

http://stackoverflow.com/questions/9336596/rvm-installation-not-working-rvm-is-not-a-function

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

https://www.digitalocean.com/community/tutorials/how-to-use-mysql-with-your-ruby-on-rails-application-on-ubuntu-14-04

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”

CREATE SSH KEY

ssh-keygen

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

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis

8) Install ImageMagick

http://askubuntu.com/questions/471045/14-04-doesnt-have-package-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

http://dbeaver.jkiss.org/download/

12)  Chrome Extension

http://usersnap.com/blog/chrome-extensions-for-developers/