Skip to content

Instantly share code, notes, and snippets.

View azakordonets's full-sized avatar

Andrew Zakordonets azakordonets

View GitHub Profile
@azakordonets
azakordonets / encryptPassWordWithCryptoJs.js
Last active August 13, 2024 07:53
This gist describes how to encode password with salt using SHA256 algorithm. It shows how to do it with google crypto-js library and Node.js module crypto
var CryptoJS = require('crypto-js');
var algo = CryptoJS.algo.SHA256.create();
algo.update(password, 'utf-8');
algo.update(CryptoJS.SHA256(salt), 'utf-8');
var hash = algo.finalize().toString(CryptoJS.enc.Base64);
console.log(hash);
@azakordonets
azakordonets / measureExecutionTime.scala
Created January 22, 2015 21:40
This small code allows you to test how much time does it take to execute your code
def time[R](block: => R): R = {
val t0 = System.nanoTime()
val result = block // call-by-name
val t1 = System.nanoTime()
println("Elapsed time: " + (t1 - t0) + "ns")
result
}
// Now wrap your method calls, for example change this...
val result = 1 to 1000 sum
@azakordonets
azakordonets / randomString.py
Last active January 7, 2016 12:37
Generate random string in python
import string
import random
print ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(3000))
print len("A5WMMLXE5DBAQMFGRF8OSEB6K5MW972PORMU4ENBC4VDBEDWB5WEFYG2ECXAJ7YSWXE9P0TUSKCD3LZMPGG9VKKLTS04R0101OS02XTKAG9VI3T69YHK56NXORO8A9GI095422I3RSFY1QJDXZONXBKHEA9HB9JB0DPG56XNYTNDLG64ITAWEKB6PEY46OW391WQCBRPPDS2VDKY748S38P0FZURELCPTDDMWI301I6I0RP7FHT20DWTWHJUH2X0ECJ9VJM108IAAZWM058HXKQJ9W6R4A3QZFM17HVB4ZPB666RANSS0TVQ4B0FYKWAJP5XYV4820H8KRPQ7OHXU85KFUUFG45MFU67JC2RE05I02YFCS720S4IVXGGY6YQE47PKXMXMZJC160WKRU2OJS7KTONBOUXA4M6RCAZYVFJCIUQE5AKCYKCLMAYB1AMC2LUEE5T21OHXKAD54QAS68FU1M3BED8QH6UAO2XYCXO8R62O48RFVK8LSX7KTZYBV15U8LGGPINTF4XTXUWDU9LI39ES404YEZRHD5RLLX8WX8ND7R2RRQ9HBFH8OY4LFIJFD38CEQ95PAEW3TW7AJTMUXS27MP7FN2FXHY7F8FB7UFHTESBU3X6GDNZN6PIJNUXFBQHUM9BCD9FYXI6CY5NPIAQJKC98BHOUFBJOC3SLNCK0LARF0W0019YB8EETF6BT8PKUNIN3B0BHFIOQEARX1IDKVF00WNH0JIO9LEHPKINLZFHOZ2FXV48SM76B84NTDGIM24XMKDA2A4RQ7J4UCLBZTQJWCWTXBY6MQMX8BXIBJV5ZHB3EYM0CXFECN6H7XLE899FW2ADGMRDYRFH19TX9LXQ4MNQLS2ZC194N5M
private def isValidBSN(candidate: Int): Boolean = {
var bsn = candidate
if (bsn <= 9999999 || bsn > 999999999) {
return false;
}
var sum: Int = -1 * bsn % 10;
for (multiplier <- 2 to 1000 ; if bsn > 0) {
bsn = bsn / 10
var value = bsn % 10
@azakordonets
azakordonets / getJiraFieldsList.py
Created September 22, 2014 10:05
This scrip allows you easily to get full list of all your JIRA instance fields
import urllib
import urllib2
import cookielib
import json
jira_serverurl = "{url to your jira environment}"
creds = { "username" : "admin", "password" : "test" }
authurl = jira_serverurl + "/rest/auth/latest/session"
# Get the authentication cookie using the REST API
public void dragAndDrop2(WebElement element, int xOffset, int yOffset) throws Exception {
Actions builder = new Actions(driver;
Action dragAndDrop = builder.dragAndDropBy(element, xOffset, yOffset) .build();
dragAndDrop.perform();
}
/**
* A convenience method that performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.
* @param slider webElement
* @param xOffset - horizontal move offset. Positive value means moving to the right, negative - to the left
* @param yOffset - vertical move offset. Positive value means moving up, negative - down
* @throws Exception
*/
public void dragAndDrop(WebElement slider, int xOffset, int yOffset) throws Exception {
Actions moveSlider = new Actions(driver);
Action action = moveSlider.clickAndHold(slider)
public void selectFromDropDownWithHover(String menuTitle, String menuItem, String locatorType) throws Exception {
Actions actions = new Actions(manager.getDriver());
//first we find the menu title on which we will hover mouse cursor
WebElement menuHoverLink = findElementByLocator(locatorType, menuTitle);
//now we hover it with mouse
actions.moveToElement(menuHoverLink).perform();
//let's find our menu item
WebElement menuItemElement = findElementByLocator(locatorType, menuItem);
actions.moveToElement(menuItemElement);
actions.click().build().perform();
public int randomIntGenerator(int minimum, int maximum) {
Random rn = new Random();
return rn.nextInt(maximum - minimum) + minimum;
}
@azakordonets
azakordonets / WaitForPageToLoad.java
Created June 2, 2014 10:17
This method allows you to properly wait for page in load with WebDriver
public void waitForPageToLoad() {
Wait<WebDriver> wait = new WebDriverWait(manager.getDriver(), 30);
wait.until(new Function<WebDriver, Boolean>() {
public Boolean apply(WebDriver driver) {
System.out.println("Current Window State : "
+ String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState")));
return String
.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState"))
.equals("complete");
}