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!