Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / export_controller.rb
Last active July 29, 2019 09:27
Rails export to csv multiple table in a same file
def backup
models = ["table1s","table2s","table3s"]
all_data = Hash.new
models.map do |model_name|
table_data = []
model_name = model_name.split("")
model_name.pop
model_name = model_name.join("")
model_name.camelize.constantize.all.map do |data|
table_data.push(data)
Data.with_schema('schema_name').all
@abhianair
abhianair / datapicker.js
Created April 29, 2019 04:50
Disable an array of dates from Datepicker
var array = ["2019-06-01","2019-06-02","2019-06-03"];
$('#inline-datepicker').datepicker({
// minDate: 0,
beforeShowDay: function(date) {
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ array.indexOf(string) == -1 ]
}
});
@abhianair
abhianair / custom_calendar.js
Created April 5, 2019 12:05
Dynamic custom calendar where day cell is text area Using Jquery.
$( document ).on('turbolinks:load', function() {
var deferentMonth = 0;
var prevEl = document.getElementById('ac-prev'), // get the ID of the prev month button
nextEl = document.getElementById('ac-next'), // get the date of the next month button
daysEl = document.getElementById("custom_calndar2");
const months = [
"JANUARY",
"FEBRUARY",
"MARCH",
"APRIL",
@abhianair
abhianair / controller.rb
Created December 24, 2018 05:04
Switch all tenants created using apartment automatically and get data accordingly.
@tenant = Apartment.tenant_names
@tenant.each do |name|
Apartment::Tenant.switch(name) do
@email = Account.pluck(:email)
end
end
<div><%= t = Time.parse(appointment.time) %>
<%= date = appointment.date %>
<%= d = Date.new(date.year,date.month,date.day) %>
<%= time = DateTime.new(d.year, d.month, d.day, t.hour, t.min, t.sec) %></div>
@abhianair
abhianair / model.rb
Created December 6, 2018 06:12
Does not need that todo_list exist
class Task < ApplicationRecord
belongs_to :todo_list, optional: true
end
@abhianair
abhianair / controller.rb
Created December 4, 2018 04:33
To check if a user already have tuple
before_action :check_have, only: [:new]
def check_have
if Profile.where(:user_id=>current_user.id).present?
redirect_to root_path
end
end