Monday, August 09, 2010

Apachectl: Use Wget instead of Lynx

A common error with apachectl is 'cannot find lynx'. This is a silly error because lynx is a text mode browser that is just used to retrieve the server-status page and grep out pertinent information.

Building Lynx just for use starting, stoppping, restarting, graceful, status, statusfull, etc. on Apache is silly. Most servers already have Curl or Wget. I prefer wget because it's simple and easy to use.

To use wget instead of lynx, modify your apachectl file as follows:

1. add a line near the top with:


2. About line 90-ish, you'll see status) - you should make it look like this:

# $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
/usr/bin/wget $STATUSURL -q -O - | egrep '(Current|Restart|uptime)' | sed 's/<[/]*dt>//g'
if [[ -f $PIDFILE ]] ; then
echo "PID: " `cat $PIDFILE`
echo "No PID file."

This uses wget to grab the status (uptime, restart time, etc.) instead of Lynx, which as I said should be discontinued as a dependency. As you can see, Wget solves the problem easily.

Note that the bottom section for fullstatus) is not changed; I didn't need the fullstatus, if you do, feel free to improve on this text.


Friday, July 30, 2010

had horrid trouble with Sybase Python interaction with escaping parameters. Problem was evinced by passing string ''' I'm ''' into an update statement with the simple:

'update table set field = %s where id = 1' % (instr)

The trouble with this is the sql string has a quote, and it dies.

Turns out, you have to escape by passing it into the c.execute(sql, paramHash)

code is as follows:

sql = '''update Answer set answerText=@at where answerid=2'''
c.execute(sql, { '@at':'hello'} )

This solves the parameterization. CRUCIAL POINT: HAVE TO USE @VAR NOT JUST VAR.


Tuesday, February 09, 2010

JQuery Autocomplete and the Back Button

JQuery's autocomplete plugin is great. No problems with it so far, easy to use, etc. However, one of my testers just found a problem:

1. Autocomplete is on Page Main. Enter text, choose option. Result function does redirect to page Other.
2. User hits back button on browser. Main shows up again.
3. form focus is still on autocomplete, so hit backspace and ... UG! space is cleared and now browser is trying to autocomplete something else into that field (usernames of all things).

So, after trying several things, including a window.onbeforeunload() method and clearing the autocompleted field, found that problem is solved by CHANGING FOCUS AWAY AND BACK.

Yes, it's that simple. Main's document ready function is called again after the user comes back using back button (thank goodness), so I just put a pair of lines in:


and it was fixed.

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() {
cache: false,
type: "POST",
success: function(html) {
// 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);
divloc = "#pActionDataProjid" + f;
var divobj = $(divloc);
$("#myprojectstable").trigger("sorton", [0,0]);
//console.log("done with AJAX POST.");
}, '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:

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
// 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) &&! { = 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
// 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'