geekdom Archive

0

Tweaking Jquery AutoSuggest

I have been using the JQuery library for a long time now, and am still amazed at what people get it to do.  One feature that the base libaray was really lacking was a good Autosuggest for a text input.  It needed to be AJAX driven, and understand having multiple values.

I found a great example of what I wanted at Drew Wilson’s blog, complete with almost all the features I needed.

One thing his script is really lacking is a good way to show ALL the results.  We have a huge category list, and want to let someone browse them all.  In the base script, this isn’t going to work, since there isnt a way to make the look up fire off without input.  I didnt want my users to have to enter in, one by one, each letter of the alphabet looking for what they wanted, so I settled on using a double click event to force the display of the entire list.

And here is how to make that happen:

In the js file (jquery.autoSuggest.js) you will need to make some changes.

~line 149 add:

 }).dblclick(function(){
 if (timeout){ clearTimeout(timeout); }
 timeout = setTimeout(function(){ keyChange(); }, opts.keyDelay);

so it will look like:

 }).blur(function(){
 if($(this).val() == "" && values_input.val() == "" && prefill_value == ""){
 $(this).val(opts.startText);
 } else if(input_focus){
 $("li.as-selection-item", selections_holder).addClass("blur").removeClass("selected");
 results_holder.hide();
 }
 }).dblclick(function(){
 if (timeout){ clearTimeout(timeout); }
 timeout = setTimeout(function(){ keyChange(); }, opts.keyDelay);
 }).keydown(function(e) {

This will pull up a list on double click.  You can change dlbclick to just click for a single click response instead.

~line 226 comment out the lines:

if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) ){ return results_holder.hide(); }

and

if (string == prev) return;

and

if (string.length >= opts.minChars) {

and then on ~line 252 comment out

 } else {
 selections_holder.removeClass("loading");
 results_holder.hide();
 }

You will also want to turn the option “resultsHighlight” false, when you create the instance.

Now, on double click it will present a full list of options.

Enhanced by Zemanta
Share
3

HTML Validation is (still) pointless!

Ok, so we all know that we should write “valid”* HTML, and yet, less than 5% of websites validate for one reason or another.  Now this statistic can be a bit misleading as a comment from a user that didn’t use valid markup could invalidate the website, so granted, there is some play with the stats (per the usual), but let’s again assume that number is close.

Why?  Why do we not write perfect HTML?  Surely with the free validator on the authority’s website there is no excuse to write code that wont validate against the standard.

The answer there is simple, if and when all the major browsers (Firefox, Safari, IE, Opera, Chrome) all render a page according to the standard, then I will finally start caring about the validation of my websites.  Until then, I will continue to write code that works across the board, and just not care if it is “valid”.

To be real though, most of the browsers work pretty well, however the 800lb gorilla in the room, IE, does not.  Microsoft continually changes the standards by which they will render a page, like promising CSS 2 support in IE7 then bailing on that promise 6 months before release.  And let us not forget the horribly pathetic Javascript rendering engine, JScript, that the rest of us just ignore because it can’t be trusted to behave reliably.

So, like even on this website, we find ourselves writing “valid” code, and at the same time having to redefine valid to mean “Code that works in all the browsers”, not “Code that the W3C says is valid even though it looks like crap in IE6″.  Just to maintain a semblance of order and sanity, we use the handy IE CSS hacks where IE on Windows will actually arbitrarly execute code depending on the version of the IE browser being used.  Does that sound like an admission of guilt on the part of MS to anyone else?  OK Bill, repeat after me, “I know my browser sucks, so, instead of fixing it which would severely hamper my marketing and legal budgets, I will just allow hacks in order to ensure you nerdy web guys can still make pretty pages”.  There, was that so hard!?

So, someone feel free to run the validate against any of my websites.  Don’t bother sending me the results because I don’t care.  The sites work, the code looks good, documented, and is maintainable, so, what exactly was the complaint?

*valid code is extremely subjective, but let’s assume here I mean W3C “valid” code.
Reblog this post [with Zemanta]
Share
1

Why Drupal Views make so little sense

