Copy a text of div by button click by javascript

Your html code  <input type="button" id="copyme" value="COPY THE DIV"> <div id="mypolicy">THIS IS WHAT I WANT TO COPY</div> js script $('#copyme').on('click', function(){     id =     var range = document.createRange();     range.selectNode(document.getElementById(id));     window.getSelection().removeAllRanges();   // clear current selection     window.getSelection().addRange(range);   // to select text     document.execCommand("copy");   });

Revert pushed commit from git

There are 2 way to revert pushed code using git commands 1) First Way, Let suppose your current branch name is staging and you want to revert commit from staging git log   you will see commit details   now git checkout <commit_hash_where_you_want_to_point_your_head>                 in this picture i want to remove 1st commit                 so my command will be git checkout a804a3c4662334b0aa33860548841db54fb508bb         3. Now Head will be on second commit so create new branch from here git checkout -b staging_copy (name will be depends on you)      4. Now staging_copy branch does not have reverted commit, means its code is clean       5. Now delete your staging branch from local machine git branch -D staging    6. now rename your staging_copy branch to staging git branch -M staging    7. now we need to force push to staging branch git push origin staging -f This process is lengthy and complex but we are using this because in this proc

cannot find module angular http

npm install @angular/http@latest

How to Access RabbitMQ Management Plugin rabbitmqadmin Command Line

1) Enable rabbitmq_management   sudo rabbitmq-plugins enable rabbitmq_management 2) Restart rabbitmq-server sudo service rabbitmq-server restart 3) Access GUI http://rabbitmq-server-ip:15672/ username:guest password:guest //you can check ip sudo service rabbitmq-server status command 4) Access  rabbitmqadmin Command Line http://rabbitmq-server-ip:15672/cli a) Download  rabbitmqadmin script wget http://rabbitmq-server-ip:15672/cli/rabbitmqadmin b) Change permission chmod +x rabbitmqadmin 5) rabbitmqadmin Commands a) Help ./rabbitmqadmin --help b)List all exchanges ./rabbitmqadmin -u guest -p cloud -H localhost list exchanges -u : username -p : password c) List all queues   ./rabbitmqadmin -u guest -p cloud -H localhost list queues d) Get help of subcommands ./rabbitmqadmin help subcommands ./rabbitmqadmin help subcommands | grep queue ./rabbitmqadmin help subcommands | grep exchnage ./rabbitmqadmin help subcommands | grep binding

How to Install or Uninstall Redis on Ubuntu 18.04

Step 1 – Open the terminal step 2. Update APT Repository Cache   (1)check the version table on your operating system     The package you are searching for is named redis-server. You can check its package info with apt show redis-server sudo apt-cache policy redis-server or sudo apt show redis-server The dataset is stored entirely in memory and periodically flushed to disk. (2)add PPA repository to your OS: sudo add-apt-repository ppa:chris-lea/redis-server (3)In order to install Redis, you first need to update the APT repository cache of your Ubuntu. You can do that with the following command: Update the apt-get packages index files and also update existing packages to the newest versions by using the following commands: sudo apt-get update  sudo apt-get upgrade step 2. Install Redis on Ubuntu Using the APT Command sudo apt-get install redis-server step 3. Check Redis Version redis-cli --version step 4:check if the Redis is running. Once t

lambda proc and block in rails

this all things basically we used in block level coding and for some custom queries in rails model class Main   [ 1 , 2 , 3 ].each do | num |     puts num   end end def block_method   yield end block_method { puts "Test"} def arg_method   yield   yield 1 end arg_method { |i| puts i*1 rescue nil} # explicit block def explicit_block(&block) #same as yield end explicit_block {puts "This is explicit block"} # lambda lambda_test = -> {puts "This is lambda"} lambda_test.() lambda_test[] # lambda with args arg_lambda = -> (i){ puts i}"test") my_proc = { |x| puts x } # Should work my_lambda = -> { return 1 } puts "Lambda result: #{}" # Should raise exception my_proc = { return 1 } puts "Proc result: #{}" def call_proc   puts "Before proc"   my_proc = Proc.n

unable to install ruby 2.2 in ubuntu 18.04

Try with this commands 1) Install rvm following instructions for Ubuntu on 2) rvm install ruby 2.2.10 3) rvm install ruby 2.2.10 --with-gcc=gcc if its not work then try with this  1. sudo apt purge libssl-dev && sudo apt install libssl1.0-dev 2. rvm install 2.3.5 --autolibs=disable

rails redirect after login devise

devise_scope :user do  authenticated :user do    root 'dashboard#index', as: :authenticated_root  end  unauthenticated do    root 'home#index', as: :unauthenticated_root  end end

Data Scrapping in rails

go to your terminal create a directory mkdir ruby_data_scrapping create directory mkdir lib cd lib/ touch scraper.rb gem install nokogiri  // install gems in local gem install httparty gem install byebug Write code in your scraper.rb require "httparty" require "nokogiri" require "byebug" class Scraper   attr_accessor :parse_page   def initialize       doc = HTTParty.get("")       @parse_page ||= Nokogiri::HTML(doc)   end   def get_prices      item_container.first(2){|x| x.text}   end   private     def item_container        parse_page.css(".tv-data-table__tbody").first.css(".tv-screener-table__result-row").css(".tv-screener-table__cell")     end   prices =   (0...prices.size).each do |index|       puts "Price: #{prices[index]}"   end end now run this scraper ruby scraper.rb

rails scope with argument or dynamic value and join tables

scope :get_by_currency, -> (currency) {find_by(currency_id: currency)} scope :by_role, ->(role) { joins(:roles).where(roles: { name: role }) } //it will work in rails 4 and previous version scope :by_role, ->(role) { joins(:roles).where(' ? ', #{role} ) } //it will work in all versions of rails validate  :validate_mimimum_amount, unless: -> (order) { order.ord_type=='market' || order.ord_type=='manual' }