Monday, October 22, 2012

ExtJS Tweak : Selecting first and last row of a grid

Very often we need to select a row by default in the grid, since some other pieces of code are linked to selection of the rows in grid , for example like charts rendering data in the grid and something like that.

The problem is the the first row in grid is not selected by default in ExtJS and we have to break our heads.
The event - 'viewready' is the answer. In the documentation , it is explicitly written to use this event to select a row in grid by default.

this small snippet of code will do the job(select the first row),
suppose you have defined your grid as 'grid', then:

 grid.on('viewready',function(){  
           this.getSelectionModel().select(0);  
      });  
Now we would also want some times to select the last row in case we have added a record. The following snippet will do the job beautifully.

 xmlgrid.getSelectionModel().select(store.getCount()-1);  
We have xmlgrid as the grid and "store" is name of data store attached to the grid.

Thursday, October 4, 2012

Verifying your domain in Google apps without hosting your domain

I recently registered a domain but did not host it. Then i registered myself with Google Apps for business and  found that i need to verify my domain for security purpose. Now, the question is how to upload the HTML file on my domain, which is the default method of Google verification process and which necessitates hosting. But there is also provision for verifying your domain without hosting, You need to look for "Alternative methods" pane.

Once into it, you will be provided with the list of domain Registrars (The people who provided you domain with). If your Registrar does not appears in the list choose "Others". If your Registrar appears, they will provide step by step method in their Instructions Pane.

Now for people whose registrars are not listed (which might hopefully get listed later), upon choosing OTHERS you will be given a CONFIRMATION CODE by google. Now login to your registrar website. In the web site look for "DNS server Management". In the various options you will get TXT Records, in this paste your value and save changes. Now you have to wait for few minutes before google can search your DNS.(8-10 mins). After this Verify on google and you are good to go!!

Sunday, August 26, 2012

Bombay Stock Exchange Data Extractor

Awhile ago, i needed an automated application to provide me with latest quotes of my scrips from Bombay Stock Exchange. I looked it over net,but did not find any. Then i decided to make my own application, using API that BSE uses to update it's own website. I thought they would be distributing it as a good software practice. But they are not doing so, so i had to reverse engineer the website code and found that they were indeed using an API.

It is not much pain to use this API, very simple GET method can be used to access this API.
The following link provides the # separated data that we need:
http://www.bseindia.com/bseplus/stockreach/AdvStockReach.aspx?scripcode=<scrip-code>&section=tab1&IsPF=sPF&random=1

where <scrip-code> is the scrip code of the company you want to access - like 532977( BAJAJ AUTO LTD).

I wrote a PHP script for extracting valuable data, you can find the code here:
https://sourceforge.net/projects/bsedataextract/files/getquotes.php/download

The script will print company name and it's face value
Other details can be extracated from the same URL in the same fashion as these values are extracted.
Go thru the script it is self explanatory.

Creating a Single Opt-In Mailchimp form

Creating a single opt-in form for your Mail chimp Account is easy and fast. No, no plugins required, no payment. Just a simple understanding of APIs and PHP scripting is enough for creating a single opt-in Mailchimp form for your web page.

So lets get started!!

To clear out the confusion between Double opt-in and Single Opt-in read the following:
1. Double Opt-In : In this type of form, the user will get a confirmation link on his email, which upon his/her clicking adds them to your list. Otherwise Not!

This type of form is necessary for anti spam measures(So that you dont bombard your users with unwanted emails/newsletters).

2. Single Opt-in : In this type of form, the user will automatically get added to your mailing list in Mail Chimp.
Such forms are necessary for internal purposes wherein your users have no intentions of blocking you from your newsletters.

Mail Chimp provides form embedded code for your website which is by default Double Opt-in.
We cannot do anything to that embedded code. So stop banging your head, if you are doing that.

Mail chimp provides API wrappers for all scripting languages, where in you can turn off / disable the double-opt-in option.

But in case you are planning to abuse the stuff!!!!!! Visit this link :
http://mailchimp.com/contact/abuse/

So make good use of this information and go ahead.

Before beginning you need to have following:
1. An authentic API key provided to you for your account
2. The list ID of your list that you want the users emails to get subscribed to

You will get both from the Mailchimp Website.

Now to begin with you first need to get the API wrapper from
http://apidocs.mailchimp.com/api/downloads/

Download the .zip file of the latest API wrapper for PHP provided and extract the contents to a suitable place.

Now in the examples folder get the following files:

1. /inc/config.inc.php
2. /inc/MCAPI.class.php
3. mcapi_listSubscribe.php

Copy these files to another destination.(Most suitably in the folder where you have your HTML form code residing).

Follow these steps and VOILA!!!!! you will be done:

1. Open 'config.inc.php'
Change the $apikey with the your API Key.
Change $listID with the ID of list you want the user to subscribe to.
Delete the line having variable $myemail.

Save the file and exit.

2.  open the file 'mcapi_listSubscribe.php'
Change the require_once addresses by removing '/inc/'. for both the imported files.
Remove $merge_vars variable initialization.
Here you need to get the emailID of user by either $_GET or $_POST method from your form into a variable like 
$subscriberemailID = $_POST["EMAIL"];
In the function (listSubscribe()) calling line replace $myemail(we deleted it!Remember?) by the variable holding the user Email ID($subscriberemailID).
Equalize $merge_vars = null

You can change the echo function if you want.(For coders only!).

Save the file and exit.

3. Open 'MCAPI.class.php' (The crux of magic)
Find function definition of 'listSubscribe'.
In the parameters passed into it you will see a parameter $double_optin being passed as TRUE. Change it to FALSE. (That is all to this head banging stuff!!!!).

Save the file and exit.

So i guess, you have the form ready and raring to go ahead.
Now in your form code put action of your form as action = "mcapi_listSubscribe.php"
or the location of above mentioned file.

Run the form, fill it up, submit the form and the user email ID will be added directly to your Mail Chimp list
without any confirmation email being sent to the user.