Thursday, April 19, 2007

Windows: Nightly Defrag

It isn't that hard to set up a nightly defragmentation routine.

In Windows XP, go to Start Menu > Settings > Control Panel > Scheduled Tasks go through the wizard, selecting C:\Windows\System32\defrag.exe to run. At the end, in the advanced options make it run
C:\Windows\System32\defrag.exe c: -f
or D: or whatever your drive name is.

Microsoft provides documentation on the command line defrag:
defrag volume [-a] [-f][-v] [-?]
volume: The drive letter or a mount point of the volume to be defragmented
-a: Analyze only
-f: Forces defragmentation of the volume regardless of whether it needs to be defragmented or even if free space is low
-v: Verbose output
-?: Display the help text


source(s): http://support.microsoft.com/kb/283080

Wednesday, April 18, 2007

PHP: PHP 5 Deployment Error

I've written some code for PHP5, and deployed it to a production server and I saw an error that I'd never seen before.

PHP 5 Code:
<?php

class form
{
    public $name;
    public $fields;
}
?>


Error:
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in C:\x\y\page.php on line z


The problem is that PHP 4 has a different syntax for classes. The code above is PHP 5 valid, but not PHP 4. A valid version of its PHP 4 equivalent is this:

PHP 4 Code:
<?php

class form
{
    var $name;
    var $fields;
}
?>

Tuesday, April 10, 2007

WINDOWS: Skip 'Open With Web Service' Window

When you try to open a file and you haven't set a handler for a file extension, a window pops up in XP saying:

"Windows cannot open this file:"
To open this file, Windows needs to know what program created it. Windows can go online to look it up automatically, or you can manually select from a list of programs on your computer.
What do you want to do?
- Use the Web service to find the appropriate program
- Select the program from a list


This is really irritating because no one would ever want to use 'the Web Service' anyway. BTW Microsoft, look up Web Service at wikipedia.

To skip that step, make a file with the following contents, and open it and the registry setting will be automatically imported into your system.

skipOpenWithWebService.reg
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
"InternetOpenWith"=dword:00000000


source(s): http://www.pctools.com/guides/registry/detail/1314/

Monday, April 09, 2007

C++: Associative Arrays

#include <map>
#include <string>


using namespace std;

int main()
{
std::map<std::string, std::string> m;
m["ENG"] = "English";
m["FRA"] = "France";
m["CAN"] = "Canada";
m["AUS"] = "Australia";

//does print empty string
cout<<m["Germany"]<<endl;

//iterate through all elements of array
std::map<string, string>::iterator curr,end;
for( curr = m.begin(), end = m.end(); curr != end; curr++ )
cout << curr->first + " = " + curr->second << endl;
return 0;
}


C++ maps or associative arrays are implemented as self-balancing binary search tree. This means that when you iterate through your map it will not be in the order you added them like in PHP but instead will be in sorted order.

source(s):
http://www.webmasterworld.com/html/3249762.htm

Sunday, April 08, 2007

HTML: Website blank in IE, fine in Firefox

I coded up a website in firefox but it wouldn't show in IE. I was trying to make it xHTML-ish, and had the script tag looking like this:

<script language='JavaScript' type='text/JavaScript' 
src='script.js'/>


For some idiot reason, IE chokes on the whole page, unless it looks like this:

<script language='JavaScript' type='text/JavaScript' 
src='script.js'></script>


source:
http://www.webmasterworld.com/html/3249762.htm

Tuesday, April 03, 2007

LINUX : C++ Hello World Compile Errors

A simple hello world using cout and string yields this.

main.cpp
#include <string>
#include <iostream>

using namespace std;

int main ( int argc, int argv[] )
{
cout << "running....\n";

cout<<"finished"<<endl;
return 0;
}


compile.sh
#compile
CFG=/usr/bin/mysql_config
sh -c "gcc -o mysqltest `$CFG --cflags` main.cpp `$CFG --libs`"


errors
abc@localhost:~/Projects/mysqltest> ./compile.sh
/tmp/ccpF755X.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccpF755X.o: In function `__tcf_0':
main.cpp:(.text+0x66): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccpF755X.o: In function `main':
main.cpp:(.text+0x81): undefined reference to `std::cout'
main.cpp:(.text+0x86): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
main.cpp:(.text+0x90): undefined reference to `std::cout'
main.cpp:(.text+0x95): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
main.cpp:(.text+0x9d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main.cpp:(.text+0xa2): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccpF755X.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'


The problem is that I was compiling with gcc instead of g++

Monday, April 02, 2007

LINUX: Weird characters when you compile

Why are there weird characters when I compile:

test.cpp: In function âint main()â:
test.cpp:7: error: âcoutâ was not declared in this scope
test.cpp:7: error: âendlâ was not declared in this scope


It's normal if you don't set the environment variable e.g.
export LANG=C


source(s):
http://gcc.gnu.org/ml/gcc-help/2006-08/msg00179.html