Javascript scope in for loops

In JavaScript, you don’t need to define your variables.  You can just up and use any variable as you see fit, like this:

asdfasdf = 'asdfasdf';

However, these variables will then be created in a global scope, which is bad.

I came across a bug today that involved for loops and globally undefined variables.  It’s not as clear what is happening when the counter variable is first used inside the for declaration, but the result is the same: a global variable:

function test2() {
     for (i = 0; i < 10; i++) {
         alert(i);
         test3();
         alert('now i is ' + i);
     }
     alert('done');
 }

 function test3() {
     for (i = 0; i < 10; i++) {
         // do whatever here
     }
 }

In this example, test2()’s for loop will only run 1 time, because test3’s loop ends up using the same variable.

To fix this problem you need to define your looping variables:

for (var i=0; i < 10; i++)

This is a best practice that you should remember to do.

Advertisements

Comcast turns off your internet

Last night, all of a sudden, my internet connection went down.

After a while, all my web requests started getting directed to a comcast page that said:

“You will need to activate your account”

telling me that I needed to download some software.  Total BS.

The link for the software didn’t even work.  I tried rebooting the modem, the router, nothing worked.

So after an hour in a comcast support chat (using my EVDO card for internet) they finally added my modem back to their system (or whatever).

If you get this message, and you are not a new customer, either comcast f’ed up (which is likely because they are possibly the worst company on earth) or you didn’t pay your bill.

Skype on Mac OSX

My wife just tried to install Skype on her Mac OSX computer.  Of course it didn’t work.  Nothing ever works on Macs it seems.

After lots of messing around I found some random suggestion on some forum to try this:

1. Quit Skype
2. Go to the folder “ ~/Library/Application Support/Skype/ “
3. Delete the file “shared.xml”
4. Start Skype

Amazingly, this worked.

Disabling SSRS Subscriptions

As far as I could find, there is no easy way to disable (not delete) an SQL Server Reporting Subscription.

We thought we had found a way to do this by changing the schedule to “run once” and set an “End Date” so that it would never run after that date.

This seemed to work, but after a restart of the server this weekend, the job executed on monday morning.

I’m not sure why it happened Monday morning ( as opposed to Sunday morning, as the machine was restarted on Saturday night) or if has anything to do with today being the first of the month, but either way, this didn’t work and people were emailed some useless notice that they didn’t need.

So, if you are using this method to disable your SSRS reports, watch out.