Tuesday, 10 December 2019

Shopify App (with shopify gem in rails)

Shopify App 

https://github.com/Shopify/shopify_app

1- # Create a new rails app 
        $ rails new my_shopify_app 
        $ cd my_shopify_app
 

2- # Add the gem shopify_app to your Gemfile  

          "gem 'shopify_app'"
           bundle install
         
Now we are ready to run any of the shopify_app generators. The following section explains the generators and what they can do.

3- Default Generator

The default generator will run the install, shop, and home_controller generators. This is the recommended way to start your app.
     
        $ rails generate shopify_app
 
 After run this cmd generated file list is here.

 generate  shopify_app:install
Running via Spring preloader in process 7234
     gemfile  dotenv-rails
      create  config/initializers/shopify_app.rb
      create  config/initializers/session_store.rb
      create  config/initializers/omniauth.rb
      insert  config/initializers/omniauth.rb
      create  app/views/layouts/embedded_app.html.erb
      create  app/views/layouts/_flash_messages.html.erb
      create  app/assets/javascripts/shopify_app.js
      create  app/assets/javascripts/flash_messages.js
      create  config/initializers/user_agent.rb
       route  mount ShopifyApp::Engine, at: '/'
      insert  config/environments/development.rb
    generate  shopify_app:shop_model
Running via Spring preloader in process 7254
      create  app/models/shop.rb
      create  db/migrate/20191210084729_create_shops.rb
        gsub  config/initializers/shopify_app.rb
      create  test/fixtures/shops.yml
    generate  shopify_app:authenticated_controller
Running via Spring preloader in process 7277
      create  app/controllers/authenticated_controller.rb
    generate  shopify_app:home_controller
Running via Spring preloader in process 7281
      create  app/controllers/home_controller.rb
      create  app/views/home/index.html.erb
     prepend  app/views/home/index.html.erb
       route  root :to => 'home#index'

4-  After running the generator, you will need to run rake db:migrate to add 
     tables to your database. You can start your app with bundle exec rails server 
     and install your app by visiting localhost.

5- The default and install generators have been updated to source Shopify API 
    key and secret from a .env file, which you will need to create with the 
    following format:
       SHOPIFY_API_KEY=your api key
       SHOPIFY_API_SECRET=your api secret
  
These values can be found on the "App Setup" page in the Shopify Partners Dashboard.(when you create a account on shopify and after create a app then u get api key and api secret )

6- Install Generator
        rails generate shopify_app:install

After running the install generator, you can start your app with bundle exec rails server and install your app by visiting localhost.

7- Shop Model Generator
       rails generate shopify_app:shop_model

This generator creates a shop model and a migration. This model includes the ShopifyApp::SessionStorage concern which adds two methods to make it compatible as a SessionRepository. After running this generator you'll notice the session_repository in your config/initializers/shopify_app.rb will be set to the Shop model. This means that internally ShopifyApp will try and load tokens from this model.
           identical  app/models/shop.rb
           identical  db/migrate/20191210084729_create_shops.rb
           gsub  config/initializers/shopify_app.rb
           identical  test/fixtures/shops.yml



Note that you will need to run rake db:migrate after this generator
 




8- Home Controller Generator
         rails generate shopify_app:home_controller

This generator creates an example home controller and view which fetches and displays products using the ShopifyAPI

         identical  app/controllers/home_controller.rb
         force  app/views/home/index.html.erb
         prepend  app/views/home/index.html.erb
         route  root :to => 'home#index' 


9- App Proxy Controller Generator
          rails generate shopify_app:app_proxy_controller

 This optional generator, not included with the default generator, creates the app proxy controller to handle proxy requests to the app from your shop storefront, modifies 'config/routes.rb' with a namespace route, and an example view which displays current shop information using the LiquidAPI.

           create  app/controllers/app_proxy_controller.rb
           create  app/views/app_proxy/index.html.erb
           insert  config/routes.rb

 
 10- Controllers, Routes and Views

The last group of generators are for your convenience if you want to start overriding code included as part of the Rails engine. For example by default the engine provides a simple SessionController, if you run the rails generate shopify_app:controllers generator then this code gets copied out into your app so you can start adding to it. Routes and views follow the exact same pattern.

