Posts Tagged ‘Programming’

Virtual Drives

Wednesday, May 6th, 2009

I had this “virtual drive” script I wrote setup a while back for my windows machine to make certain things easier.  For instance I setup my apache htdocs directory so that it was the “W” drive so I could just open my computer and W and I would be there with my websites – it just made things more easily accessible.

The solution was used again for a different purpose when one day I had a friend who had installed windows and something went wrong.  A drive other than his main windows partition was set as “C” and his windows partition was created as “F”.  What made this a problem was that when he would install some programs (flash for example) it would attempt to install certain things to the registry on the “C” drive which it couldn’t find and there seemed to be no way to correct this.  So I showed him my little trick.  I didn’t think much of it until the other day he asked me for the script again because when he just installed his new computer the USB drive was “C” and he messed it up again.  He said he searched for a fix on Google and couldn’t find one.  You can’t just rename the partition because you are using it.  I imagine there is some kind of a fix if you put in a live cd and you can change it but we didn’t really look into it.  I just gave him the script and off he went.

So its a very simple batch script and you can modify it to do either of the things that I just mentioned.  Just save the following as virtualDrive.bat (or whateverYouWant.bat)

This first one shows my setting up the W drive:

@ECHO OFF
ECHO.

subst W: /d
subst W: D:\htdocs
CLS
EXIT

This one shows the fix if your windows partition is not set to C and it is causing you a problem:

@ECHO OFF
ECHO.

subst C: /d
subst C: F:

CLS
EXIT

The first “subst” line deletes the “C” drive in case your script has already ran previously (this stops an error from popping up if it already exists) – The second creates the “C” drive pointing to the “F” drive.

The last hint is that if you want to have it created every time you start your computer, just put a link to the virtualDrive.bat file in your startup folder in the start menu.

IE and DOM buttons – The correct way

Tuesday, August 26th, 2008

I have had so many problems creating buttons in IE using the dom that I had gone to just using images as buttons and adding them. Turns out there is one simple thing you can do to get it to work. Create the button, then add it to the page…

Here is what I was doing:

var button = item.appendChild(document.createElement('input'));
button.type='button';
button.value='THIS IS A BUTTON';

This code always threw an error, however if you do it this way (creating the button, and then adding it) it works fine:

var button = document.createElement('input');
button.type='button';
button.value='THIS IS A BUTTON';
button = item.appendChild(button);

Have fun dynamically creating forms that will work in most browsers!

Remove yourself from your google analytics

Thursday, March 6th, 2008

Are your Google Analytics stats messed up because you go to your site all the time? Would you like to fix that? Well Google provides a way you could block the traffic from a certain IP address. But if you are checking it from a range of computers then that doesn’t really do you any good. You can block a range but what if you use your laptop all over town and connect into different wireless access points. Or in my case when I go to school I get an new IP every day if not more. So what I decided to do was to defeat it with cookies.
The first step is to create a page that will store a cookie to the computer. For this site I added it into the submission page for these posts. No one else comes here so I shouldn’t have to worry about people accidentally getting the cookie set on their own computer. (A side benefit of having it on a page that I use a bunch is that if I clear my cookies it comes back without me having to think about it.) To create a cookie on a page using php you put this at the top:

<?PHP
setcookie (“analytics”, “no_analytics”);
?>

This sets a cookie with the name analytics and the value no_analytics set to that cookie.
Next, we put an if statement around where we record the analytics (for me this is in the header so it is called on every page.):

<?

if($_COOKIE["analytics"] != ‘no_analytics’) // if there is a cookie for this site that contains this information then the analytics will not be counted
{

?>

This If statement will check the cookie and if it exists it will not print out the javascript that sends the information to the Google servers. As long as you have the cookie set in the browsers you use, you will be able to visit the site without being counted. And if you visit from somewhere else – if you want you can hit the page, store the cookie and delete it when you are finished!