Given an array, find number of subsets with k elements, where absolute difference between the maximum and mininmum element is at most x

Problem Given an Array consisting of N integers, we need to find the number of subsets of this Array of size K, where Absolute difference between the Maximum and Minimum element of the subset is at most X. Explanation Lets say given Array is [4 5 1 3 2] and... »
Author's profile picture Rajat singla

Automated testing of google autocomplete using cucumber and capybara

Ruby script for automated testing of google autocomplete in HTML form using cucumber and capybara. Add the following script for google autocomplete. google_autocomplete.feature Scenario: S1 And I fill google autocomplete google_autocomplete.rb module name def fill_google_autocomplete(id) sleep 1 ele=find(id) if ele ele.set "delhi" sleep 1 ele.native.send_keys(:arrow_down) ele.native.send_keys(:return) end sleep 1 endendWorld(name)Then... »
Author's profile picture Rajat singla

How to manage assets in rails, difference between app, vendor and lib assets, what is asset pipeline?

What is assets pipeline? In rails asset pipeline offers tools and mechanism to manage assets i.e. JavaScript, css, image, video files. Using it you can pre-process(coffeescript,sass), compress, minify and prepare assets for use by browsers. Problems solved by it Asset pipeline solves problem of multiple requests for each asset by... »
Author's profile picture Rajat singla

Difference between vanilla.js, javascript, ecmascript, ember.js, node.js

Vanilla.js Vanilla.js is nothing but a name given to the practice of using plain JavaScript without any additional JavaScript libraries as a mockery to remind framework lovers that many things can be done without the need for additional JavaScript libraries. ECMAScript ECMAScript is a standard followed by JavaScript language. ECMAScript... »
Author's profile picture Rajat singla

Swap elements in dom by drag and drop.

Drag and drop is a very common feature. In which you drag an element and drop it somewhere else. Drag and drop is a standard feature in HTML5, You can make any element draggable. Below are the steps on how to achieve the same. Below is a demo of the... »
Author's profile picture Rajat singla

What are the options with which protect_with_forgery is called?

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: :exceptionend What happens if the token is missing or wrong depends on the option with which protect_from_forgery method is called. In Rails there are three options:... »
Author's profile picture Rajat singla

How to add csrf in ember app.

What if i’m using rails as api, so my frontend is seperated from rails can i still prevent csrf and how? So lets take an example where we use ember for frontend and rails as api. In this case, apart from adding protect_from_forgery in application controller you have to do... »
Author's profile picture Rajat singla

Sessions and csrf in rails.

Most apps need to be able to store some data about a user. Maybe it’s a user id, or a preferred language. session is the perfect place to put this kind of data. Little bits of data you want to keep around for more than one request. Sessions are easy... »
Author's profile picture Rajat singla

Best practices while using ooor gem for making rpc calls to odoo(openerp) from ruby framework

Best practices while Using Ooor gem for making rpc calls to Odoo(openerp) from ruby framework Odoo(openerp) is a management software written in python using xml and qweb engine. Odoo is all the rage for ERP back-offices, but sometimes you want freedom and scalablity for your web front ends which you... »
Author's profile picture Rajat singla

Integrate paytm payment with rails app

Paytm. The fast growing payment network, it’s quite easy to integrate paytm payment in your rails app. Here is simple step by step guide on the same. 1. Register on paytm payment website. For registering on paytm payment as a merchant you need to sign up here, you need TAN... »
Author's profile picture Rajat singla