Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View azakordonets's full-sized avatar

Andrew Zakordonets azakordonets

View GitHub Profile
@azakordonets
azakordonets / ghostImageAlignment.html
Created April 15, 2014 20:57
Some code for image alignment in ghost blog editor
<!--To center an image-->
<p align="center">
![alt]()
</p>
<!--To right align an image-->
<p align="right">
![alt]()
</p>
@azakordonets
azakordonets / DbConnection.java
Created April 18, 2014 12:08
Class for DbConnection handiling
package Base.db_connection;
import org.json.JSONObject;
import java.sql.*;
import static Base.TestPropertiesLoader.getDbConnectionDetails;
public class DbConnection {
public Connection con = null;
@azakordonets
azakordonets / ResultSetConvertor.java
Last active November 25, 2018 19:19
This class is designed to convert ResultSet data taken as a result of Db query into JSON. Also additional coverter methods are available
import org.json.JSONArray;
import org.json.JSONObject;
import java.sql.ResultSet;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
/**
* Utility for converting ResultSets into some Output formats
@azakordonets
azakordonets / ProxySelector.java
Created April 18, 2014 12:18
This class allows you to get a hacky but working way of connecting with Java to SOCKS proxy, when standart ways are not working. Java has a problem with DNS resolving and therefore i had an issue with one of my project. When i was enabling proxy setting through System.Properties , i still was hitting production server, not the test server behind…
import java.net.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.IOException;
/**
* this class is needed for Java to connect to SOCKS proxy server
* Unfortunately Java cannot resolve remote DNS and therefore, when we set System.properties
* with our proxy server details, we hit incorrect server . This is because
* Java is connecting to Proxy, but DNS is resolving with system details and therefore goes to server directly.
@azakordonets
azakordonets / yaml_to_json_convertor.py
Created April 30, 2014 09:50
Converty yaml to json on Python
import yaml
import json
yml = "file_path"
data = yaml.load(open(yml,'r'))
json = json.dumps(data)
print(json)
@azakordonets
azakordonets / getJSONFromFile.java
Created May 6, 2014 14:33
This method allows you to read from file (where already stored data in json format) and save it into JSON object.
public static JSONObject getJSONFromFile(String path) throws JSONException, IOException, ParseException {
JSONParser parser = new JSONParser();
Object obj = parser.parse(new FileReader(path));
return new JSONObject(obj.toString());
}
@azakordonets
azakordonets / webDriverSnippets.java
Last active August 29, 2015 14:01
Set of handy commands and method to work with WebDriver
public void refreshPage(){
driver.navigate().refresh();
}
@azakordonets
azakordonets / getDate.java
Last active August 29, 2015 14:01
get date as a string basing on date format and number of days since now
/**
* This method allows to generate time stamp with predefined format, but not only from today, but from date that we
* pass as a parameter to the method.
* If days = 0 , then we return current date stamp
* If number is > 0, then we return date in the future
* If number is < 0 then we return date from the past
* @param days number of days since stated date
* @param format it's a format in which date string will be returned
* @return date as a String
*/
@azakordonets
azakordonets / getLastDayOfTheMonth.java
Created May 19, 2014 15:33
Getting last day of the month
/**
* This method will return as a date string of the last day of the month.
* @param month if 0 then we look for current month
* @param format format in which date should be returned as a string
* @return
*/
public static String getEndOfTheMonth(int month, String format){
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
Date today = new Date();
Calendar calendar = Calendar.getInstance();
@azakordonets
azakordonets / getAbsolutePath.java
Created May 21, 2014 14:24
returns absolute path to the file
public static String getResourcePath(String relativePath) {
return new Utils().getClass().getResource("/").getPath() + relativePath;
}