Friday, November 19, 2010

Grab the URL from Site or Page

If you want to crawel links from all the site or pages, Below is the function:

$arrGetAllLinks = array();

// if you want all links from site, set $isRecuressive = 1
// if you want all links from page, set $isRecuressive = 0

function fnGrabTHeURLFromLink($strLink,$isRecuressive = 0)
{
$parse = parse_url($strLink);
$strMainHost = $parse['host'];

global $arrGetAllLinks;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$strLink);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);

if( $result )
{
preg_match_all( '/href="(http:\/\/www.[^0-9].+?)"/', $result, $output, PREG_SET_ORDER );

foreach( $output as $item )
{
$parse = parse_url($item[1]);
$strHostOfURL = $parse['host'];

// ALL LINKS DISPLAY HERE
//print "
";
//print_r($item);

if(($strMainHost == $strHostOfURL) && !in_array($item[1], $arrGetAllLinks))
{
$arrGetAllLinks[] = $item[1];
if($isRecuressive == 1)
{
$arrTempGetAllLinks = fnGrabTHeURLFromLink($item[1]);
$arrGetAllLinks = array_merge((array)$arrGetAllLinks, (array)$arrTempGetAllLinks);
$arrGetAllLinks = array_unique($arrGetAllLinks);
}
}
}

}

return array_unique($arrGetAllLinks);
}

print_r(fnGrabTHeURLFromLink("MENTION SITE HERE"));

Thursday, November 4, 2010

Fragment Id Messaging Concept

we use a hack called fragment id messaging. This should be cross-browser, provided the page containing your iframe is the top level.

In other words, there are a total of two levels.
Basically, the child sets the fragment of the parent, and the parent watches for this.