after run this cmd create files:
      create  app/controllers/shopify_app/authenticated_controller.rb
      create  app/controllers/shopify_app/callback_controller.rb
      create  app/controllers/shopify_app/sessions_controller.rb
      create  app/controllers/shopify_app/webhooks_controller.rb

  
 11- Routes
           mount ShopifyApp::Engine, at: '/'


     * update the omniauth initializer to include a custom callback_path
 

          provider :shopify,
             ShopifyApp.configuration.api_key, 
             ShopifyApp.configuration.secret, 
             scope: ShopifyApp.configuration.scope, 
             callback_path: '/auth/shopify/callback'




  
   
Finally, note that if you do this, to add your app to a store, you must navigate to / in order to render the Enter your shop domain to log in or install this app.

          UI  (example.myshopify.com) when run localhost:3000/login

12- Custom login URL

While you can customize the login view by creating a /app/views/shopify_app/sessions/new.html.erb file, you may also want to customize the URL entirely. You can modify your shopify_app.rb initializer to provide a custom login_url

           ShopifyApp.configure do |config|
              config.login_url = 'https://my.domain.com/nested/login'
           end
 



















13- Per User Authentication 

To enable per user authentication you need to update  the omniauth.rb  initializer:

        provider :shopify,
          ShopifyApp.configuration.api_key,
          ShopifyApp.configuration.secret,
          scope: ShopifyApp.configuration.scope,
          per_user_permissions: true
 
 
The current Shopify user will be stored in the rails session at session[:shopify_user]

This will change the type of token that Shopify returns and it will only be valid for a short time. Read more about Online access here. Note that this means you won't be able to use this token to respond to Webhooks.

14- WebhooksManager

rails g shopify_app:add_webhook -t carts/update -a http://localhost:3000/webhooks/carts_update

invoke  test_unit
      create    test/jobs/carts_update_job_test.rb
      insert  config/initializers/shopify_app.rb
      insert  config/initializers/shopify_app.rb
      create  app/jobs/carts_update_job.rb