I recently had a very short contract gig working for a company that creates websites using Drupal.  While that doesn’t sound very interesting or even hard, to make it more so of both, these guys used Views for every

Drupal
Image via Wikipedia

thing.  Which I just don’t get.

If you are a programming, why would you use views?  It is adding a layer of abstraction between the logic and database in an interpreted language with a framework that is already bloated beyond all recognition.  I know when I write plugins for WordPress, I want the plugin to be quick, precise, and add the least amount of overhead possible.  Views just seem to be a way to do all the opposites of those, just for the hell of it.

If you are not very technically inclined, I understand.  Using views is a lot like using MS Access.  You can create fairly complex queries yourself, without having to get someone that actually understands it involved.  And that is the trade off.  You can do it yourself, and eat the extra overhead, or pay/hire/bribe/cajole someone else into doing it for you, specialized, and thus, in theory at least, more efficiently.

These folks claimed to be programmers though, so I just don’t get it.  Why are you depending on someone else’s plugin, that extends functionality that is inefficient and clumsy, can’t do everything, and still requires custom code to be written or even more plugins to be added.  Where exactly does that circular line stop?

The Drupal “framework” and I use that term loosely since it is really a CMS that can just be extended, has enough problems and bloat in it, why exactly are views worth adding more?  Again, assuming you know SQL and PHP on even a basic level.

It just doesnt make any sense.  Query writers and views are one thing if you are working directly with the database, (e.g. phpMyAdmin or TOAD), but adding it as a layer to a “custom” application that you will be supporting when you claim to be capable of actual programming!!??  Please explain that one to me.

To be fair, I dont use Drupal much, I like WP much better.  The OO approach is much more appealing than the very Perl-esque (read: old) way of doing things Drupal does with its modules. But I still don’t get what the big deal is about Views.

Enhanced by Zemanta
Share
1

Programming Standards are NOT pointless

It seems some people took my other article a bit too seriously.  While I was very serious and feel strongly about my convictions when it comes to HTML “validation”, the same cannot be said of programming standards.

For those of you that have never programming professionally, this stuff may be very new to you.  However, trust me, it is extremely important.  Programming standards are not stupid, are not corners to be cut, and must be strict, otherwise they ARE pointless.

There are standards when it comes to documenting your code, and I wont get into them.  But if you are interested there are programs out there which more or less set the standard if you want to use them.  JavaDoc, PHPDoc, and for those MS folks….. .  Go check out their websites for good advice on how to format your comments in your code.

Now, for actually coding, I have my own set of standards, developed over the years, to make the code both readable, but also hopefully logical.  Most people I run into think my code is pretty readable, some languages more than others.  Let’s face it, Perl code will never, ever, be as readable or “pretty” as Python.  It just isn’t going to happen.  Sorry you old UNIX guys, but Perl just isn’t very pretty.  The OO languages are much easier on the eyes.

So, other than for documentation reasons, readability (which leads to maintainability), are there actually other reasons to program to a standard?  Only if you want to use your code in some sort of portfolio.  But those first two reasons are EXTREMELY important.  Everyone out there that has programmed professionally will know exactly what I mean.

Tabs or spaces?  Braces at the end of a line or on their own line?  Spaces between concatenation or operators?  Double quotes or single quotes?  Print to buffer or hold in variables?  Globals or object variables?  Arguments or variables?

There are a ton of questions, and I cant answer them all.  But think about why you do something, and if you cant come up with a good reason, probably time to stop doing it.

Enhanced by Zemanta
Share
0

How to fix WP ECommerce

On front end pages with no ecommerce functionality, this plugin adds over 220+ database queries.  The more I messed with the code trying to make it behave, the more I understood just how horribly written this plugin is.

Now, as someone that has been doing development long enough to know, there are times that code just gets away from the development team and becomes a mess unto itself.  It happens, especially in the OSS world where code reviews are few if ever.  But, as I read the forums for this thing, the developers are just fooling themselves thinking the code is in good shape.

