Tuesday, December 19, 2006

Unix : Exporting a schema / stored procedure packages

Often you need to update the stored procedure packages for a schema.

So you laboriously export them via DDL and pretty them up and then run them on the target schema and then commit them.

Sometimes it's just easier to export the schema as an Oracle dump (which includes all the related stored procedures) and then import them on the target schema.

An example of the export command is:

exp login/password@schema file=target file directory/export name.dmp

Enjoy!

Friday, November 10, 2006

Unix : Libraries in an executable

A useful command to do this is:

ldd executable name

This will list out all the libraries required by that executable.

Enjoy!

Monday, November 06, 2006

Misc : Folder / file comparisons with hard drive and FTP

I frequently have problems comparing folders on my PC with folders on a machine that is accessible mainly by FTP.

An excellent tool for this is Beyond Compare which allows all combinations of local driver and FTP including FTP to FTP.

Also allows custom compares so you could create a preprocessor to do some manipulation before the actual compare.

A massive time saver.

Enjoy!

Misc : Formatting code in your blog

One possible solution is to use the

==blockquote==/blockquote==

construct

e.g.

void method (int a)
{
==blockquote==


int b = a * a;


==/blockquote==
}

where the "==" stands for the angled brackets.

Enjoy!

Friday, October 20, 2006

Misc : 100 posts

Bingo!

Finally hit the magic number.

Enjoy!

Unix : Finding files that start with a .

The classic "ls -l" doesn't show you any files that start with . (which is legal) (e.g. .param) and which are effectively hidden.

You need "ls -al" to ferret out these elusive beasts.

Enjoy!

SQL : Comparing VSS stored procedures with the DB

This is a right royal pain. You have to extract every .pkg and .pkb manually e.g. if using SQL Navigator you right click, Extract DDL and save.

But how do you ensure that VSS is up-to-date?

An easy way is to right click on the heading e.g. right click on Package Bodies and then Extract DDL from here. What you are doing is creating one DDL file that contains ALL the package stored procedures.

In VSS, however, each package is stored individually. To combine them, DOS comes to the rescue! Use the copy construct "+".

e.g. copy a + b + c d.

This concatenates a, b and c and puts them in a file called d.

Now you can compare the combined DDL extract with the concatenated file from VSS.

But wait, there's more!

Part of the DDL extract puts the date on the extract and the tnsname that you use to access the DB. Different developers may have different tns names. So you need to remove these lines. This can be done very simply by writing a program to parse the file and create a new one without these lines.

e.g. in C#, something like:

(where the command line is something like 'Program 'input file' 'filtered file'')

static void Main(string[] args)
{


string readBuffer = "";
int gIndex = 0;
int fIndex = 0;

if (args.Length != 2)
{


Console.WriteLine ("\nFormat is Prog 'input' 'output'");
System.Environment.Exit (0);


}

try
{


FileStream readStream = new FileStream (args[0], FileMode.Open);
StreamReader fileRead = new StreamReader (readStream);
FileStream writeStream = new FileStream (args[1], FileMode.Create);
StreamWriter fileWrite = new StreamWriter(writeStream);

while (fileRead.Peek () >= 0)
{


readBuffer = fileRead.ReadLine();

gIndex = readBuffer.IndexOf ("-- Generated");

if (gIndex == -1)
{


string tempReadBuffer = readBuffer.ToLower();
fIndex = tempReadBuffer.IndexOf ("-- from 'a specific DB string'");

if (fIndex == -1)
fileWrite.WriteLine (readBuffer);


}

}

fileRead.Close ();
fileWrite.Flush ();
fileWrite.Close ();


}

catch (Exception e)
{


Console.WriteLine("Error : {0}", e.ToString());


}


}

So the batch file would be:

copy concatenate statement
run filter on concatenated file
run filter on saved DDL file
compare the two filtered files

You could use something like Examdiff which is free to do the compare in which case the batch file line would be:

