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.