Skip to content

Instantly share code, notes, and snippets.

View ProProgrammer's full-sized avatar

Deep Sukhwani ProProgrammer

View GitHub Profile
@ProProgrammer
ProProgrammer / JavaScript - Automate Login.js
Last active April 23, 2024 07:38
A Quick JavaScript written to automate login on a page for testing / fun purpose.
/*
The actual javascript code starts from document.forms[0].username.value.... however to run it in the URL bar (address bar) of a browser you have to put the entire Javascript Code in this format javascript:{<YOUR JAVASCRIPT CODE>}
I have tested it in Chrome, Firefox, Internet Explorer and Safari and it works perfectly fine. If you notice any different behaviour with any other browsers, please test and contribute.
Simply replace <YOUR USER NAME> with your actual username and <YOUR PASSWORD> with your actual login password and run this in browser address bar (no need to input actual URL in the JavaScript code)
------------------------------------------------------------------------------------------------------------
CAUTION: PLEASE ENSURE YOU KEEP YOUR PASSWORD SECURE AS YOU ACTUALLY GIVE YOUR PASSWORD IN TEXT FORMAT INSIDE THIS JAVASCRIPT CODE, SO IF ANYONE GETS ACCESS TO THIS CODE THEY WILL GET ACCESS TO YOUR PASSWORD
----------------------------------------------------------------------------------------
@ProProgrammer
ProProgrammer / Generate Random Number.js
Last active August 29, 2015 13:56
Random number - Not probably as good as Mersenne twister - http://en.wikipedia.org/wiki/Mersenne_twister
//Get a random value from a list of words
list1 = ["Hi", "How", "are", "you"];
list1[Math.floor(Math.random() * list1.length)];
@ProProgrammer
ProProgrammer / Rename.js
Last active December 21, 2017 10:34
One line code to replace http in URL with https to ensure you are browsing in secure mode whenever possible
//Replacing http with https by manipulating DOM element as shown below
document.location.href = document.location.href.replace("http","https");
/* ** .replace function will replace the text passed as first argument with the text passed as second argument
** document.location.href returns current URL including the fragments / query parameters in the URL
*/
//OR
document.location.protocol = 'https:'
// Changes URL protocol to https from whatever it is currently.
@ProProgrammer
ProProgrammer / GetYTVidTitle.py
Created May 8, 2014 07:17
Fetch Youtube Video title using Google Data Python client library
"""
## This function returns title of the Youtube Video whose video_id is passed to the function as a parameter
## You must have Google Data Python Client Library installed and path setup for this to work.
## More information on that can be found here:
## https://developers.google.com/gdata/articles/python_client_lib#library
"""
import gdata.youtube
@ProProgrammer
ProProgrammer / TimingListsExecution.py
Last active August 29, 2015 14:10
Execution time of list creation using 4 most common methods of list creation in python
"""
Timing code execution time.
From book: Problem Solving with Algorithms and Data Structures: http://interactivepython.org/runestone/static/pythonds/AlgorithmAnalysis/Lists.html
This code times the execution time of each function.
test1() uses concatenation method to create a list of 1000 numbers from 0 to 999
test2() uses append method to create a list of 1000 numbers from 0 to 999
test3() uses list comprehension to create a list of 1000 numbers from 0 to 999
test4() uses range function inside list function to create a list of 1000 numbers from 0 to 999
For timing the test case execution, we are here using Python's timeit module. More about it: https://docs.python.org/2/library/timeit.html
"""
@ProProgrammer
ProProgrammer / TimingPopOnLists.py
Created November 23, 2014 12:43
Timing Pop Operation on lists
"""
Timing code execution time.
From book: Problem Solving with Algorithms and Data Structures: http://interactivepython.org/runestone/static/pythonds/AlgorithmAnalysis/Lists.html
This code times the execution of pop operation for popping first element in a list and popping last element in a list.
For timing the test case execution, we are here using Python's timeit module. More about it: https://docs.python.org/2/library/timeit.html
"""
import timeit
popzero = timeit.Timer("x.pop(0)", "from __main__ import x")
@ProProgrammer
ProProgrammer / sqlite.py
Created December 23, 2014 04:56
Sample SQLite connection builder using Python
import sqlite3 as lite
import sys
con = None
try:
con = lite.connect(u"C:\\Python27\\test.db")
cur = con.cursor()
@ProProgrammer
ProProgrammer / sqlite_post_images.py
Created December 23, 2014 04:58
Posting images to sqlite database - Incomplete script
import sqlite3 as lite
import os
import sys
# def con_to_file(filename):
# #Ensure correct filename / filepath is given as argument to the function
# con = lite.connect(filename)
# cur = con.cursor()
@ProProgrammer
ProProgrammer / pywinauto.py
Created December 23, 2014 05:32
Work on Automating Windows application using pywinauto
from pywinauto.application import Application
app = Application.start('notepad')
app.Notepad.MenuSelect('Help->AboutNotepad')
app.AboutNotepad.OK.Click() #May have to do it twice to bring notepad application in focus first and then click on OK in the second time.
# app.AboutNotepad.OK.Click()
app.Notepad.MenuSelect('Format->Font')
app.Font.FontComboBox.Select('Arial')
app.Font.FontStyleCombo.Select('Bold Italic')
app.Font.OK.Click()
@ProProgrammer
ProProgrammer / DirectoriesWithPeriodInName.py
Last active August 29, 2015 14:13
A quick dirty script to list all directories in a given folder that have a period (.) in their name
import os
# Change to directory where the folders are located that you want to work with!
os.chdir('path/for/directory')
for item in os.listdir(os.getcwd()):
# os.path.isfile returns true if the specified path is a file
# Hence not os.path.isfile returns true if the specified path is NOT A FILE (i.e. a directory)
if not os.path.isfile(os.path.join(os.getcwd(),item)):
if '.' in item: