Posts

Showing posts with the label Sabyasachi

Debug Nodejs inside docker container

If you want to debug a node js or express application that is running inside a docker container please follow the below steps. Step1:   add pryjs in you package.json and run npm install    or    npm install --save pryjs Step 2:   Go to your docker-compose file and find the specific docker container which you want to debug.   Ex. if your container name is an app then please add the below lines   app:     stdin_open: true     tty: true Step 3:   Go the specific file where you want to debug and require the library     var pry = require('pryjs');   Then add the script to the specific like where you want to stop the execution.     eval(pry.it) Step 4:   Run the docker compose file and attach the specific process     docker-compose up -d && docker attach $(docker-compose ps -q app) It will stop the execution in the specific line once the request will hit that specific line Please check the documentation for a more pry option.

Install Ruby on Rails on Mac

Please follow the below steps to i nstall RVM RUBY RAILS and Postgres in MAC yosemite. Step 1. Install Homebrew Homebrew is a package manager for the Mac. Installing Homebrew by issuing the following command: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) " To make sure Homebrew is installed correctly run: brew doctor Step 2: Install GPG Package. Download and install the GPG package from the link https://gpgtools.org Step 3: Install RVM gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 and \curl -sSL https://get.rvm.io | bash -s stable Reload your bash_profile, so it can initialize RVM. ~/.bashrc Run RVM requirements to install basic required packages with Homebrew. Accept the license agreement and install Xcode Tools. After installing the tools continue the rvm requirements installation. rvm requirements Step 4. Install Requir

How To Setup Ruby on Rails with Postgres

Postgres is a great open source database management system. It's pretty easy to use postgres with Ruby on Rails. Step 1: Install postgress in your system. If you already have postgres installed in your system then skip it else follow the  link . Step 2: Create new project rails new pg_demo You can also create using rails new pg_demo --database=postgresql Step 3: include the pg gem in your gem file gem 'pg' Step 4: run bundle command bundle Step 5: It will give you some error like An error occurred while installing pg (0.17.1), and Bundler cannot continue. Make sure that `gem install pg -v '0.17.1'` succeeds before bundling. So let's try to install the  pg gem first gem install pg It will again throw an error  :( Building native extensions.  This could take a while... ERROR:  Error installing pg: ERROR: Failed to build gem native extension.     /home/sabyasachi/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb checking for pg_config... y

How To Install PostgreSQL on Ubuntu 12.04

Step 1: Before postgres install, we should quick perform a quick update. apt-get update Step 2: Now install Postgres using the command line.   sudo apt-get install postgresql postgresql-contrib This will install the latest version available in your Ubuntu. Step 3: Install the client   sudo apt-get install postgresql-client Step 4:  For a handy GUI for PostgreSQL install pgAdmin III.  sudo apt-get install pgadmin3 Step 5:  We need to change the PostgreSQL postgres user password; sudo -u postgres psql postgres Set a password for the "postgres" database role using the command: \password postgres Step 6: Exit from Postgres   \q That's it we are done with the installation.  

Set up Neo 4j With Rails In Ubuntu

How to setup new 4j database with Rails 4. Step 1: Install Neo4j Database in ubuntu.   login as Admin  sudo -i  wget -O - http://debian.neo4j.org/neotechnology.gpg.key | apt-key add -  Add Neo4J to the Apt sources list:   echo 'deb http://debian.neo4j.org/repo stable/' > /etc/apt/sources.list.d/neo4j.list  Update the package manager:  exit as admin  apt-get update  Install Neo4J:  apt-get install neo4j  sudo /etc/init.d/neo4j-service restart Step 2: Create a new rails project.  Rails new neo4j Step 3:  Add neo4j Gem in your gem file   gem 'neo4j', github: 'andreasronge/neo4j' Step 4: Go to application.rb require File.expand_path('../boot', __FILE__) require "rails" %w(   neo4j   action_controller   action_mailer   sprockets ).each do |framework|   begin     require "#{framework}/railtie"   rescue LoadError   end end # Require the gems listed in Gemfile, including any gems # you've

Creating RESTful API using Grape and RABL in Rails 4

We can create a RESTful API using Grape and RABL in Rails4. Step 1: Add this GEMS in your Gem file, And do Bundle install.  gem 'grape'  gem 'rabl-rails'  gem 'grape-rabl'  gem 'rack-cors', :require => 'rack/cors' Step 2: Create a file under lib directory called api.rb, and create a folder inside the view named as api. # lib/api/v1/root.rb class API < Grape::API end Step 3: Add this line to your application.rb file    config.paths.add "app/api", glob: "**/*.rb"     config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/api/*)     config.middleware.use Rack::Cors do       allow do         origins '*'         # location of your API         resource '/*', :headers => :any, :methods => [:get, :post, :options, :put, :delete]       end     end     config.middleware.use(Rack::Config) do |env|       env['api.tilt.root'] = Rails.root.join "app", "

Set up Jruby with apache and passenger in EC2

How to set up jruby with apache and passenger in amazone ec2. Step 1: First install jruby using please check the current version in the   link . And make sure you are installing the bin version of it wget 'http://jruby.org.s3.amazonaws.com/downloads/1.7.4/jruby-bin-1.7.4.tar.gz' Step 2: extract the tar file using tar zxvf jruby-bin-1.7.4.tar.gz Step 3: We need to set come environment variable so that it will be accessible from every other place. export JRUBY_HOME=/home/home_directory_name/jruby-1.7.4 export PATH=$JRUBY_HOME/bin:$PATH And Open the .bashrc file and put the path in their sudo nano ~/.bashrc PATH=$PATH:/home/ubuntu/jruby-1.7.4/bin Step 4: Now to check if jruby is properly installed or not put jruby-v If your system does not have java installed then it will show an error like /home/ubuntu/jruby-1.7.4/bin/jruby: line 395: exec: java: not found Don't worry we will install java to fix this. sudo apt-get install openjdk-7-jdk apt-cache

Set up ruby 2.0 and Rails 4.0.1 in Rackspace

First we need to install ruby Step 1)Install Ruby apt-get -y update apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev cd /tmp wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz tar -xvzf ruby-2.0.0-p247.tar.gz cd ruby-2.0.0-p247/ ./configure --prefix=/usr/local make make install Step 2) Install Rails gem install rails 4.0.1 Step 3) Install passenger gem install passenger Step 4) Install Apache2 apt-get install apache2 Step 5) Install Mysql sudo apt-get install mysql-server mysql-client That's it we are done with the setup.

