Thursday, April 14, 2016

How to Make a CURL Request Identicle to a Browser Request

It is possible to get the identical CURL request directly from the browser. Most of the modern browsers have it's own developer tool set. I will use Firebug for this.

1. Right click the browser and Click 'Inspect Element with Firebug'


2.  Click on Network tab

3. Enter url of the request and press Enter.

4. Write click on the required request and click 'Copy as cURL'


5. Identical CURL request command will be copied.

Friday, July 3, 2015

Php Script to Download Your Facebook Albums

In facebook there is no option to download all the albums that you have created. Following steps will describe how you can use a php script to download all the albums to your local machine.

I have used facebook access token to authenticate and facebook graph API to retrieve album details.

1. You can get the script from following git-hub repository.
https://github.com/yasithacp/fb-albums-download-script

2. Then you need to get your facebook access token.
  • Go to the facebook graph explorer.
  • Log in using your facebook credentials.
  • Click on the Get Token drop down and then Get Access Token.
  • Select check-box and click on Get Access Token.
  • Note down your access token.

3. Open up the script file and modify the following configuration section.
  • ACCESS_KEY: Access key retrieved in step 2.
  • FOLDER_PATH: Local folder path that albums should download.
4. Obviously you should have php on your machine.

5. Execute the following command to run the script and download will start.
6. If you have large number of albums, script will take time to download all the albums. If your access token get expired repeat the step 1 and replace the script with your new access token and re-run the script. Download will resume.

Sunday, June 21, 2015

Ruby script to use Azure Blob Storage

Azure Blob storage is a service for storing large amounts of unstructured data, such as text or binary data, that can be accessed from anywhere in the world via HTTP or HTTPS. You can use Blob storage to expose data publicly to the world, or to store application data privately.

This post will show you how to perform common scenarios using the Azure Blob service. The samples are written using the Ruby API. The scenarios covered include uploading, listing, downloading, and deleting blobs.

You can download final ruby script from here.

This post assumes you have already created a storage account and a container.

  • Type "gem install azure" in the command window to install the gem and dependencies.
  • Import installed package in to the script file.
  • Setup global parameters.
  • Uploading a Blob into a Container
  • List the Blobs in a Container
  • Download Blobs
  • Delete a Blob

Writing Dynamic SQL in MyBatis

This post will take you through a several examples of creating a dynamic sql queries which you will come up in a day to day development using mybatis.
  • Use of if statement
We can use the if statement where we need to conditionally include parts of a where clause.
eg: Search Employee. Employee name and role can be added as filter fields.
  • Use of choose, when, otherwise
What about switch statement in query where we need to choose only one case among many options.
  • Use of where
When you have a query with multiple optional where clauses you may find a difficulty to build the query with correct prefix. MyBatis has a simple solution for this. It is where element. The where element knows to only insert "WHERE" if there is any content returned by the containing tags. Furthermore, if that content begins with "AND" or "OR", it knows to strip it off.
  • Use of set
The set element can be used to dynamically include columns to update, and leave out others.
  • Use of foreach
Another common necessity for dynamic SQL is the need to iterate over a collection, often to build an IN condition.

Monday, August 26, 2013

Import Data from a CSV file to a Cassandra Keysapce - Java

In this post I am giving a Java solution for importing data from a CSV file to a Cassandra Keyspace.

In the example given below I have used "opencsv" which is a very simple csv parser library for Java to read the data from the csv file. Opencsv is available under a commercial-friendly Apache 2.0 license.

Sunday, October 28, 2012

Test Protected and Private functions in php

Testing private and protected functions in php is normally done through testing the public function it calls. But sometimes you need to test the private or protected functions separately. How can we do this? Lets consider the following simple example.

When you try to run the test class you will get the following error. PHP Fatal error:  Call to private/protected method MyClass::myProtectedMethod() from context 'MyTestClass' After version 5.3.2 PHP's "Reflection Class" makes it possible to temporarily work around access modifiers. This is done using the setAccessible function. Then you need to change your test class as follows.
You will be able to run the test case for your private/protected function now.

Friday, June 1, 2012

Automated Testing - GSoC 2012


For Google Summer of Code (GSoC) 2012 I submitted a proposal on "AutomatedTesting" project listed by phpmyadmin (PMA). Michal Čihař, Marc Delisle, Madhura Jayaratne and Stas Zarubin who is the last year GSoC contributor helped me a lot when I improve my patches and the proposal. Michal Čihař act as my mentor for my project in this summer of code.

PMA is a free software tool written in PHP, intended to handle the administration of MySQL over the web. Automated testing is a project idea which continues from the last year GSoC session which was partially done by Stas Zarubin. Expectation of the project is automate the testing in PMA by writing uni test cases and selenium test cases using phpunit and improve the code coverage. Last year Stas Zarubin has written some test cases for the PMA libraries and classes but couldn't complete all. In this time I am improving the written test cases coverage and write new test cases for the remaining libraries and classes. 

In the next series of blog post I will discuss more about my project in this summer.