2008-08-30

NetBeans 'Main Project' Configuration Hack

I had an old folder of C++ exercises, containing a Makefile and some source files. Each source file would compile to one executable. I imported that folder into NetBeans then wondered how to run and debug each executable as a different 'Main Project'. After some twiddling, the solution (hack?) is to define different configurations for the project, one for each executable.

  1. Select your project's context menu item Set Configuration / Manage Configurations….
  2. In the Project Properties dialog, press the Manage Configurations button (I know that's rather confusing).
  3. In the Configurations dialog, create a new configuration with the target executable file name.
  4. Press the OK button to close the Configurations dialog.
  5. In the Project Properties dialog, select the Categories / Build / Make node.
  6. Select your configuration from the Configuration: drop down list. Note that you have to select any node other than General otherwise the Configuration: drop down list is disabled.
  7. In the Makefile panel:
    • Working Directory = . (current directory)
    • Build Command = ${MAKE} -f Makefile <file.exe>
    • Clean Command = ${MAKE} -f Makefile clean
    • Build Result = <file.exe>
  8. Press the OK button

Now, to run or debug a different executable, I just change the project's Active Configuration.

2008-08-27

What's the time?

14 quick ways to find the current time on your computer.

Cmd.exe has two built-in commands for the date and time. You have to add the /t option when calling these commands otherwise you are prompted to set the system time:

> date /t
Wed 27/08/2008
> time /t
07:42 PM

GnuWin's date command prints the date, time and time zone:

> date
Wed Aug 27 19:43:23 AUS Eastern Standard Time 2008

You can use the POSIX module in Perl to get the current date and time:

> perl -e "use POSIX; print asctime(localtime());"
Wed Aug 27 19:44:21 2008

Python has a time module similar to Perl's:

> python -c "import time; print time.asctime()"
Wed Aug 27 19:48:07 2008

PHP's time and date functions return an array, which you can dump using the print_r() function:

> php -r "print_r(get_date());"
Array
(
    [seconds] => 49
    [minutes] => 34
    [hours] => 14
    [mday] => 30
    [wday] => 6
    [mon] => 8
    [year] => 2008
    [yday] => 242
    [weekday] => Saturday
    [month] => August
    [0] => 1220070889
)

Ruby has a Time class:

> ruby -e "print Time.now"
Wed Aug 27 19:45:32 +1000 2008

PowerShell has a get-date cmdlet:

> get-date
Wednesday, 27 August 2008 7:50:13 PM

Or use the .Net System.DateTime.Now property in PowerShell:

> [System.DateTime]::Now
Thursday, 28 August 2008 9:53:21 AM

Firefox can tell you the time using the Javascript Date() object. Enter the following statement in your browser's address bar:

javascript:Date()
Wed Aug 27 2008 20:11:27 GMT+1000 (AUS Eastern Standard Time)

MSIE6 has a similar object but the output is different from Firefox's:

javascript:Date()
Thu Aug 28 10:06:59 2008

Groovy (and Java) has a java.util.Date object which defaults to the current time:

new java.util.Date()
Result: Thu Aug 28 09:58:45 EST 2008

2008-08-24

MinGW and Gdb in NetBeans

I configured NetBeans to use MinGW (Minimalist GNU for Windows), but when trying to debug an old C++ program, NetBeans kept displaying this error message: Gdb could not load your program. Terminating debug session. The version of gdb matched the MinGW distribution, so that wasn't the problem. After the usual bit of head-scratching, I ran gdb in a console and got this message: Reading symbols from <file>...(no debugging symbols found)...done. I manually compiled the source using g++ and found that my program was 3 times bigger than the NetBeans compiled version. So, the source of the problem is in the Makefile.

It turned out that when I imported my project into NetBeans, I forgot that my Makefile had this rule: $(CXX) -Wall -ggdb -s. The command-line option -s told the linker to strip all symbols, so gdb couldn't debug my program. Duh.

2008-08-15

Firefox Unexpectedly Popular

Falls in the use of older versions of MSIE are always offset by rises in use of newer versions and some rise in the use for other browsers. The July 08 browser statistics for W3 Schools show that the use of all versions of MSIE fell 2.0% while use of Firefox rose 1.6% (and Opera gains 0.2%). Has the use of MSIE7 peaked? (Insert usual caveats about selective audience of this site, monthly fluctuations, rounding errors, yada yada.)