Posts

Showing posts from 2017

Deploy Ruby On Rails application on production AWS Ec2 server

1. Give 400 permission to pem file. sudo chmod 400 example.pem 2. Login on server.  ssh -i  example. pem file ubuntu@ip_address ------------------------------ ------------------------------ ---------- 3. You can check ubuntu server details by: lsb_release -a No LSB modules are available. Distributor ID:    Ubuntu Description:    Ubuntu 16.04.2 LTS Release:    16.04 Codename:    xenial ------------------------------ ------------------------------ ---------- 4. Install the required libraries: sudo apt-get update sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs yarn sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev gpg --keyserver hkp:// keys.gnupg.net  --recv-keys 409B6B1796C275462A1703113804BB 82D39DC0E3 curl -sSL  https://get.rvm.io  | bash -s stable source

Integrate faye gem on server with nginx

I was getting follwing error on server. ActionView::Template::Error (Failed to open TCP connection to localhost:9292 (Connection refused - connect(2) for "localhost" port 9292)) It can be fixed by following options: sudo nano /etc/nginx/sites-available/default location /faye {     proxy_pass  http://localhost:9292 ;      proxy_set_header Host $host;      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;      proxy_set_header X-Real-IP $remote_addr;      proxy_connect_timeout 90;      proxy_send_timeout 90;      proxy_read_timeout 90;      proxy_set_header X-Forwarded-Proto https;      break; } rackup  private_pub.ru  -s thin -E production -D

Failed to connect to localhost port 9200: Connection refused

From a fresh install of Ubuntu 16.04: sudo apt-get install elasticsearch After that, the following should work but doesn't: sudo /bin/systemctl daemon-reload sudo /bin/systemctl enable elasticsearch.service sleep 10 curl  http://localhost:9200/ Despite that, the following does work: sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch & sleep 10 curl  http://localhost:9200/

Clear Linux cache

sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

Optimize images on ubuntu

JPG: find . -name '*.jpg' -execdir mogrify -strip  {} \; PNG: find . -name '*.png' -execdir mogrify -strip  {} \;

Install redis server on Elastic beanstalk

In .ebextensions/ruby.config packages:   yum:     gcc-c++: []     make: [] sources:   /home/ec2-user: http://download.redis.io/releases/redis-2.8.4.tar.gz commands:   redis_build:     command: make     cwd: /home/ec2-user/redis-2.8.4   redis_config_001:     command: sed -i -e "s/daemonize no/daemonize yes/" redis.conf     cwd: /home/ec2-user/redis-2.8.4   redis_config_002:     command: sed -i -e "s/# maxmemory <bytes>/maxmemory 500MB/" redis.conf     cwd: /home/ec2-user/redis-2.8.4   redis_config_003:     command: sed -i -e "s/# maxmemory-policy volatile-lru/maxmemory-policy allkeys-lru/" redis.conf     cwd: /home/ec2-user/redis-2.8.4   redis_server:     command: src/redis-server redis.conf     cwd: /home/ec2-user/redis-2.8.4

Set database.yml in rails

Database.yml is one of the most important files in rails project, database.yml rails is actualy a configuration file. What is Contains? Database.yml is configuration file which tells rails about database, database information such as Paramter Description host  URL of the Host Machine where database is installed. If over a network then IP/Web address and if local then 127.0.0.1 database  The name of database to be selected. Rails way is mydb_development username  The username of the database chosen password  password for the user account with given username to the database adaptor  Type of database being used for the Rails application (can be any MySQL/Oracle/Sqlite... etc) pooling  Related to maximum number of connections to be made with database There are such multiple configurations here in this file. You need to write appropriate values in this configuration based on the Database you are using, and host/machine of the DB. If you want to use  MySQL Database.y

Get video duration by URL in Ruby on Rails

First install ffmpeg on your system  http://ffmpeg.org/download.html OR sudo add-apt-repository ppa:mc3man/trusty-media And confirm the following message by pressing <enter>: Also note that with apt-get a sudo apt-get dist-upgrade is needed for initial setup & with some package upgrades More info: https://launchpad.net/~mc3man/+archive/ubuntu/trusty-media Press [ENTER] to continue or ctrl-c to cancel adding it Update the package list. sudo apt-get update sudo apt-get dist-upgrade Now FFmpeg is available to be installed with apt: sudo apt-get install ffmpeg In Controller: your_video_path =  https://s3-us-west-2.amazonaws.com/its-get-brighter-staging/uploads/video/video/2/Planking.mp4 result = `ffmpeg -i #{your_video_path} 2>&1` videotime = result.match("Duration: ([0-9]+):([0-9]+):([0-9]+).([0-9]+)")[0].split("Duration: ").last.split(".").first

Display title, description and image by sharing URL on facebook

Put below meta tags into your web application:   <meta property="fb:app_id" content="768103839966918" />   <meta property="og:title" content="Nice title" />   <meta property="og:type" content="article" />   <meta property="og:author" content="Arvind" />   <meta property="og:description" content="This is nice description here" />   <meta content="https://dreamermade-staging.s3.amazonaws.com/uploads/project/image/17/project_bittern-square-logo.png" itemprop="image">   <meta content='https://dreamermade-staging.s3.amazonaws.com/uploads/project/image/17/project_bittern-square-logo.png' property="og:image" >   <meta content="690" property="og:image:width">   <meta content="225" property="og:image:height">   <meta content="origin" id="

Get Gmail contacts in Ruby on rails

>> If you are looking for the functionailty for fetching the  google contacts  than you can follow the below mentioned instructions. >> Firstly You need to define the  google contact and contact groups url  in the scope for fetching the google contacts. It will allow our retrieve access token to use google contact api. >> We can define multiple scopes with the google keys :    config.omniauth :google_oauth2, client_id, client_secret, {       name: 'google',       scope: 'email https://www.google.com/m8/feeds/'   } >> In the scope I have defined  email  for   ( user's email access access )  and  https://www.google.com/m8/feeds/  for  ( read/write access to Contacts and Contact Groups ) >> I am assuming you have added the omniauth-google-oauth2 gem and added the functionality of auth login. >> After successful auth login when you will return back to the website using callback method with some josn. You can see that us

Adaptive paypal to pay multiple paypal accounts at once

Add gem:  gem 'paypal-sdk-adaptivepayments' In views: <div class="modal-body">               <%= form_for cart.build_payment, class: "form-horizontal", role: "form" do |f| %>                 <%=  f.hidden_field :cart_id, :value => cart.id %>                 <% url = "#{baseUrl}/subscriptions/subscription_create?cart_id=#{cart.id}&subscriptions=true" %>                 <%=  f.hidden_field :url, :value => url %>                 <div class="form-group">                   <label class="control-label col-sm-2" for="email">First Name:</label>                   <div class="col-sm-10">                     <%= f.text_field :first_name, class: "form-control", placeholder: "Enter the First Name", required:true %>                   </div>                 </div>                 <div class=&qu