Tuesday, January 26, 2010

JQuery: TableSorter AJAX Zebra Fix

Just had a day of yuckky dealing with a 'bug' / nonfeature of JQuery's Tablesorter dealing with an AJAX call. Problem was that once I make the ajax call, the zebra striping goes all to hell.

This was due, it turns out, to 2 things:
1. I had a hidden/openable div in one of the table cells;
2. I didn't have the update call after the ajax return.

IMPORTANT: TO SEE FULL CODE, CUT AND PASTE. STUPID LAYOUT OF THIS BLOG. The text/code is really there, the viewable div below prevents it from displaying. Just cut and paste the code fragments below to see the full code...

So, step one:


function actionCount() {
$.ajaxSetup({
cache: false,
type: "POST",
success: function(html) {
$("#myprojectstable").trigger("update");
// console.log("Inside Success function..");
}
});
var orgid = $("#orgID").val();
var projidlist = <%= self.fields.projidlist %>;
$.post("ActionsCountJSON", { projids: projidlist }, function(raw){
var rawData = raw['resultSet'];
var rawList = raw['resultListing'];
for (f in rawData) {
var divloc = "#pActionsProjid" + f;
var divobj = $(divloc);
divobj.html(rawData[f]);
divloc = "#pActionDataProjid" + f;
var divobj = $(divloc);
divobj.html(rawList[f]);
};
$("#myprojectstable").trigger("sorton", [0,0]);
$("#myprojectstable").trigger("applyWidgets");
$("#myprojectstable").trigger("update");
//console.log("done with AJAX POST.");
//stripe("myprojectstable");
}, 'json');
}



Having the update there made the widget trigger after the ajax returned, a vital thing because otherwise tablesorter doesn't know the underlying data has changed. After I had this, it resorted after the ajax came back.

Next, I had a widgets: [zebra] in my document ready function, but this widget wasn't working right.

So, I replaced it with my own widget by specifying widgets: ['zebraKJR']
then creating that widget as:



$.tablesorter.addWidget(
{
id: "zebraKJR",
format: function(table)
{
var even = false;
// console.log("zebraKJR called.");
// if arguments are provided to specify the colours
// of the even & odd rows, then use the them;
// otherwise use the following defaults:
var evenColor = arguments[1] ? arguments[1] : "#fff";
var oddColor = arguments[2] ? arguments[2] : "#cde4ff";

if(table.config.debug) { var time = new Date(); }

//var tbody = $("tr:visible",table.tBodies[0]);
// by definition, tables can have more than one tbody
// element, so we'll have to get the list of child
// <tbody>s
var tbodies = table.getElementsByTagName("tbody");
// and iterate through them...
// for (var h = 0; h < 1tbodies.length; h++) {
for (var h = 0; h < 1; h++) {
// find all the <tr> elements...
var trs = tbodies[h].getElementsByTagName("tr");
// ... and iterate through them
for (var i = 0; i < trs.length; i++) {
if (trs[i].id != 'stripeMe') {
// console.log("SKIPPING thru tr's, h="+h+", i="+i+", len="+trs.length+", trs data:"+trs[i].id); //innerHTML
continue;
}
// console.log("COLORING thru tr's, h="+h+", i="+i+", len="+trs.length+", trs data:"+trs[i].id); //innerHTML

trs[i].style.backgroundColor = even? evenColor : oddColor;
// avoid rows that have a class attribute
// or backgroundColor style
if (true) { //(! hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
// get all the cells in this row...
var tds = trs[i].getElementsByTagName("td");
// and iterate through them...
for (var j = 0; j < tds.length; j++) {
var mytd = tds[j];
// avoid cells that have a class attribute
// or backgroundColor style
if (true) { //(! hasClass(mytd) &&! mytd.style.backgroundColor) {
mytd.style.backgroundColor = even ? evenColor : oddColor;
}
}
}
// flip from odd to even, or vice-versa
even = ! even;
}
}
}
});



That's it!

I also have a parser method for parsing text out of HTML tags:


// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'noUrlSorter',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
beforeString = trim(s);
t1 = s;
t2 = t1.replace(/\"/ig,"");
t3 = t2.replace(/(<([^>]+)>)/ig,"");
t4 = t3.toLowerCase();
//alert(" t1="+t1+
// ",t2="+t2+
// ",t3="+t3+
// ",t4="+t4);
//console.log("parsing, b4="+beforeString+", returning: "+t4);
return t4
},
// set type, either numeric or text
type: 'text'
});

Thursday, August 13, 2009

diffdir

One thing Solaris does nicely is let you find the differences between directories and show 'em side by side so you can figure out what files are where.

I'm using Ubuntu (and Bash, like normal) and need to find a dir diff showing files in one dir and not in another, etc .

this is simply the command diff -q -r dir1 dir2.

However, I'm using source controlled directories, so this shows up with a whole mess of gall-durn .svn directories, etc. So I need to filter this out and an alias won't work.

Here's the code for my dirdiff or diffdir bash script:


#!/bin/bash
#--verbose
if (!(test -d $1))
then
echo "bad dir 1";
exit;
fi
if (!(test -d $2))
then
echo "bad dir 2";
exit;
fi
out=`diff -q -r $1 $2 | egrep -v svn `;
# echo "Result of diff: $out";
if [ -z "$out" ]
then
echo "Same";
else
echo "Difference between $1 and $2: "
echo "$out"
fi
# echo "Done";


Tuesday, August 11, 2009

Submission to FCC Re: Broadband

Who I Am / Use Cases:

1. I am a computer professional and use a large amount of bandwidth connecting with my workplace's VPN.

2. Further, I regularly download and upload large amounts of source code as part of my work on Linux and open-source related projects.

3. Futher, I have a great interest in downloading movies via Hulu.com, NetFlix.com, etc.

My requests / Interests:

1. My cable TV provider (Comcast, Inc.) provides my internet connection. They currently have a cap on usage of about 250 GB per month, but no way for me as a user to track my usage level. They also have a penalty for overuse of 'banishment' which would leave me with far fewer options for broadband.

Proposal: Require all providers that provide ISP services that have a cap on overall bandwidth usage to provide a free, auditable, accessible via automated tool (website, etc., vs. calling in by phone), means of finding out our usage.

Proposal: Require any cap on bandwidth to have reasonable overage charges in line with actual usage. That is, if there is an overage, an email would notify me, and my account would be charged a fee at the same rate or less than the original usage. This prevents them from setting a $10,000 fine on a small overage. If my monthly bill is $50, then doubling the bandwidth usage would ONLY double my bill, or less.

3. Describe in law that any collusion between ISPs (comcast, AT&T and/or other DSL providers, etc.) in setting prices, contract terms, or making available services or not, would be punishable under anti-trust statutes.

4. PROHIBIT MANDATORY COLLECTIVE BARGAINING in ISP broadband contracts. These massively favor the corporate interests and are well-known to almost never result in outcomes favorable to the 'little guy'.

5. Alternatively, require publication of all collective bargaining cases in the form of submission to a public civil federal court to establish if the cases are being resolved / adjudicated fairly. No outside judicial review of these cases ever occurs and this practice is organized fraud under the guise of allegedly fair practices in a gamed system.

6. I agree that all federally funded road and bridge projects require installation of large scale conduit in public rights of way affording access to the installation of dark or used fiber optic or other communication cables. Such space to be leased in a manner to prevent monopolizing of said conduit capacity by any one provider.

Your Confirmation Number is: '2009811037388 '
Date Received: Aug 11 2009
Docket: 09-51
Number of Files Transmitted: 1

Wednesday, June 10, 2009

Summer Reading Ideas

I recently wrote this as recommendations for good books for a trip:

Reading is all about what's right FOR a person. Not knowing you well, difficult to say.

However, one of the best science fiction books I've read in years is "Old Man's War" by John Scalzi (sp?). If you liked Heinlein (best: 'To Sail Beyond the Sunset", "Stranger in a Strange Land", or "Have Spacesuit Will Travel"... Or perhaps "Starship Troopers" which was 100x better than the movie), or Asimov (best: "Caves of Steel"), you'll like Old Man's War.

If you're more into NonFiction, "The World Is Flat" is good despite being several years old. "Eat the Rich" is very funny and an excellent economics bit told with lots of jokes and irreverent humor.