start ExamDiff.exe File1 File2

Enjoy!

Tuesday, October 17, 2006

Visual Studio : Errors in the output

Quite often when you are doing a build of a large project, the build will fail when some VS utility returns an error. The problem is that you can't see why it fails.

A useful technique is to use the VS command prompt (Start - Programs - VS 2005 - VS 2005 Tools) and cut and paste the command line that failed from the VS output window.

Then execute it - you'll see all the errors.

The other option is to select Tools - Options - Projects and Solutions - Build and Run and change the build output verbosity to "Detailed" or "Diagnostic". Just change it back afterwards or you'll be swamped!

Enjoy!

Tuesday, September 12, 2006

Misc : Vital links

Reading List: Fog Creek Software Management Training Program here

"A combination of the best business books of all time / the best software management books of all time / every worthwhile history of a software/computer company that Joel can find."

Joel's Programmer's Bookshelf here

"This is the short list of all the books that Joel thinks that every working programmer needs to read."

Ten Must-Have Tools Every Developer Should Download Now Enjoy! here

James Avery introduces you to some of the best free tools available today that target .NET development with Visual Studio.

Visual Studio Add-Ins Every Developer Should Download Now here

James Avery creates a list of must-have tools, but this time focusing on Visual Studio add-ins as opposed to standalone tools.

Enjoy!

Wednesday, August 30, 2006

Visual Studio : The application domain in which the thread was running has been unloaded.

Upgraded to Visual Studio 2005. With a large project, I kept getting this error when building. No clues as to what was wrong or how to fix it.

Googled the message but little joy. Eventually found a link that suggested that virtual memory was the problem so changed my XP virtual memory.

Path is Control Panel / System / Advanced / Performance / Settings / Advanced / Virtual memory and selected "System managed size".

Seems to have fixed the problem.

Enjoy!

Monday, August 14, 2006

C# : Visual Studio Express

If you want to take the first steps to getting familiar with C# and Visual Studio, check out these Visual Studio Express downloads.

There is one for:

Web developer
SQL
Visual Basic
Visual C#
Visual C++
Visual J#
MSDN Express Library (optional)

And best of all, they are FREE.

Thursday, August 10, 2006

C# : NUnit - integrating with Visual Studio

There are a number of ways of doing this but one of the simplest is to go to the NUnit site, click on "Documentation" then "Current Release" then "Features" then "Visual Studio Support" e.g. something like
this.

Add a custom tool entry specifying the path as described and then run nunit-gui.exe by clicking the NUnit entry which will now be under the "Tools" menu.

If you want to debug using NUnit, the procedure is also described here. Essentially, you first set the breakpoint, run an instance of NUnit as described above and then you click "Tools / Attach to Process" and then select the nunit-gui.exe line in the dropdown. Then re-run NUnit by clicking the "Run" button.

C# : NUnit

NUnit is a very powerful way of testing using extreme programming. Check out:

NUnit

The simple sample isn't all that clear. If you wanted to test a method Return0 in a class called CSharp1 which looked like:

public int Return0 ()
{

return 0;

}

use the following in CSharp1Test:

[Test]
public void CheckReturn()
{

CSharp1 cs = new CSharp1 ();

int ret = cs.Return0();

Assert.AreEqual(0, ret, "Should return 0");

}

Monday, July 03, 2006

Unix : List symbols from object files

Often when adding a method to a shared library, the method can't be found when accessed from another program. You start to wonder whether you made a mistake and whether the new method was indeed added. A simple way to check is to use the "nm" command e.g.

nm libraryname.sl

This lists all the symbols so best to do something like:

nm libraryname.sl | grep nameofmethod

Enjoy!

Unix : Sorting directory by date (ls -ltr)

Almost everyone knows the

ls -l

command to display information about the contents of a directory. Sometimes you need to display it in date order so

ls -lt

To display in ascending date order (i.e. most recent last)

ls -ltr

Enjoy!

Monday, May 29, 2006

C - Premature end-of-file (EOF)

So there I was writing a C program on Windows to change some fields in a binary file and copy the rest over as is. The problem was that the output file was always smaller than the input file? A little research showed that the problem was a 0x1A in the file. This is interpreted as an EOF.

Aside: This dates from MS-DOS days. The ASCII character 0x1A or 26 decimal (the "SUB") character was used as the end of file marker for text files. This mode also translates "\r\n" to "\n" for reading and translates "\n" to "\r\n" for writing.

The solution is to read and write the file as binary i.e.

fopen ("File", "rb") or fopen ("File", "wb") where the "b" indicates binary.

Enjoy!

Thursday, May 25, 2006

Unix : bdf - free disc space

To see a report of free disc space, the "df" command is the UNIX standard. However, for HP-UX use "bdf". It's more useful.

Enjoy!

Monday, May 08, 2006

Unix : httpget

Very useful utility to check if a server can access URL's programmatically i.e. without using standard IE browser port 80. Useful if you think firewalls, proxies etc. will get in the way.

Usage : httpget http://www.testsite.com

Enjoy!

Monday, May 01, 2006

Unix : Find a list of files and compile them

Very easy way to find a list of files in a directory and compile them all via a shell script without having to manually find and compile each one:

for i in $(ls *.c); do

compile $i

done

This looks for a list of C files and then compiles them. You need to substitute the actual name of your compiler for the "compile" part of the script.

Enjoy!

Friday, April 28, 2006

Unix : Find files modified within a certain time period

So there I was trying to find where this application stored its @#$% log file.

Eventually had a brainwave and decided to search for all files recently modified.

A quick Google bought up the Find command:

Find / -mtime [+|-] value

The "+" or "-" indicates before or after e.g.

-4 indicates all files modified within the last 4 days

+4 indicates all files modified more than 4 days ago

4 indicates all files modified 4 days ago only

0 indicates all files modified in the last 24 hours.

Enjoy!

Monday, April 03, 2006

Misc : Multiple IDE's

I rarely have less than 3 open at any one time covering a range of languages:

Java , C, C++ , C#, Cobol ...

What's really confusing is when you write a correct statement in the wrong language

e.g. in the Cobol IDE, I wrote:

Temp = 1;

and then you wonder why the compiler complained!

If you don't have your orientation correct, it's a puzzle because it *looks* correct. The moment you realise you are in the Cobol IDE, the penny drops.

The correct statement is of course:

Move 1 to Temp.

Enjoy!

Friday, March 17, 2006

Misc : FTP from a browser

Most people know that you can FTP from a browser via the

ftp://

mechanism.

What most people don't realise is that you can also include the logon and password. The format is:

ftp://logon:password@site

e.g. ftp://user1:pass1@111.24.12.6

You can also set an initial directory

e.g. ftp://user1:pass1@111.24.12.6/dir1/dir2

provided that the user has the rights to access that directory.

Enjoy!

Wednesday, March 15, 2006

.NET : Converting two ASCII bytes to one hex byte

One of the big disadvantages of tools like Visual Studio is that they hide the underlying machine operations from the user. As a result, most developers haven't a clue about hex , bit shifting etc. To those oldies who started in the assembler / DOS era, hex manipulation is something they ate / slept and breathed.

Quickly, what's 0x7e in decimal?

Waaay to slow. The answer is 126. (7 x 16) + 14.

So I'm sitting with a whole bunch of "wunderkinden" (who think they know everything)
and not one of them could figure out how to "un URL encode" in C#

i.e. convert %7F (three ASCII bytes) to 1 hex byte (0x7F).

Here's one way:

String urlEncode = "%7F";

String hString = "0123456789ABCDEF";

String sHighVal = urlEncode.Substring (1,1);
String sLowVal = urlEncode.Substring (2,1);

int iHighVal = hString.IndexOf (sHighVal);
int iLowVal = hString.IndexOf (sLowVal);

