Add Google Custom Search to your Rails Application (Business Edition)

Posted by anup.narkhede on July 17, 2008

Here are the steps to set up a Google CSE for your rails application. In order to use the xml api, first of all you need to have a business account. You can get the xml query format url or more precisely the cx parameter (unique ID of the CSE) from the control panel.

Setup:

Identify your resource to be searched with the help of url patterns. For ex, if the application is RESTful, it is easy to index something like http://someshop.com/products. Configure your CSE for the above url pattern so that http://someshop.com/products/1, http://someshop.com/products/2.. etc get indexed by the search engine.

Code:

The GoogleSearch class sends a GET request to fetch the results xml, which is parsed using the Hpricot parser.

Output:

Now you could get the urls of search results as an array. Likewise, you can fetch other parameters from resultant xml by referring the this doc..

SecuritySandbox Errors and PaperVision3D

Posted by anup.narkhede on November 27, 2007

I have been banging my head since past one week to resolve the Security Sandbox error issue with ActionScript 3.0 and Papervision 3D. This security thingy was needed badly to get my FlickrGallery working.

Error Description:

     SecurityError: Error #2122: Security sandbox violation: LoaderInfo.content:
     file:///C:/Documents and Settings/anup/My Documents/app/Final/bin/Final.swf
     cannot access http://farm3.static.flickr.com/2263/2043746131_8e36900f5d_t.jpg.
     A policy file is required, but the checkPolicyFile flag was not set when this media
     was loaded.
	at flash.display::LoaderInfo/get content()
	at Final/::imageLoaded()

Anyhow the flash application was not getting the LoaderContext’s checkPolicyFile flag and domain’s crossdomain.xml file. I searched for solutions all over the web including pv3d mailing list and then arrived at a solution for this problem.

My ActionScript 3.0 loader code looks like this:

     imageURL = string;
     var loaderContext:LoaderContext = new LoaderContext(true);
     var imageLoader:Loader = new Loader();
     imageLoader.load( new URLRequest(imageURL),loaderContext);
     imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, imageLoaded );

     private function imageLoaded(e:Event):void{
	var loadedBmp:Bitmap = e.target.content as Bitmap;
	var bmp:BitmapData = loadedBmp.bitmapData;
	var material:BitmapMaterial = new BitmapMaterial(bmp);
	material.doubleSided = true;
	images[imgCounter] = new Plane( material, 40, 40, 1, 1);
	rootNode.addChild(images[imgCounter]);
     }

I created a proxy script for my domain http://anup.info to route all flickr images through my domain. Found a cool php script at http://www.abdulqabiz.com/blog/archives/general/php_proxy_script_for.php

Then finally added one crossdomain.xml file at http://anup.info

     < ?xml version="1.0"?>
        < !DOCTYPE cross-domain-policy SYSTEM
          "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
        <cross -domain-policy>
            <allow -access-from domain="*" />
        </cross>>

Bravo! it works! Finally my FlickrGallery is ready to go live on external web sites.