Skip to content

Instantly share code, notes, and snippets.

@abhianair
abhianair / google-drive-uploader.py
Created October 23, 2019 03:52
Upload a file using oAuth 2.0 google-api in python, credential.json should be saved in the same folder, any update to the scope needed delete the token .pickle from the root folder
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from googleapiclient.http import MediaFileUpload, MediaIoBaseUpload
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/drive']
@abhianair
abhianair / auto_fields.py
Last active October 24, 2019 04:54
Adding checkout fields automatically using python selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
print("Enter wp username")
user = str(input())
print("Enter wp password")
passw = str(input())
print("Enter field numbers")
num = int(input())
driver = webdriver.Chrome('chromedriver')
@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
# 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 / 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"
@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 / app.js
Created March 24, 2020 10:03
Jquery function wrapping
var main = (function($, window, document){
function object(){
// scripts
return{
object : object,
};
@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 / 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 / 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(){},