IE not saving cookies with facebook apps

Here is a nice gotcha that i hope will save someone some time. If you are creating a Facebook app, then you are probably using iframes, and probably using cookies, and probably care that it works in Internet Explorer. If all those are true the Gotcha is that IE will not allow iframes to save cookies unless there is a p3p header set. It won’t tell you that it is being asked to save cookies it doesn’t like, and it won’t tell you that it decided to not save cookies. In order for IE to behave like the other browsers you have to set the header.
Mine is:

p3p:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"

No idea what it means. but after setting it, the cookies got saved. Hope this helps out someone else

Fly through data

I always wanted to fly through my data. Mainly for fun more than for some amazing analytic tool. So i used unity, to make this possible. All this does is take a location of a csv file (you can use the file:// syntax to reference local data) and loads all the csv data into the grid. (make sure you have 3d data for it). Made a mac version of it to Download, You can see the video for it here:

Diff Directories in TextMate

Came across the need to determine what was different in two different directories. So the terminal command is simple.

diff -rq dir1 dir2

Simple enough. But I noticed the textmate doesn’t have this in its diff bundle. So opened Bundles->Bundle Editor->Show Bundle Editor. Select the diff section. Create a new command (I called it “Selected Directories in Project Drawer”. Input is “none”, Output is “create new document”, and here is the script to put it in there.

eval arr=("$TM_SELECTED_FILES")
if [[ ${#arr[@]} != 2 ]]; then
   exit_show_tool_tip $'You need to select exactly two\nfiles in the project drawer.'
fi

if eval diff -rq "$TM_SELECTED_FILES"; then
  exit_show_tool_tip "There are no differences."
fi

Test your JavaScript in production

Most developers usually have elaborate mechanisms for JavaScript changes to get toproduction. Maybe it goes through development, staging and testing environments. This process can get slow and bogged down with problems outside of your individual control.

So what if you needed to do a quick fix that you just want to confirm works on the production environment?

Simple. Have apache run locally, and proxy pass everything to the production environment accept the JavaScript files you have locally. Here is an example apache conf file:


<VirtualHost 0.0.0.0:80>
   ServerName localjs

    
   Alias /js/ /var/opt/mytestingjsfolder/
   <Directory "/var/opt/mytestingjsfolder/>
      Order allow,deny
      Allow from all
      Otions FollowSymlninks
      AllowOverride Node
   </Directory>
   #Don't forward anything in the js directory
   ProxyPass /js/ !
   
   #Forward everything else
   ProxyPass / http://some.production.site.com/
   ProxyPassReverse / http://some.production.site.com/
</VirtualHost>

So now when you open localjs in your browser, it forwards everything to http://some.production.site.com while letting any request on http://some.production.site.com/js/ to served from the local folder /var/opt/mytestingjsfolder/. This is becomes extremely handy for debugging, and development. ProxyPass will also work with SSL. I personally have my testing conf file, hosts file, and js testing code synched across my computers, So that I can easily test my js anywhere.

Oh and don’t forget to set your hosts file to point localjs to your home

Testing ExtJs: Finding the generated component id

The main reason anyone uses ExtJS is because they don’t want to program these widgets by themselves. The problem being for the automated testing people (meaning me) is how to select these widgets? Shouldn’t use XPath, because it is slow and IE doesn’t have it natively, because webdriver has to emulate XPath for IE. Using CSS is a pain in the ass because each ExtJS component has a random ID associated to the element. And the class definitions simply don’t make sense to me. What is worse is my web application does not add easily searchable component ids.

So this is how I handled it.

In javascript I used Ext.ComponentMgr to find the element I wanted

Ext.ComponentMgr.all.find(
  function(c) {
     return c.text == "Text of my element"
  }
);

This will return any ExtJs Component. Included the elusive autogenerated id which will exist in the “c.continer.id”.  So the only thing left to do is tell webdriver to run this javascript to get the id of the element to look for:

public class ExtJsSelector {

   static public String getMenuId(WebDriver driver,String name) {
      JavascriptExecutor js = (JavascriptExecutor) driver;
      Object o = js.executeScript("return Ext.ComponentMgr.all.find(function(c) { return c.text == \""+name+"\"}).container.id ");
      return o.toString();
   }
}

Now that i have the id, i can simply do driver.findElement(By.id(the_id_i_got)).

My way of getting the set of all subsets

So while working on one of the Dropbox Challanges, I developed a need to generate the list of all proper subsets of a set of numbers (Powerset).

def subSets(div):
	g = pow(2,len(div))
	result = []
	for x in range(1,g-1):
		sub = []
		w = x
		p = range(len(div))
		p.reverse()
		for d in p:
			if pow(2,d) <= w:
				w = w - pow(2,d)
				sub.append(div[d])
		result.append(sub)
	return result

Basically i think of the problem in binary. I am going to count from 0 to the max which is 2^(size of the list). For each of those numbers, if the first digit is a 1, then the first item in the list is included in my subset. If it was a 0 I wouldn’t include it. In the end I would have gone through every possible combination.

This came up when I needed to find the list of possible ways two numbers multiply to the same value as the mulitiplication of all primes in the list. There is a better way to word that. Basically I have a number, and I was curious to find all the different ways two number could be multiplied to make that number.

Follow

Get every new post delivered to your Inbox.