iHighVal = iHighVal << 4;

int result = iHighVal | iLowVal;

Enjoy!

Thursday, March 09, 2006

Cobol : Conditional compile

This may apply only to Micro Focus.

Define a 78 level in Working Storage.

78 functionality value "yes".

Then use the $if .. $else .. $end construct,

$if functionality defined
* Conditional code xxx here.
$end

With this setup, xxx will be compiled. Now here's the trick. You would then expect that setting "functionality" to "no" would stop xxx from being compiled but no way!

You need to comment out the 78 line to achieve this.

You can also achieve this from the command line:

cob -C 'constant functionality "yes"' yyy.cbl

(Pay special attention to the use of ' and ").

Enjoy!

Tuesday, March 07, 2006

Cobol : Trimming a field

Cobol doesn't support a trim function but you can get by by using:

WORKING-STORAGE SECTION.

01 InputString Pic X(20).

01 TrimString Pic X(20).

01 TrimCount Pic 9(2).

PROCEDURE DIVISION.


move 'poiuytrewq ' to InputString

move zero to TrimCount
inspect function reverse (InputString) tallying TrimCount for leading space
compute TrimCount = (length of InputString) - TrimCount
move InputString (1:TrimCount) to TrimString


Enjoy!

Friday, February 24, 2006

Cobol : Net Express IDE comments

Ever noticed how the comments display as actual commands even though you have an "*" in column 7 and you chose a special colour for the comments under "Options / Customize IDE / Colors" ?

The solution is to go to "Options / Edit" and set the left margin to 7.

Now you have comments that actually look like comments!

Enjoy!

Friday, February 17, 2006

Cobol : Conditional compile / debug

DISPLAY messages are often useful in a development system but you most certainly don't want them in a production environment.

You can do this by setting a "D" in column 7. From the manual:

"A debugging line is any line with a "D" in column 7. It is only permitted in the program after the OBJECT-COMPUTER paragraph.

A debugging line will be considered to have all the characteristics of a comment line if the WITH DEBUGGING MODE clause is not specified in the SOURCE-COMPUTER paragraph."

e.g. SOURCE-COMPUTER. MainFrame WITH DEBUGGING MODE.

Enjoy!

Cobol : Creating a logging file for standard out and standard error

Often you want to send a log file to stdout so you can then redirect it to wherever.

In Cobol, you can use:

SELECT OUTPUT-LOG ASSIGN ':CO:'

where:

:CO: is standard output (stdout)

These can also be used:

:CI: is standard input (stdin)

and

:CE: is standard error (stderr)

Enjoy!

SOAP : TCPMON - trace SOAP messages

This can also be done with Ethereal but that requires some TCP/IP knowledge.

Download tcpmon.jar from here

and run as:

java -jar tcpmon.jar

This will bring up the screen with:

Local Port: 8080
Server Name: 127.0.0.1
Server Port: 80

Assume that the web service address that the client uses is

http://a.b.c.d:9090

Change this in the client to

http://localhost:8080

Then change the Server Name to a.b.c.d and change the Server Port to 9090.

Then "Add Monitor"

So now your client will send to port 8080 and tcpmon will pick this up and redirect to a.b.c.d:9090 thus trapping the messages and then displaying them

Enjoy!

Friday, January 27, 2006

VS : Looking at the SOAP proxy code

So you are writing a web client with Visual Studio (assume command line) and you need to add a web reference.

Solution Explorer - right click References - Add Web Reference.

Point to the WSDL - GO and it's done.

What's done? - where's the generated code?

Open File - navigate to Web References / WebReference / Reference.cs.

This will show the SOAP methods and signatures you can call.

It will start with "public class X".

So use:

X x = new X ();
and the SOAP call will be x.method.

(Hint - when compiling add a "using" to your main class and check the namespace of the generated code.)

The line "this.Url = "http://a.b.c.e"; " is useful. Change this url if you move your web service.

Enjoy.