Here are a few basic suggestions:
1) Check to see if the page needs to execute the plugin.  If it doesnt, dont do it.  There is no reason to increase the number of queries by an order of magantuide when I am on a page that has no WP Ecommerce functionality.
2) Clean up the queries.  For example:
SELECT `id` FROM `wp_product_list` WHERE `active` IN(’1′)
should be
SELECT `id` FROM `wp_product_list` WHERE `active` = 1
It is more effiecent.

3) Index the tables!  The query above doesnt use an index.  That is right folks, the field “active” in product_list is not indexed.  This is easy and simple.

4) Use arrays or some other data structure for complex data.  Dont use the same basic query over and over again.  Example:

Share
2

Well Played Windows 7, Well Played

I had been having some problems with my computer lately, I have no idea what caused it, but I was running XP Pro for about 5 years without a single re-install, which must be a record of some type.  But the screen would get a bunch of lines on it after any given amount of time, forcing a reboot.  Totally impossible to get anything done.

Well, I thought “Video Card“, but I was wrong.  I went out and bought a new ATI 5870 by Asus.  Turned out replacing my 4870 with that beast didnt do a thing for me.  So, back the $400+ card went.

Well, it must be software then, the problem now being I can either re-install XP, or try Windows 7 since that is where I will have to update to within 6 months anyways.  Out I go to get Windows 7 Pro, and more than $2,000 later, it is finally installed and working.

Upon installing it, I had network driver issues from hell.  Who knew a Linksys wireless G PCI card wouldnt work with Win7?  What kind of moronic OS development team made it where one of the most prolific network card manufacturers products wouldn’t work?  Answer:  Microsoft!  But since I used the word “moronic” we all knew that was coming, right?  Ok, read a lot online about the various woes of people with that card, and I upgraded to a D-Link N card, that seemed better.  Only, it wasnt.  But I knew, from what I read online the network card was correct.  Could it possibly be my Linksys router?  I mean, really, a router is a router right?  Nope!  I replaced the router with a Netgear one and BAM, it works great on the network now.  Spiffy!  Time to start installing software finally.

That’s right, installing software, because for some dumb-ass reason you can’t upgrade from XP to Win7, they expect you to have had 2×4 to the head and actually used Vista.

Start installing software, and the first reboot, the computer doesn’t come back up.  Not only that, the primary hard drive isnt even seen by the BIOS anymore.  WTF!!!???  How did Win7 just kill a Seagate HD?  I have no idea, but it did.  Off I go to purchase new hard drives.  This time, I got two, so I can RAID 1 them, “ah ha!” I will show you Microsoft, I will fix your stupidity with hardware. RAID array created, Windows 7 installed (again), and now I can start installing software.

But wait, Adobe CS2 isnt supported by Windows 7, so, $1,699 later, I am the extremely annoyed owner of CS4 Web Premium, a supported version of the ridiclously priced yet required by everyone software suite.

I get everything re-installed, except for my document management software, Source Link.  It seems those retards over there won’t reissue a CD key without a $60 fee, “because that is how we control the licenses”.  “Why do I use your software again”, I wonder as I am re-downloading games from EA, QuickbooksNuSphere, and a ton of other software that doesnt require me to pay them to reinstall their software on the same computer. Clearly everyone else has figured it out, even Microsoft and Adobe!  And get this, I get to upgrade as well to SourceLink 2010 in order to have it supported as well.

So, what is the final tab you ask….

$200 for Windows 7
$350 for 2 Hard Drives
$70 for Network Card
$70 for Router
$1700 for Adobe CS4
$50 for new McAfee
$169 for SourceLink
Total: $2,609 plus tax for the privelege, nay honor, nay ass raping that is Windows 7.  I bow to Microsoft’s superior skills at making their products part of everyday life, because both I am in awe I spent that much, and bowing is about all I can do since I won’t be sitting for at least  week, or until the bleeding stops.

Enhanced by Zemanta
Share
0

You think I have free time!??!?!

I think sometimes I have too much free time, but it is nothing compared to this guy. This rates up there with the homemade Battlemech, but still pretty cool.
Backyard Monorail

Share
Tags: