programming 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
6

For the Love of God, Optimize those Images!

Time for another lesson in web design: Image Optimization!  Yes, as we all know it is really pretty to have a huge header on your website.  Hey, look at this website, I have large images on my front page.  But, you don’t have to make that experience painful for your users, especially those on *gasp* dial-up!

The solution is simple: optimize your images.  I use Fireworks, but Photoshop has it built in these days as well.  It is basically a way of taking the image you want to use, and removes unwanted data, making the image size smaller, and hence, faster to load.  The web is a horrible medium for images, the 72dpi resolution of most monitors is just not that great.  But, it is all we have right now, and that is probably a good thing since anything more and the image just gets bigger and bigger.

By optimizing, your look stays intact, and everyone can enjoy it faster.  And it is cheaper on your wallet since it requires less bandwidth and less CPU to serve a smaller file.  Speaking of cheap, for those of you that do not have the Adobe suite, there is a pretty spiffy free online optimizer here.  Enjoy, and for the love of all things holy, optimize!

If you want to read more on the topic: HTMLSource.

Enhanced by Zemanta
Share
4

Programmers, do you have Insurance?

Calling all programmers, those of you that do it professionally at least.  Do you have your own personal errors and omissions insurance?  Should you?  Probably.

I have been in development for a long time time, about 12 years, and for the web development world I live in, that makes me ancient.  I carry my own errors and omission insurance for personal projects, just in case the GPL can’t protect me well enough.  What is this insurance you ask?

There is a good article over at Insurance Journal that goes over exactly what it is and why you might need it.  My question is a bit more complex though.  If you are a professional programming, working on someone else’s payroll, do you need this insurance?  If you are fired for incompetence, or laid off, and the company you used to work for finds a bug that has cost them $1M a week since it was implemented 2 quarters ago, do they have the right, or abililtty, to sue you for that loss?  Perhaps.  It all depends on where you live, what company, and the situation.

Being sued for something you did on the job, in the best interest of the company, under the leadership of someone else, is extremely rare.  Most likely because it requires the company to admit they were less than diligent, didn’t do a very good job managing, and then makes them liable to their stakeholders since they are basically admitting an agent of their company screwed up.  Companies don’t like to do that.

However, if you are working on a 1099 or a third party W2, you need to make sure you are covered.  If you are on 1099 or doing corp-to-corp, you had better have insurance.  You are liable in that case, in the absence of another contract, for everything you do and write.  While you probably wouldn’t be found guilty of anything (I hope), it would be expensive to fight it, and better let the insurance company do it.

If you are on a third party W2, make sure the folks you are actually workign for have E&O insurance as an add on or rider to their general liablity.  You could need them to protect you for something you did in their employ on behalf of one of their clients.

So, do you have insurance?  Do you need it?  I am not a lawyer, so none of this should be taken and blindly run with, but, ask yourself if you are covered, and if you have questions or doubts, find someone that knows and ask.  It never hurts and could save you a lot of trouble later.

Related articles by Zemanta
Enhanced by Zemanta
Share
0

Types of Programming Bugs

In a recent project I have been working on, I took over another’s code base, based in Drupal, and have been working to both fix issues and add functionality.  It has been a lot of fun learning Drupal, and working with this interesting application.  And finding different types of bugs.  If you are a programmer, you know there are bugs that are different and behave oddly.   Here are some types of programming bugs I have come across recently.

Heisenbug
Named for the Heisenberg uncertainty principle, this type of bug is only appears when you aren’t looking.  You know the kind, the kind you swear you can’t replicate, but yet, the users day after day report them happening.  If you try to measure this type of bug, you will inevitably alter your results.  They are the worst to track down, because a lot of the time you end up making changes just to hope they go away, even though you still aren’t sure exactly what caused them.

Keyser Söze Bug
These actually arent even bugs, but they make you think they are, and are a complete pain in the neck.  Basically, it is a “bug” that is causing a huge problem for you, but as you learn, and dig and dig, you figure out it isnt a bug, just a “feature”.  It may be stupid, illogical, or incorrect, but the code itself is working just as design and written.  So, in essence, it isnt a bug, only made you think it was.

WTF Bug
This is one of those that you swear up and down you have fixed, several times, yet is still there.  The most common one of these is when a customer’s ISP or internal firewall have cached old versions, so the damn thing is still cropping up on you, but you know it isn’t there anymore.  Another time these happen is when you change one part of the code, only to figure out that those methods were depreciated 8 versions ago, and now all that logic is somewhere else.  Yes you changed it, yes you committed it, but the bug is still there.

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
0

New Look for this.rand()

Well, it has been a while since I did a new look for our homepage, so here it is.  What do ya think?  This is a theme instead of the usual totally custom method I do, but I like it.  It is a very magazine type of look, but it gets a lot more content on the front page, and uses the sidebars better.  So it should drive a little more traffic, and be easier to use for those that do show up.

Share
0

phpMyAdmin over SSL

I get asked this question a lot: “How can I force phpMyAdmin to run over https ‘SSL’?” It is basically an issue to deal with security. Since phpMyAdmin deals with directly accessing your database, it only makes sense you want to make it as secure as you can. While running over SSL ‘HTTPS’ is not the total solution, it does help. So, here is how to make it run over SSL.

Read the rest of this entry »

Share
Tags: , ,