ShopifyApp can manage your app's webhooks for you if you set which webhooks you require in the initializer:

 ShopifyApp.configure do |config|
     config.webhooks = [
          {topic: 'carts/update', address: 'http://localhost:3000/webhooks 

          /carts_update', format: 'json'},
     ]

 end

15- AfterAuthenticate Job

We've also provided a generator which creates a skeleton job and updates the initializer for you:
       bin/rails g shopify_app:add_after_authenticate_job

invoke  test_unit
      create    test/jobs/shopify/after_authenticate_job_test.rb
      insert  config/initializers/shopify_app.rb
Error adding after_authenticate_job to config. Add this line manually:   config.after_authenticate_job = { job: "Shopify::AfterAuthenticateJob", inline: false }
      create  app/jobs/shopify/after_authenticate_job.rb

 

 To configure the after authenticate job update your initializer as follows:

         ShopifyApp.configure do |config|
              config.after_authenticate_job = { job:"Shopify::AfterAuthenticateJob", 
               inline: false }
         end










 

Tuesday, 26 November 2019

Error Handling in rails


Error Handling — Modular Approach



1. app/controllers/application_controller.rb
        class ApplicationController < ActionController::Base
        # Prevent CSRF attacks by raising an exception.
        # For APIs, you may want to use :null_session instead.
        protect_from_forgery with: :exception
        include Error::ErrorHandler
     end
 
2. Let’s refactor the ErrorModule to accommodate multiple
    error handling blocks. It looks much cleaner this way.
     lib/error/error_handler.rb
       # Error module to Handle errors globally
      # include Error::ErrorHandler in application_controller.rb
# Refactored ErrorHandler to handle multiple errors
# Rescue StandardError acts as a Fallback mechanism to handle any exception
module Error
  module ErrorHandler
    def self.included(clazz)
      clazz.class_eval do
        rescue_from ActiveRecord::RecordNotFound do |e|
          respond(:record_not_found, 404, e.to_s)
        end
        rescue_from StandardError do |e|
          respond(:standard_error, 500, e.to_s)
        end
      end
    end

    private
    
    def respond(_error, _status, _message)
      json = Helpers::Render.json(_error, _status, _message)
      render json: json
    end
  end
end
 
3. Define your own Exception (lib/error/custom_error.rb)
module Error
  class CustomError < StandardError
    attr_reader :status, :error, :message

    def initialize(_error=nil, _status=nil, _message=nil)
      @error = _error || 422
      @status = _status || :unprocessable_entity
      @message = _message || 'Something went wrong'
    end

    def fetch_json
      Helpers::Render.json(error, message, status)
    end
  end
end
 
Custom Error File Name:- (lib/error/not_visible_error.rb)
module Error
  class NotVisibleError < CustomError
    def initialize
      super(:you_cant_see_me, 422, 'You can\'t see me')
    end
  end
end
 
4. 404 and 500
You can handle common exceptions like 404 and 500, although it’s totally up to the developer. We need to create a separate controller class, ErrorsController for it.
Error Controller File Name:-(controllers/errors_controller.rb)
class ErrorsController < ApplicationController
  def not_found
    render json: {
      status: 404,
      error: :not_found,
      message: 'Where did the 403 errors go'
    }, status: 404
  end

  def internal_server_error
    render json: {
      status: 500,
      error: :internal_server_error,
      message: 'Houston we have a problem'
    }, status: 500
  end
end
5. We just have to add the following line to application.rb.
        config.exceptions_app = routes 
 6. Tell Rails to use Routes to resolve exceptions.
      Rails.application.routes.draw do
       get '/404', to: 'errors#not_found'
       get '/500', to: 'errors#internal_server_error'

       root 'home#index'
       get 'not_visible', to: 'home#not_visible'

     end
Now 404 exceptions fallback to errors#not_found and 500 to errors#internal_server_error.


Error Handling Link:-
https://medium.com/rails-ember-beyond/error-handling-in-rails-the-modular-way-9afcddd2fe1b

Pundit Gem in rails for authorization


Pundit Gem 

1. Add pundit gem in your Gemfile. gem "pundit"
2. Run Command bundle install.
3.  Include Pundit in your application controller:
       
class ApplicationController < ActionController::Base
          include Pundit
          protect_from_forgery
   
            (For Error Message)
            rescue_from Pundit::NotAuthorizedError, 
            with: :user_not_authorized
            def user_not_authorized
            flash[:warning] = "You are not authorized to perform this
              action."
            redirect_to(request.referrer || root_path)
          end
        end

4.  Optionally, you can run the generator, which will set up
     an application policy with some useful defaults for you:
         
rails g pundit:install

         After generating your application policy, restart the Rails  

         server so that Rails can pick up any classes in the new  
         app/policies/ directory.

5.  We suggest that you put these classes in app/policies.
     File name:- (app/policies/user_policy.rb) 
      
       
class UserPolicy < ApplicationPolicy
          attr_reader :current_user
     
          def initialize(current_user, user)
            @current_user = current_user
            @user = user
          end   

          def index?
           (@current_user.has_role? :administrator) ||  

           (@current_user
           ==  @user)
          end

          def show?
            false
          end

          def create?
            false
          end

          def new?
            create?
          end

          def update?
            (@current_user.id == @user.id) || 
            ((@current_user.has_role? :administrator) and not 
            (@user.has_role? :administrator))
          end

          def edit?
            (@current_user.id == @user.id) || 
            ((@current_user.has_role? :administrator) and not       
            (@user.has_role? :administrator))
          end

          def destroy?
            (@current_user.id == @user.id) || 
            ((@current_user.has_role? :administrator) and not
            (@user.has_role? :administrator))
          end 
        end

6.  The authorize method automatically infers that User will  

     have a matching UserPolicy class, and instantiates this   
     class, handing in the current user and the given record.  
      File Name:-  (controllers/users_controller.rb)
         
def index
            authorize @user
          end

          def edit
            authorize @user
          end
           
          def update
            if @user.update(user_params)
              redirect_to user_path(@user), notice: 'User was
                successfully updated.'
              authorize @user
            else
              render :edit, alert: "Sorry. Something isn't right."
            end
          end

          def destroy
            if @user.destroy
              redirect_to users_path, notice: 'User was successfully 
                destroyed.'
              authorize @user
            else
              redirect_to user_path(@user), alert: "Sorry. Something isn't  

               right."
            end
          end

7.  Policy File Name:- (app/policies/event_policy.rb)


       
class EventPolicy < ApplicationPolicy
          attr_reader :current_user

          def initialize(current_user, event)
            @current_user = current_user
            @event = event
          end

          def update?
            (@current_user.has_role? :administrator)
          end
             
          def edit?
            (@current_user.has_role? :administrator)
          end

          def destroy?
            (@current_user.has_role? :administrator)
          end 
        end

8.  Controller File Name:-  (events_controller.rb)


       
class EventsController < ApplicationController

          def edit
            @event = Event.find params[:id]
            authorize @event
          end

          def update
            @event = Event.find(params[:id])
            authorize @event
             end

          def destroy
            @event = Event.find(params[:id])
            authorize @event
          end

        end

9. Policy File Name:- (app/policies/artist_policy.rb)


       
class ArtistPolicy < ApplicationPolicy
          attr_reader :current_user

          def initialize(current_user, artist,user)
            @current_user = current_user
            @user = user
            @artist = artist
          end
           
          def update?
            ((@current_user.id == Artist.where(slug:
              @artist.slug).first.id) ||
            (@current_user.has_role? :administrator))
          end

          def edit?
            ((@current_user.id == Artist.where(slug:
               @artist.slug).first.id) ||
            (@current_user.has_role? :administrator))
          end

          def destroy?
            ((@current_user.id == Artist.where(slug:
                @artist.slug).first.id) ||
            (@current_user.has_role? :administrator))
          end
           
        end

Monday, 18 November 2019

React moment tag for datepicker/REACT-Day-PICKER

REACT-Day-PICKER

1. Install as dependency to use it in your project:
       npm install react-day-picker --save 

2. Then import the component and its style into your component:
      import DayPicker from 'react-day-picker';
 
     // Or import the input component
     import DayPickerInput from 'react-day-picker/DayPickerInput';

     import 'react-day-picker/lib/style.css';
 
3.  import DayPicker from 'react-day-picker';
   // Or import the input component
    import DayPickerInput from 'react-day-picker/DayPickerInput';
    import 'react-day-picker/lib/style.css';
    import MomentLocaleUtils, {formatDate,parseDate} from 'react-day-picker/moment';
    import 'moment/locale/it';

4. <DayPickerInput inputProps={{ className: 'form-control' }}
 formatDate={formatDate}
 parseDate={parseDate}
 format="LL"
 placeholder={`${formatDate(new Date(),'LL')}`}
 dayPickerProps={{
  localeUtils: MomentLocaleUtils,
 }}
    />

 React moment tag for datepicker

1. Installing :- npm install --save moment react-moment
2. Timezone support:- npm install --save moment-timezone
3. import Moment from 'react-moment';
4. 
 

Sunday, 17 November 2019

How to use datepicker gem in rails

 How to use datepicker gem in rails



1. Include bootstrap-datepicker-rails in Gemfile
     gem 'bootstrap-datepicker-rails'

2. Add this line to app/assets/stylesheets/application.css
   *= require bootstrap-datepicker3

3. Add this line to app/assets/javascripts/application.js
     //= require jquery3
     //= require bootstrap-sprockets
    //= require bootstrap-datepicker 



Thursday, 7 November 2019

ssh key open cmd in terminal

ssh key open cmd in terminal 

cat ~/.ssh/id_rsa.pub 

How to heroku database import 

heroku pg:backups:capture
heroku pg:backups:download
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump

Wednesday, 23 October 2019

Configuring Git

#### If you want to use SQLite (not recommended)
rails new myapp
 
#### If you want to use MySQL
rails new myapp -d mysql
 
#### If you want to use Postgres
# Note that this will expect a postgres user with the same username
# as your app, you may need to edit config/database.yml to match the
# user you created earlier
rails new myapp -d postgresql  
 
# Move into the application directory
cd myapp

# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified

# Create the database
rake db:create

rails server 

Wednesday, 16 October 2019

Mobile Rails API with Devise

Mobile Rails API with Devise

https://jee-appy.blogspot.in/2016/03/how-to-make-rest-api-in-rails.html

1. rails g migration AddAuthenticationtokenToUsers authentication_token:string

2. rails generate controller Api/V1/Api

3. create a user model (User.rb)

       class User < ApplicationRecord
         devise :database_authenticatable, :registerable,
               :recoverable, :rememberable, :validatable

        before_save :ensure_authentication_token
       
           def ensure_authentication_token
          if authentication_token.blank?
            self.authentication_token = generate_authentication_token
          end
        end

        private
        def generate_authentication_token
            loop do
              token = Devise.friendly_token
              break token unless User.find_by(authentication_token: token)
            end
        end

      end

4. ApiController

      class Api::V1::ApiController < ApplicationController
        def create
       
        end

        def destroy
       
        end

        respond_to :json
        helper_method :current_user
        def getting_started
        end

        def current_user
          @current_user ||= User.where(authentication_token:  
                request.headers['User-Token']).first
        end

        def authenticate_user!
          return render json:{error:'401 Unauthorized!'},status: 401 unless 
            current_user
        end

      end

5. ApplicationController

     class ApplicationController < ActionController::Base
        before_action :configure_permitted_parameters, if: :devise_controller?

        protected

        def configure_permitted_parameters
            devise_parameter_sanitizer.permit(:sign_up) do |user|
            user.permit(:email, :password,:password_confirmation, :remember_me)
          end
            devise_parameter_sanitizer.permit(:sign_in) do |user|
            user.permit(:email, :password)
          end
            devise_parameter_sanitizer.permit(:account_update) do |user|
            user.permit(:email, :password,:password_confirmation, 
              :current_password)
          end
        end

    end

6. routes.rb

       namespace :api do
        namespace :v1 do
          devise_scope :user do
            post "/sign_in", :to => 'sessions#create'
            post "/sign_up", :to => 'registrations#create'
            get "/sign_up", :to => 'registrations#create'
            put '/change_password', to: 'registrations#change_password'
            get "/profile", :to => 'registrations#profile'
            post "/update_account", :to => 'registrations#update'
            # delete "/sign_out", :to => 'sessions#destroy'
            # get "/reset_password", :to => 'registrations#reset_password'
            # get "/reset_password_link", :to => 'registrations#reset_password_link'
          end
        end
      end

Flow of registration controller :=>
Sign Up

1. routes.rb
       post "/sign_up", :to => 'registrations#create'
       get "/users", :to => 'registrations#index'

2. registrations_controller.rb

class Api::V1::RegistrationsController < Api::V1::ApiController
 
   /*--------------------------------------  Create   -------------------------------------------------*/
        def new
          user = User.new
        end

        def create
          user = User.new(registration_params)
           if user.save
              return render json: {status: 200, data: {user: user}, :message
                 =>"Successfuly Signup"}
          else
             warden.custom_failure!
             return render json: {status: 401, data: {user: nil, errors: 
                user.errors}, :message =>"SignUp Rollback"}
          end
       end
  /*--------------------------------------  Index   -------------------------------------------------*/
       def index
         user = User.all
        if user.present?
          return render json: {status: 200, data: {user: user}, :message =>"All
             Users"}
        else
          return render json: {status: 401, data: {user: nil, errors: user.errors},
             :message =>" Rollback"}
        end
      end
  /*--------------------------------------  Update   -------------------------------------------------*/
     first select which user update so please select user token 
        def update
           user =  current_user
            if params[:user][:email].present?
              user.email = params[:user][:email]
            end
            if params[:user][:password].present?
             user.password = params[:user][:password]
            end
           if user.save
              return render json: {status: 200, data: {user: user}, :message
                   =>"User Profile Successfully Updated"}
          end
       end  
/*--------------------------------------  Destroy   -------------------------------------------------*/
     def destroy
       
     end

end

3. sessions_controller.rb

    class Api::V1::SessionsController < Api::V1::ApiController
       
            def create
              email = params[:user][:email]
              password = params[:user][:password]
             @user = User.where(email: email).first
                 return render json: {status: 200, data: {user: @user}, message:  
                    "Login Successful"}
           end

           def destroy
           end








    end
 

      




Tuesday, 15 October 2019

Social login facebook,twitter ..

Social Login fb/twitter/linkedin

1. Gemfile:

    gem "oauth"
    gem "oauth2"
    gem 'omniauth-oauth2'
    gem 'omniauth-facebook'
    gem 'omniauth-twitter'
    gem 'omniauth-google-oauth2'
    gem 'omniauth-linkedin'
    gem 'omniauth-github'
    gem 'omniauth-pinterest'

2. Model generate:

   rails g model authentication provider:string uid:string user_id:integer  
   token:text token_expired_at:datetime

3. app/model/authentication.rb:
class Authentication < ActiveRecord::Base
    
     belongs_to :user
     # validates :provider, :uid, :presence => true
     def self.from_omniauth(auth)
    if auth[:provider] == "twitter"
        email =  auth[:info][:nickname] + '@' + 'gmail.com'
    end

    if auth[:provider] == "linkedin"
        email =  auth.extra.raw_info.requestId.to_s+"@gmail.com"
    else
        email = auth[:email].present? ? auth[:email] :  auth[:info][:email]
    end

    if auth[:provider] == "instagram"
        email =  auth[:info][:nickname] + '@' + 'gmail.com'   
    end
   
            authenticate = where(provider: auth[:provider], :uid=>auth[:uid]).first_or_initialize
    if authenticate.user
         authenticate.provider = auth[:provider]
        authenticate.uid =auth[:uid]
    else
        if auth['provider'].downcase == "facebook"
           email = auth[:email].present? ? auth[:email] :  auth[:uid].to_s+"@facebook.com"
        elsif auth['provider'].downcase == "google"
            email = auth[:email].present? ? auth[:email] :  auth[:uid].to_s+"@google.com"
        end
        user = User.find_or_initialize_by(:email => email)
        authenticate.provider = auth[:provider]
        authenticate.uid = auth[:uid]
        user.email = email
        user.save(validate: false)
        authenticate.user_id = user.id
       end
            authenticate.save
            authenticate.user
     end
    
end

4. User.rb
      # before_create :confirmation_token
       has_many :authentications, dependent: :destroy
       validates :email, :uniqueness => {:allow_blank => true}

5. Config/initializers/omniauth.rb
      Rails.application.config.middleware.use OmniAuth::Builder do

         provider :facebook, '433592010474964',   
             '547da79dec038a932f4c846986398f63'
         provider :linkedin, '81q662zzjusm67', 'xZyEHlGAaZI8Gm9q'
         provider :google_oauth2,      
           244615150400-05thnta81fhg631up71t8v7e167i8pta.apps.googleusercontent.com',   'XW9LFZYGtLjruVh9kOpmCaRY'
        provider :twitter, 'y6kILe3VwuGpaFIIfPXdnv8pw',    
            'Gb76xJS6ZvTrzzxp0jNFLnZG2nNhNaaNPfx5FAWLrL5y11e14D'

     end

6. routes.rb
       match '/auth/:provider/callback', :to => 'sessions#create', via: [:get, :post]
       match '/auth/failure', :to => 'sessions#failure', via: [:get, :post]

7. app/controller/sessions_controller.rb
      
  class SessionsController < ApplicationController

     # skip_before_action :authenticate_user!
  def create
    user = Authentication.from_omniauth(request.env["omniauth.auth"])
    if user
      flash[:notice] = "Authentication successful."
      sign_in(user)
      sign_in_and_redirect(user)
    else
        flash[:notice] = "Authentication Failed."
    end
  end
 
end

8. Add links
       
<li><a href="/auth/facebook" class="icoFacebook ib" title="Facebook"><i class="fa fa-facebook"></i></a></li>
              <li><a href="/auth/twitter" class="icoTwitter ib" title="Twitter"><i class="fa fa-twitter"></i></a></li>
              <li><a href="/auth/google_oauth2" class="icoGoogle ib" title="Google +"><i class="fa fa-google-plus"></i></a></li>
              <li><a href="/auth/linkedin" class="icoLinkedin ib" title="Linkedin"><i class="fa fa-linkedin"></i></a></li>




Start server in https mode for facebook login 
  Step 1:- Gemfile  
         group :development do
            gem 'thin'
        end
Step 2: bundle install
Step 3: Start server ( thin start --ssl )
Step 4: https://localhost:3000

Thursday, 10 October 2019

ssh key add gen

How to find ssh key of any System (PC)

1.  cat ~/.ssh/  
     output:-   id_rsa       id_rsa.pub   known_hosts  system ssh/
2.  cat ~/.ssh/id_rsa.pub
     
output:-  ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCeD9RuCKA9ZvJMSgTTi29iHJk0ZDoO6UKvT8XsmNdeq+FtW6NW1gdfRDAw+nfhWyTwxKpATbR5OrsvrY2JmqWAOfOeEwOZf7LMVta9pxakiO80Jt+EUAs1SGRZr8BA8bvP5cX617598UJZG2j+uenk36cBUhcMWks6JYGP5EK//XvsN0S5PW0lD2C0S1I3Cfe9DSEiUhCU4COgOHMYzKOhgyhNDLzHbAaf6TlGCls/gIqat4E2au6AQsnl/IX2vY/KqgWLdQpHkjwAUgXuIH+KVAW3ye2s3xPNGwfWWgxd30nhrLFLdK28T5LEUz81MRLc23sej9+prG9ZLpBpMg5RqJrLuZocPkUWsctMqVdzQipdMPZu1qdWfTQFwjJO8ARyP3SJdt7DuTTX3IscaPnut8oUXx16yFoOLQmq2gGuu63+niB5rv/0bcTQoNhYCCUGboOMp5AwKjTcJDT4J/wrPXarheH5dzXk6X5x8C2IVGl2RScyf8KQijL28tj/awc4wgB671VbQk3GvUyzteTjcXKzfrMKRn0FUCCrdEGVU2Dv3SqOkB7lcTGYOQP7gLUc8uBPenFq76nqQJzhXdrz+CLS+SXveDZEiY5XU0GAXFXrvMNQ5hmai5jver8hBXeztcNrdOOYLjAqKaKBKHMe9Q4uRCil2Zkr62DcyInZgQ== shikha@bittern.co

3. set git config username and email
     
     git config user.name "Arvind Kushwah"
     git config user.email "arvindkushwah9@gmail.com"
4. Add remote origin:-   
    git remote add origin git@bitbucket.org:arvindkushwah9/jcss.org.sg.git
    git remote add origin2 https://arvindkushwah9@bitbucket.org   
    /arvindkushwah9/jcss.org.sg.git


5.  Generate ssh key cmd:=>  ssh-keygen
6.  Add ssh key on my system:=> ssh-add



 

Wednesday, 9 October 2019

How to install mysql in ubuntu 18.04 and Import mysql database

How to install mysql in ubuntu 18.04

1.  sudo apt-get install mysql-server mysql-client libmysqlclient-dev
2.  sudo service mysql status
3.  mysql -u root -p
4.  sudo mysql -u root -p
5.  uninstall plugin validate_password;
6.  ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
7.  ALTER USER 'root'@'localhost' IDENTIFIED WITH 
      mysql_native_password  BY 'root';
8.  SELECT user,authentication_string,plugin,host FROM mysql.user;
9.   ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
      BY 'password';
10.  ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
       BY 'root';

  Import database:-  (mysql -u username -p database_name < file.sql)

Friday, 27 September 2019

Line Chart

Line Chart 

1.  Add this line to your application's Gemfile:
     # ======= Chart ========
         gem 'chartkick'
         gem 'groupdate'

2.  After run the bundle install 

3.  Sprockets, in app/assets/javascripts/application.js, add:
         //= require chartkick
         //= require Chart.bundle

4.  For View Page :- 
          <%= line_chart User.group_by_day(:created_at).count %>
          <%= line_chart Order.all.group_by_day() { |order| order.created_at    
                }.map{ |date, orders, | [date, orders.size] } 
           %>

  Common Git Commands   Take clone of a repository git clone <remote-repository-url> ex: git clone  https://github.com/agricor/RegTech...