Active resource in rails

This is a powerful feature of rails to communicate between two models in two different application running in two different server. ActiveResource:Base is the main class for mapping RESTful resources as models in a Rails application. Active Resource objects represent your RESTful resources as manipulatable Ruby objects. To map resources to Ruby objects, Active Resource  only needs a class name that corresponds to the resource name (e.g., the class User maps to the resources Products, very similarly to Active Record) and a site value, which holds the URI of the resources. class User < ActiveResource::Base   self.site = "http://api.products.com:3000/" end In order to access products.com controller you need to send the json response like i am going to call the index action so we need to write :- def index @products = Product.all respond_to do |format| format.json { render :json => @products} end end Now the User class is mapped to RESTful resources located

How Action Mailer Works in Rails

Sending emails in a rails application is very easy and quite handy using action mailer. First we will go through the basic setup of action mailer then we will go in details how it works. Step 1   We can setup a mailer class using rails generator   rails generate mailer UserMailer Step 2   Then we can create any instance method inside it.     def welcome_email(user)       @user = user       @url  = 'http://example.com/login'       mail(to: @user.email, subject: 'Welcome')     end Step 3   We can call this method form model or controller or any kind of callbacks using    Like     UserMailer.welcome_email(@user).deliver Step 4   You can set up a view template for the welcome_email in side the views/mailer directory   Like   welcome_email.html.erb   and you can specify the layout format here and can also access the instance variables defined in the       welcome_email(user) method Step 5   Additionally we can set up the smtp configuration inside

Interesting ubuntu trick

1) tail cannot watch no space left on device.    Solutions   a)  echo 900000 | sudo tee /proc/sys/fs/inotify/max_user_watches      Or Place   b) "fs.inotify.max_user_watches=16384" in /etc/sysctl.conf 2)  How to remove all files and sub-directories in a directory WITHOUT deleting the directory in bash? Solutions rm -rfv dontDeleteMe/*

How to upload Bulk file in rails 3 application

If you want to upload bulk file in rails application just follow the following steps 1) create a rails application     rails new bulk_upload 2) Add passenger in your gem file     gem 'passenger' Now try to start with your rails application with the command   passenger start by default it will run on port number 3000 Now if you try to upload bulk files lets just say more than 500 mb or 800 mb you will get an error in the time of uploading like [ error] 4840#0: *557 client intended to send too large body: 94672000 bytes, client: 127.0.0.1, server: _, request: "POST /XXX HTTP/1.1", host: "localhost:3000" so this not error of you application this is the error thrown by passenger and ngnix which is responsible to run passenger First uninstall using purge to remove even configuration files and records:   apt-get purge nginx nginx-common nginx-full Then reinstall it  apt-get install nginx If above doesn't work for you you can also