2008-03-19

Poor Man's Which Command For Windows Cmd.exe

The Windows Command Processor (cmd.exe) doesn't seem to have an equivalent to a Unix shell's which command to find the directory in the PATH variable of a given executable. Here's a poor man's version using the for command:

>for /F %i in ("notepad.exe") do @echo %~$PATH:i
C:\WINDOWS\system32\notepad.exe
>for /F %i in ("gawk.exe") do @echo %~$PATH:i
C:\Program Files\GnuWin32\bin\gawk.exe

20-Mar-2008: Added as a macro using doskey:

>doskey which=for %i in ("$1") do @echo %~$PATH:i

2008-03-15

Making ID Photos with GIMP

You can make ID photos cheaply using GIMP:

  1. Take a head-and-shoulders picture with your digital camera.
  2. Load or paste the image into GIMP.
  3. Rotate the image, if necessary, to a portrait orientation using menu item Image / Transform / Rotate 90 ….
  4. Shrink the image to one quarter the original size using menu item Image / Scale Image. You have to calculate the required pixel size because the Scale Image doesn't have a "shrink by half" function.
  5. Create a new image with the dimensions of the original image, in landscape orientation.
  6. Select menu item Image / Configure Grid and set the spacing so that it matches the size of your shrunk image. The idea is to have a grid as per ASCII art below:
    +--+--+--+--+
    |  |  |  |  |
    +--+--+--+--+
    |  |  |  |  |
    +--+--+--+--+
    
  7. Select menu item View / Snap to Grid and View / Show Grid.
  8. Copy and paste your shrunk image into the new image. You should be able to fit 8 images in one picture. Use the grid to help you position the images in each cell. Positioning all images in the grid's cells also makes it easier to cut the photos after they have been printed.

My camera takes 3072 x 2304 pixel images (or 6:4.5 ratio), so if I use 15cm x 10cm (6:4 ratio) paper, the images on the left and right edges would be cropped unless I further shrink the images by 5%.

2008-03-11

How to Extend Image with GIMP

If you have an image with a plain background that is too short or narrow, here's how you can extend it using GIMP 2.x. Note that extending an image is not the same as stretching an image using a transformation; important elements in the image are not distorted, just moved (see ASCII art below).

+----+     +------+
|A  B| ==> |A    B|
+----+     +------+
  1. Open the image file.
  2. Select menu item Image / Canvas.
  3. In Set Image Canvas Size dialog, uncheck the link between Width and Height, enter the required dimensions, then press the Resize button.
  4. Select menu item Layer / Layer to Image Size. You have to extend the background layer because you cannot see any part of the image beyond the background layer's boundaries.
  5. Use Rectangle Select Tool, select area to move, then copy selection to clipboard.
  6. Paste selection into image (which creates a Floating Selection in the Layers dialog).
  7. Move the selection to the required position in the layer. If you want to precisely place the selection, you should zoom in and use the cursor keys.
  8. When you are satisfied with the position of the selection, use Layer / Anchor Layer to put it back into the background layer.
  9. Use the Color Picker Tool to select a colour, then use a Pencil Tool or Paintbrush Tool to touch up the background.

Note that you can only move the selection after you have created a Floating Selection, which confused me initially because I thought that just copying a selection would give me an object to move.

2008-02-29

Microsoft Access Export Truncates Numbers

Introduction

I wanted to export all tables from an Access database into a folder of CSV formatted text files. For most data types, such as Text or Integer, all data was exported without any loss. However, floating point numbers (Float or Double) were exported with only two decimal places.

Approach

You can export a Microsoft Access table to a text file using either the menu item File / Export or this Access SQL statement from KB208408

SELECT * INTO [Text;FMT=Delimited;HDR=Yes;Database=<Path>].[<Table>.csv] FROM <Table>

Solutions

Here's three solutions with varying advantages:

  • KB153364 article suggests formatting the number column to define the required decimal places. This solution requires writing a SQL statement for each table you're exporting.
  • You can add a schema.ini into the destination export folder and specify the number of decimal places for all floating point numbers in a table using the NumberDigits keyword. This solution requires creating or copying a schema.ini file into the export directory before exporting the tables.
  • You can change the No. of digits after decimal in your Regional and Language Options of your computer. This solution means you or your user has to remember to the change that setting on their computer before exporting the tables.

About Schema.ini File

A slight digression: schema.ini is a file used by the Text Driver to determine the characteristics of tables and columns of a database. You can find the syntax and properties of the schema.ini file in Schema.ini File (Text File Driver).

When exporting tables, Access creates a schema.ini file in the export folder if that file does not exist. If there is an existing schema.ini file and the section for the output CSV file does not exist, Access will add a new section for the output CSV file. Otherwise, Access does not change the schema.ini file.

Conclusion

None of the solutions are very satisfactory for writing a general program to export tables from an Access database into a folder of text files. The simplest solution is to define the required number of decimal places in the database connection string (the part between the square brackets in the SQL statement). However, I couldn't find any formal specification of this string on the Web.