"Hitchhiker's Guide to the Galaxy" is fantastically funny science fiction, again 100x better than the movie.

I recently read a thing called The J Curve which has completely changed my understanding of international politics, talking about how countries behave in general terms, and evolve from autocracies to pluralistic democracies, or NOT, as the case may be. Feel free to skim, this has great parts and boring bits, but it's worth skimming to get there.

I was traveling in Europe many years ago and found a copy of Rob Roy, which was great reading on the trains. Long, yet very engaging.

Anything by Mark Twain makes great reading for travel - easy to put down and pick up again.

All in all, your best bet is a librarian, someone older who's been there a while. Tell them what you've read and liked, and be honest. My mother in law is a librarian, and she is one of the least judgemental people I know. She's found me great books, because she knows my taste and can match books to it.

Monday, June 01, 2009

On the Idea of Being Awesome

AWESOME nature entwines within its nonchalant grasp that mote of me.

Casually searching for meaning, loving and being loved, I hope for a difference-making life to emerge from this, my formless day-breaking average-ness, my oft-times mundane but happily or at least consolingly unique existence, my castle of experiences.

Such castles I have witnessed and joined in assembling, my own and my cared-for compatriots. These being assembled, we build them from our faults and costs and joys and glees.

Such are the AWESOME projects I set my shoulder upon. Such projects are unleashed by ashes and sawdust, by baby's cry and dinner's on and cleaning messes made by my not-swift-enough fingers or too-swift tongue.

I find my sadness and happiness and all betwixt that remains of a day, Awesome.

Wierd Phone dialing rules

Ok, so it occurred to me today again how silly and wrong the numbering scheme for phone numbers is.

It's especially confusing when you're abroad. Country codes are not all the same number of digits, like area codes. Very Silly way to run a numbering scheme.

My opinion: Country codes should all be the same length, say 3 digits. There's only 211 countries, that should be enough. From anywhere then, dial 999, then the country code, etc. Everyone knows the same rules, everywhere it's the same idea. If you don't dial 999 first, you're dialing inside your country. Every country has a different number of digits in their numbering scheme, too! It's confusing and yucky!

So how hard would it be to have a 10 digit number (area + 7) for every person in every country? that's enough, isn't it?

(123) 456-7890 = 1,234,567,890 == 1.2 billion phone numbers per country. Ug. Doesn't work for China or India if everyone has a phone number there.

Ok, so we decide on an 11 digit number (4 digit area code) and we get 12 billion numbers per country. That's enough.

Better yet, your phone number could be yours for life, and you could register it with a phone handset or location, like we do with cell phones.

I guess the only change here would be adding a digit to the area codes. But, the international dialing scheme would change so no matter where you went, you'd easily understand how to dial in that country, and between countries.

This is sounding a lot like the domain name scheme for the internet. I know, too idealistic to work. Maybe in 100 years when we need the flexibility. Or, it's utterly silly because in 100 years, there won't be phone numbers, there'll be phone 'codes' like domain names you register, and it will stick with you for as long as you want, and any computer/phone (like there's a difference) can find you.

Rant mode off...

Tuesday, April 28, 2009

Just had a big problem with my at-work PC. I upgraded from Intrepid to Jaunty, and X stopped working. Not just a little - hard lock on start. UG! Tried previous kernels, no go, same symptom, so not that.

Tried recovery mode netroot, root with networking. didn't know my graphics card. Looked at xorg.conf for complexities. But, xorg.conf yielded NOTHING, it was very generic, it can't be failing. Running lspci shows I'm running ATI RV515 GL (that's a FireGL V3350 card). Jaunty upgrade failed with this card.

Link Here to read great explanation of fixing it

Summary of commands from this other page:
$ sudo apt-get remove –purge xorg-driver-fglrx xserver-xorg-video-ati xserver-xorg-video-radeon
$ sudo apt-get install xserver-xorg-video-ati
$ sudo apt-get install –reinstall libgl1-mesa-glx libgl1-mesa-dri
$ dpkg-reconfigure -phigh xserver-xorg
Presto, reboot and glorious!