Tag Archive for programming

Disabling Empty Tab Completion in Bash to Prevent Delays

While typing in a terminal, tab completion is a huge time saver. Being able to auto-complete file names or commands is very nice, especially if you can’t quite remember what it is.

There are times, however, that this has become quite annoying for me as a developer. More than once a day when I really get in the zone and start hacking, I will accidentally hit tab when I have not yet input anything. While this doesn’t slow things down too much for me on a native Linux installation, it causes a huge delay when using Cygwin. Instead of just quickly asking me if I want display all the options, it appears to start to build the command list which has a delay of many seconds. This completely breaks my flow of programming.

I’m not entirely sure if it has to do with the number of possible auto-completes in my Cygwin installation or if it just is slower than a Linux installation but I didn’t want it anymore. I never find myself just hitting tab to get the list of every possibility; I am always auto-completing.

Having searched online before for a solution but never coming up with anything I just sort of accepted that my flow would be interrupted every once in a while by this silly behavior. Today, I ran into the issue multiple times and decided I had, had enough. I hopped into ##linux on Freenode.

There, I was delivered the option that would make my problem go away:

shopt -s no_empty_cmd_completion

Dropping this line in my ~/.bashrc file accompanied by a quick restart finally made my problem go away.

Much better.

Creating Elements with jQuery and Internet Explorer

And if I had a gun, with two bullets, and I was in a room with Hitler, Bin Laden and Internet Explorer, I would shoot Internet Explorer twice.

When creating HTML elements with jQuery, there is an elegant syntax that was introduced quite a few versions ago.

$("<div/>", {
    id: 'someDiv',
    class: 'someClass',
    text: 'Some text in the div.'
}).appendTo("#someOtherDiv");
 
// Another example
$("<label/>", {
    for: 'someInput',
    text: 'Label for my Input'
}).appendTo('#selectDialogue');

Simple, elegant and easy to use. This code works fine in Google Chrome and Firefox.

Unfortunately, every developers favorite browser, Internet Explorer, chokes with the following error message:

…expected identifier, string or number…

It took me a while to figure it out but, through trial and error, I discovered that the issue was with the way Internet Explorer handle reserved words. In this case, both examples are using two that IE will simply choke on. Here are the offending lines:

class: 'someClass'
for: 'someInput'

Internet Explorer will not allow you to set these attributes when creating the element. After spending too much time tracking down and figuring out the problem, since IE is so good at explaining itself when it comes to errors, I came to a solution. My first reaction was to simply apply the attribute to the element after it had been generated. After speaking with a colleague about the issue, he suggested putting the attribute name in quotes to see if it would do the trick. Turns out: this worked just fine.

After some digging around, I came across some documentation available from the jQuery folks that describes this problem. Unfortunately, this documentation was not prevalent in any of the searches I was attempting to perform. Here’s what they had to say (emphasis added):

As of jQuery 1.4, the second argument to jQuery() can accept a map consisting of a superset of the properties that can be passed to the .attr() method. Furthermore, any event type can be passed in, and the following jQuery methods can be called: val, css, html, text, data, width, height, or offset. The name “class” must be quoted in the map since it is a JavaScript reserved word, and “className” cannot be used since it is not the correct attribute name.

Using the quoted attribute solution, our code changes to:

$("<div/>", {
    id: 'someDiv',
    'class': 'someClass',
    text: 'Some text in the div.'
}).appendTo("#someOtherDiv");
 
// Another example
$("<label/>", {
    'for': 'someInput',
    text: 'Label for my Input'
}).appendTo('#selectDialogue');

This allows Internet Explorer to go along it’s merry way doing it’s browser impression as best as it possibly can.

I hope this helps post will help others who come across this problem. If you liked this post, please consider subscribing to my feed.

The Joys of Merging Code

I consider myself lucky to work at a place where we have someone working QA to ensure the code we’re pushing out isn’t going to blow up. When a development ticket has passed through QA, we get an email to let us know. Usually saving the task of merging code until the end of the day allows me to spend the last bit of time doing something that doesn’t require a huge amount of brain power. Normally this consists of running a merge command and fixing a conflict that pops up every once in a while.

Occasionally things just don’t work out that way.

$ svn merge -r 24936:24937 http://blade00/svnroot/crm/trunk
Conflict discovered in 'soapserver/soap_server_production.wsdl'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p
--- Merging r24937 into 'soapserver':
C    soapserver/soap_server_production.wsdl
Conflict discovered in 'soapserver/soap_server_uat.wsdl'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p
C    soapserver/soap_server_uat.wsdl
Conflict discovered in 'soapserver/soap_server_staging.wsdl'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p
C    soapserver/soap_server_staging.wsdl
Conflict discovered in 'soapserver/soap_server.php'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p
--- Merging r24937 into 'soapserver/soap_server.php':
C    soapserver/soap_server.php
Conflict discovered in 'soapserver/soap_server_dev.wsdl'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p
--- Merging r24937 into 'soapserver':
C    soapserver/soap_server_dev.wsdl
Summary of conflicts:
  Text conflicts: 5
FFFFFFFFFFUUUUUUUUUUUUUUUUUUU

Ahh… the joys of merging code.