Installing Postgresql 9.5 on Debian 8 (Jessie)

Create the following file

/etc/apt/sources.list.d/pgdg.list

add the following line to it

deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
  sudo apt-key add -
sudo apt-get update

and then to install it simply run the following

apt-get install postgresql-9.5

Using selenium and phantomjs with Maven

Here are the dependencies you will need to use Selenium and PhantomJS with Maven.

		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>2.53.0</version>
		</dependency>
		<dependency>
			<groupId>io.github.bonigarcia</groupId>
			<artifactId>webdrivermanager</artifactId>
			<version>1.4.2</version>
		</dependency>

and in your code call the following

PhantomJsDriverManager.getInstance().setup();

WebDriverManager downloads the latest version of the required PhantomJS binary to be used with Selenium WebDriver.

Turn off log messages for Selenium PhantomJS

When using PhantomJS visa GhostDriver with Selenium, you will get all kinds of log messages which would not be necessary in some instances. The example below shows how to disable these log messages.

            DesiredCapabilities caps = new DesiredCapabilities();
            caps.setJavascriptEnabled(true);
            caps.setCapability("takesScreenshot", true);
            caps.setCapability("screen-resolution", "1280x1024");
            caps.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
            caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\Users\\USER\\Downloads\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe");

            ArrayList<String> cliArgsCap = new ArrayList<String>();
            cliArgsCap.add("--webdriver-loglevel=NONE");
            caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
            Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.OFF);

            driver = new PhantomJSDriver(caps);

Using proxy with Selenium PhantomJS

The example below shows how you can configure PhantomJS to use proxies with your web testing.

ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--proxy=127.0.0.1:1024");
// cliArgsCap.add("--proxy-auth=username:password");
cliArgsCap.add("--proxy-type=socks5");

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", true);
caps.setCapability("screen-resolution", "1280x1024");
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\Users\\USER\\Downloads\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe");

caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);

Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.OFF);

driver = new PhantomJSDriver(caps);

Checking response time with HTTPWebRequest

If you want to time the response time of your webrequests/proxies, etc using C# there is a easy way to do it. We need to use a stopwatch object as shown in the example.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);
System.Diagnostics.Stopwatch timer = new Stopwatch();

timer.Start();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close ();

timer.Stop();

TimeSpan timeTaken = timer.Elapsed;

Java programs that contain file paths, making them compatible on Windows and Linux

If your Java application makes use of files using paths, it’s best not to use slash “/” or backslash “\” hard coded in your source code. Use the following to ensure your program would work as expected on both Windows and Unix like systems.

File.separator

Increasing java heap space with command line argument

If you find that your Java application is running our of heap space and you don’t have a memory leak, you can give the JMV more memory. This is very simple to do by starting your java application with the following argument.

java -Xmx6g myprogram

You have three options for increasing size

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size

java -Xms16m -Xmx64m ClassName