Skip to content

Instantly share code, notes, and snippets.

@abhianair
abhianair / subscription_paypal.rb
Last active August 18, 2023 11:36
Paypal creating subscription using paypal api with ruby on rails
require 'net/http'
require 'uri'
def create
@subscription = current_user.subscriptions.build(subscription_params)
if @subscription.save
create_subscription_with_api(@subscription)
else
redirect_to request.referrer, notice: 'Some error caused in the payment gateway.'
@abhianair
abhianair / subscription_paypal.rb
Created May 14, 2020 04:25
Paypal creating subscription using paypal api with ruby on rails
require 'net/http'
require 'uri'
def create
@subscription = current_user.subscriptions.build(subscription_params)
if @subscription.save
create_subscription_with_api(@subscription)
else
redirect_to request.referrer, notice: 'Some error caused in the payment gateway.'
@abhianair
abhianair / textarea.js
Created May 6, 2020 09:45
Auto Height of text area
$( document ).on('turbolinks:load', function() {
(function($){
$.fn.autoResize = function(options) {
// Just some abstracted details,
// to make plugin users happy:
var settings = $.extend({
onResize : function(){},
@abhianair
abhianair / controller.rb
Created May 5, 2020 11:43
create and capture the order in paypal
# this wont support recurring subscription
def create
@subscription = current_user.subscriptions.build(subscription_params)
if @subscription.save
create_subscription(@subscription, debug=true) #paypal checkout sdk
else
end
end
@abhianair
abhianair / app.js
Created April 21, 2020 10:09
jquery url dynamic change
url = window.location.href;
paramName = 'myparam';
paramValue = $(this).val();
var pattern = new RegExp('('+paramName+'=).*?(&|$)')
var newUrl = url.replace(pattern,'$1' + paramValue + '$2');
var n=url.indexOf(paramName);
alert(n)
if(n == -1){
newUrl = newUrl + (newUrl.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue
}
@abhianair
abhianair / app.js
Created March 24, 2020 10:03
Jquery function wrapping
var main = (function($, window, document){
function object(){
// scripts
return{
object : object,
};
@abhianair
abhianair / main.rb
Created February 11, 2020 06:07
Gross and Effective time from an array of time DateTime objects
def task_overalltime(timelines)
array = timelines.split(',').map{ |x| x.to_datetime}
nd_time = array.length.even? ? '' : '+'
array = array.reverse
rec_difference = 0
array.each_with_index do |val, ind|
if ind.odd?
next_ind = ind - 1
rec_difference = rec_difference + (val.to_time - array[next_ind].to_time).to_i.abs if array[next_ind].present?
end
@abhianair
abhianair / application_controller.rb
Created January 27, 2020 06:01
Avoiding caching the login page
class ApplicationController < ActionController::Base
before_filter :set_cache_headers
private
def set_cache_headers
response.headers["Cache-Control"] = "no-cache, no-store"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
# show orgins for a repository
git remote -v
#delete a remote of a repository
git remote rm origin #where origin is the remote
#pushing to master with branches
@abhianair
abhianair / setup.txt
Created October 24, 2019 04:48
Selenium-Python-Chromedriver-Windows webpage automation initial setup
#chrome driver installation
link: https://chromedriver.chromium.org/
#download the chromedriver respective to the version of your chrome webbrowser
#unzip the downloaded file and move "chromedriver.exe" to a folder or a working directory
#run the "chromedriver.exe" before the automated script runs.
#selenium module installation using pip
pip install selenium