Generally fragment id messaging use for cross-domain communication.
Technically, this hack uses window.location.hash (the part of the URL following #) to communicate.

Historically, any window could change the location of any other window. This turned out to be a problem because, among other things, it meant embedding a login iframe in a window was unsafe (because then a malicious site could replace the login iframe with a spoofed version). Over time further restrictions have been applied to location changes to browser windows, until now, when HTML5 and most browsers have reached common agreement on the ancestor policy. In a nutshell, paraphrasing the HTML5 specification, a window A can change the location of another window B if:

* the locations of A and B have the same origin, which is to say they have the same scheme, host, and port (http, stackoverflow.com, 80 for example), or
* B is a top-level window, and A is a window in a frame nested at some depth within B (direct child, child of a child, etc.), or
* B is a window opened using window.open and A can change the location of the window that opened B (so B is a popup opened by A, by a popup window opened by A, or at greater depth), or
* B isn't a top-level window, but its parent window, or its parent's parent window, or at some similar amount of parentage the locations of that window and A are same-origin

(Same origin is more complicated than this, but the embedded description above catches its essence and covers the most common cases.)

Under this policy, C may change the location of A, and A may change the location of B or C, but C may not change the location of B. If you need to work around this, then you should change your page A's location to something that changes B as appropriate; alternately, you could ask your page B to change its own location.

Configuring SSL (Godaddy) for Apache 2.X

While configuring SSL you will need to provide Certificate Signing Request (CSR).

Steps to generate CSR can be found on below url:
http://help.godaddy.com/topic/746/article/5269

Steps are also described below:

Creating a CSR (required while registering ssl certificate)

Create a directory /usr/bin/ssl/ where your csr files will be stored.

Type below command from the shell:

1 . cd /usr/bin/ (/your path to openssl/)
which will change your directory to the one which is going to store the CSR files.
Then type below command on shell
2. openssl genrsa -des3 -out .key 2048
Replace with the name which you want.
3. openssl req -new -key .key -out .csr
Replace with the name which you want.
The above two commands will create a .key and .csr file at the location which you have specified above.

Note – while creation of a CSR you will be asked the details about organization.
Once the certificate is registered you will get two files with .crt extension. Place these two files in the same directory as the one which you have created while CSR.



Now for apache server configuration:
Go to /etc/httpd/conf.d folder where you will find a ssl.conf file.

In ssl.conf file you will find below lines
SSLCertificateFile – replace the path of your SSL certificate file (from above e.g. /usr/bin/ssl/yourcertificate.crt)

SSLCertificateKeyFile - replace the path of your SSL key file (from above e.g. /usr/bin/ssl/key.crt)

SSLCertificateChainFile – replace with the path of 2nd .crt file which you got after registering the certificate. (its generally named as gd_bundle.crt) (from above e.g. /usr/bin/ssl/gd_bundle.crt)

Tuesday, July 6, 2010

How to Get the Base Url with Javascript for a Domain or Localhost

In the code below, you will be able to find the baseUrl of your website using javascript. The following javascript code will work when used on your localhost or when it's used in a live site (finds the root url of the domain address).


function fnGetBaseURL() {
var strUrl = location.href;
// entire url including querystring - also: window.location.href;
var strBaseURL = strUrl.substring(0, strUrl.indexOf('/', 14));


if (strBaseURL.indexOf('http://localhost') != -1) {
// Base Url for localhost
var strUrl = location.href; // window.location.href;
var strPathName = location.pathname; // window.location.pathname;
var intIndex1 = strUrl.indexOf(strPathName);
var intIndex2 = strUrl.indexOf("/",intIndex1 + 1);
var strBaseLocalUrl = strUrl.substr(0, intIndex2);

return strBaseLocalUrl + "/";
}
else {
// Root Url for domain name
return strBaseURL + "/";
}

}

If you'd like to test the fnGetBaseURL function in an html page and view the result, simply add the following after the closing tag of the fnGetBaseURL () function:
document.write(fnGetBaseURL());

Saturday, February 13, 2010

linkedin API.... Exploring Frustration Discovering Satisfaction

Hi All,

last month Me and My team from CueLogic implemented LinkedIn connect with Oauth for Justmeans.... Its really frustrated.......... at last we Succeed....

True Said:

linkedin API.... Exploring Frustration Discovering Satisfaction


Stay tuned... API's coming soon.............................

Wednesday, September 9, 2009

Web Scalability and Performance

Web Scalability and Performance – Real Life Lessons

Last Saturday, we had TechWeekend #3 in Pune, on the theme of Website Scalability and Performance. Mukul Kumar, co-founder, and VP of Engineering at Pubmatic, talked about the hard lessons inscalability they learnt on their way to building a web service that serves billions of ad impressions per month.

Here are the slides used by Mukul. If you cannot see the slides, click here.
Web Scalability & Performance

The talk was live-tweeted by @punetechlive and @d7ylive. Here are a few highlights from the talk:

  • Keep it simple: If you cannot explain your application to your sales staff, you probably won’t be able to scale it!
  • Use JMeter to monitor performance, to a good job of scaling your site
  • Performance testing idea: Take 15/20 Amazon EC2 servers, run JMeter with 200threads on each for 10 hours. Bang on your website! (a few days later, @d7y pointed out that using openSTA instead of JMeter can give you upto 500 threads per server even on old machines.)
  • Scaling your application: have a loosely coupled, shared nothing, stateless, distributed architecture
  • Mysql scalability tip: Be careful before using new features, or new versions. Or don’t use them at all!
  • Website scalability: think global. Some servers in California, some servers in London, etc. Similarly, think global when designing your app. Having servers across the world will drive architecture decisions. When half your data-center is 3000 miles from the other half, interesting, non-trivial problems start cropping up. Also, think carefully about horizontal scaling (lots of cheap servers) vs vertical scaling (few big fat servers)
  • memcache tip: pre-populate memcache with most common objects
  • Scalability tip: Get a hardware load balancer (if you can afford one). Amazon AWS has some load-balancers, but they don’t perform so well
  • Remember the YouTube algo for scaling:
    while(1){
    identify_and_fix_bottlenecks();
    eat_drink();
    sleep();
    notice_new_bottleneck();
    }

    there’s no alternative to this.
  • Scalability tip: You can’t be sure of your performance unless you test with real load, real env, real hardware, real software!
  • Scalability tip – keep the various replicated copies of data loosely consistent. Speeds up your updates. But, figure out which parts of your database must be consistent at all times, and which ones can have “eventual consisteny”
  • Hard lessons: keep spare servers at all times. Keep servers independent – on failure shouldn’t affect other servers
  • Hard lessons: Keep all commands in a script. You will have to run them at 2am. Then 3am. Then 7am.
  • Hard lessons: Have a well defined process for fault identification, communication and resolution (because figuring these things out at 2am, with a site that is down, is terrible.)
  • Hard lessons: Monitor your web service from 12 cities around the world!
  • Hard lesson, Be Paranoid – At any time: servers can go down, DDOS can happen, NICs can become slow or fail!

Friday, June 5, 2009