Friday, November 18, 2011

linq js

In JavaScript (even with other framework library), there may not be some very easy dot notation way to filter data.

You often have to go through the whole collection then to push values into another array object to collect the values that you want, filtering. 

Data Structure
[ FieldName : string, Filters :  [ IsSelected : boolean, Value : variant  ] ]

Typical JavaScript Filtering Pattern
var data = fetchData(); // gets the ajax data in Json array
var filteredData = new Array(); // where new filtered 
var filterListLimit = getFilteredListLimit(); // number of times which the category changes


/// this is O(n^2) ~= f(x) = O * nO 
for (var q = 0; q < data.length; q++) {
var oX = data[q]; // for convenience
var includeCounter = 0;

for (var f = 0; f < FilterList.length; f++) {
if (oX[FilterList[f][0]] == FilterList[f][1]) {
includeCounter++;
}
}
if (includeCounter == filterListLimit) {
filteredData.push(oX);
}
}

In C#, you can do 
var filteredData =( from p in data
where p.key == 5
select new {
   Brand = p.Brand,
   Name = p.Name,
   Year = new DateTime(p.Date).Year
}).Distinct();

with linq.js, you can do
var filteredData = Enumerable.From(data)
.Where(function(x) { return ( x.key == 5 ) })
.Select("o=> { Brand : o.Brand, Name : o.Name, Year : o.Year "}).Distinct().ToArray();

Neat ... :-)

There are more examples and a file at the below link.

jquery.each inefficient

I have discovered that the jQuery.each() call is inefficient.

jQuery.each() maybe f(x) > n; where f(x) maybe n^i or xn.  i > 1.

I recommend using the for loop instead.

Wednesday, November 16, 2011

Selenium

SampleTest1
open / http://localhost:5000
waitForPageToLoad
select id=pageList label=2
verifyText //div[@id='workQueue']/table/tr[1]/td[2] some text value
click //div[@id='Filter']/ul/li[@id='BTU']/dl/dd[3]
verifyText //div[@id='workQueue']/table/tr[1]/td[2] some text value
select id=pageList 1
click //div[@id='Filter']/ul/li[@id='BTU']/dl/dd[3]
select id=sortList Applicant Name
verifyText //div[@id='workQueue']/table/tr[1]/td[2] some text value
select id=pageList 5
click //div[@class='queues']/ul/li[3]/a

Tuesday, November 1, 2011

Mac OS Mouse Scroll Reverse

If you have a mac, and you are using a non-Mac mouse, you are experiencing backward mouse scroll action, aka natural scrolling.. (stupid).

In order for the mouse scrolling to work like way it always worked is to open the terminal and type in


defaults write ~/Library/Preferences/.GlobalPreferences com.apple.swipescrolldirection -bool false


you then either have to log out or restart.

bam!


Wednesday, September 21, 2011

Acer declines in Q2 2011

I am not surprised by the report that Acer is now the #4 PC Maker.

Acer just didn't drop to No. 4 from No 3 but its PC shipments has decreased while other top 5 makers increased their shipments.  There are reasons why Acer has fallen.

Their PCs aren't very exciting.  They turned Gateway to Packard Bell of today where none of the Gateway's machines are exciting and highly featured.   Their notebooks are nothing compared to Dell's or HP's. Their FX series matches low end Alienware's effort.

Acer's laptops, tablets, and PCs are just not that exciting either.  Their tablet is really waste of money when you can buy iPad, Samsung Galaxy, or Sony Tablet S.

I like what ASUS, Dell, HP, and Apple are doing, not Acer.  I really want to like what Acer is doing but can't.

source: http://www.gmanews.tv/story/233033/technology/lenovo-topples-acer-as-worlds-3rd-largest-pc-vendor
Gateway: http://us.gateway.com/gw/en/US/content/models/fx-series
Acer: http://us.acer.com/ac/en/US/content/home

Monday, April 11, 2011

Thursday, September 2, 2010

JavaScript Age Calculation

function IsValidAge(agelimit) {
var month = document.getElementById("ddlMonth").selectedIndex-1;
var day = $("#ddlDay option:selected").val();
var year = $("#ddlYear option:selected").val();
var Birthdate = new Date(year, month, day);
var Today = new Date();
var diff = new Date(Today - Birthdate);
var days = diff / 1000 / 60 / 60 / 24 / 365.25;
var age = Math.round(days);
return age > agelimit ? true : false;
}