Thursday, November 20, 2008

Dynamic Checkerboard Code

An interesting problem is to draw a dynamic checkerboard or chessboard with the constraints that the height and width of the board are variable along with the fact that the dimension of the individual squares themselves have variable defining their own height and width. The board must be drawn with a simple text output.

The following java solution is proposed


/*
* Create a function that can draw a checkerboard with boardwidth by boardlength where each square is squarewidth by squarelength.
* It is to be drawn with System.out.prints only.
*/
public class DrawCheckerBoard {

public static void drawCheckerBoard(int checkerBoardWidth, int checkerBoardHeight, int squareWidth, int squareHeight)
{
for (int i = 0 ; i < checkerBoardHeight ; i++)
{
for (int j = 0 ; j < squareHeight ; j++)
{
for(int k = 0 ; k < checkerBoardWidth ; k++)
{
//determine character to draw for square
//based on the which checkerboard spot (i and k indices)
String character = "X";
if ((i+k)%2==0)
{
character = "O";
}
for (int l = 0 ; l < squareWidth ; l++)
{
System.out.print(character);
}
}//end of line
System.out.println("");
}
}

}

public static void main(String[] args)
{

System.out.println("4 by 4 board with each square being 2 by 2");
drawCheckerBoard(4,4,2,2);

System.out.println("8 by 8 board with each square being 4 by 4");
drawCheckerBoard(8,8,4,4);

}

}

Monday, September 22, 2008

COBIT Powerpoint Presentation


I researched to find out what COBIT was by reading IT Governance Based on Cobit 4.1: A Management Guide (Paperback)
by Koen Brand and Harry Boonen.

COBIT is an IT Framework for Governance. It has similarities to ITIL and some overlap. One person told me that COBIT is what you build and ITIL is how you do it.

Anyways, I made a brief powerpoint presentation on COBIT which may be viewed from Here

Obviously very high level, but with pictures and some text, it will help.

Tuesday, September 9, 2008

Determining Leap Year in Oracle and Days in February

Recently, I was playing around with a leap year issue and the number of days in February. I would like to share the following snippets of commands to help some people save some time.

--2 ways to determine if it is a LEAP YEAR in ORACLE

SELECT 2008 , Decode( mod(2008, 4), 0, decode( mod(2008, 400), 0, 'Yes', decode( mod(2008, 100), 0, 'No', 'Yes') ), 'No' ) as LEAP_YEAR
FROM DUAL;

or

SELECT DECODE(29, (SELECT to_date('01032008', 'DDMMYYYY') - to_date('01022008', 'DDMMYYYY')FROM DUAL),'LEAPYEAR','NOTLEAPYEAR')
FROM DUAL;

--2 ways to determine the NUMBER OF DAYS IN FEBRUARY in ORACLE

SELECT (EXTRACT (DAY FROM LAST_DAY(ADD_MONTHS(TRUNC(TO_DATE('2008','YYYY'),'YYYY'),1))))
FROM DUAL;

or

SELECT to_date('01032008', 'DDMMYYYY') - to_date('01022008', 'DDMMYYYY')
FROM DUAL;



Of course the input to these queries requires the year that you are inquiring about.

Saturday, August 30, 2008

Powerpoint ITIL Presentation



I have recently done some research into ITIL including the reading of Foundations of IT Service Management Based on ITIL V3 by Jan Van Bon, Arjen de Jong, and Axel Kolthof.

ITIL is a very broad level topic about IT services and how to approach them.

I did make a brief high level powerpoint presentation on an Introduction to ITIL.

This presentation may be downloaded from Here

It is a basic high level presentation, it is difficult to present the topic without getting lost in the depth and breadth. This presentation just presents a little background and a little overview of the lifecycle phases in Version 3.

Wednesday, August 13, 2008

Service Oriented Architecture with Java



I recently read “Service Oriented Architecture with Java” by Binildas CA, Malhar Barai, and Vicenzo Caselli. This book, available at http://www.packtpub.com, provides a look at some of the tools in the java world that can be applied to support a Service Oriented Architecture.

There are 6 Chapters in all:

Chapter 1: The Mantra of SOA
This chapter reviews basic tiered architecture, EA and the basic points of benefit of SOA including better integration, business agility, asset re-use, increase ROI

Chapter 2: Web Services and SOA
Practically all current SOA implementations now are built upon web services. XML over the Http protocol is covered. Representational State Transfer(REST) is covered. Main java implementations of web services are introduced including JAX-WS 2, Axis2, Spring-WS, and XFire/CXF 2.0.

Chapter 3 : Web Service Implementations
Code is presented for getting a web service up and running in JAX-WS2, Axis2, Spring-WS, and XFire/CXF 2.0 The coded examples are very easy to follow and can get a developer up and running quickly.

Chapter 4: Data and Services – All Roads Lead to Enterprise Service Bus
This chapter reviews JDO(Java Data Objects) as an alternative to JDBC along with sample code and examples. Service Data Objects(SDO) are covered as a way to abstract data within and SOA. Apache Tuscany DSO is covered with an example. Service Component Architecture(SCA) is described along with a Tuscany SCA java example
Benefits of MOM and ESB are also covered. OpenESB is covered as an open source option for implementing an ESB.

Chapter 5 – Traditional Integration Technology
2 Case Studies are presented showing the advantages of an SOA based architecture over that of EAI.

Chapter 6 – Goals We Can Achieve with SOA
Loose Coupling, Reusability, Seamless Integration, Return on Investment(ROI)

All in all this is a pretty good book. It’s focus is definitely to provide information on a SOA implementation in a java oriented environment. This book covers the basics of the open source options to getting java based web services and infrastructure. I would strongly recommend this book to those trying to do open source SOA implementations in java.

Wednesday, July 16, 2008

Run .NET Code from a shared drive/directory

Security is an issue whenever running code from an untrusted source like a shared or network drive. It would be nice to be able to put an application on a share drive to run whether it be in C# or VB .NET.

Normally, when you try to run .NET code on a shared network drive you will get an exception like System.Security.Permissions.SecurityPermission .


There is a way to relax the security via the caspol.exe command(For .Net Framework 2.0 "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CasPol.exe -s off").

An application may be launched with one simple batch file as follows:

AllInOne.BAT:
@ECHO OFF

REM Relax security constraints for .NET
START C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CasPol.exe -s off

REM Pause until first command has executed
Set Count=1
:LOOP
Set /A Count=%Count%+1
If %Count% lss 100 GoTo :LOOP

REM Launch .NET application
"""SomeExecutable.exe"""

REM Remove relaxation of security constraints
TASKKILL /im CasPol.exe

@ECHO ON

*****************************

A pause is required to allow caspol to start up before launching the .NET application.

But of course this implementation does meet the requirements of launching the .NET application from the shared location but there are those DOS windows which are open and probably not that desirable.

These can be avoided with 2 BAT files and 2 VBS files as follows. This is just one way of doing it but there are probably better ways out there.

launch.bat (Main file)
****************
@ECHO OFF
REM Main Launch for .NET application on share drive
REM VBS script used so there is not a DOS console opened up

START launchtasks.vbs

@ECHO ON

****************

launchtasks.vbs
****************
On Error Resume Next

CmdLine = """tasks.bat"""
Params = ""
CmdLine = CmdLine & " " & Params

'Launch without window
wscript.echo fShellRun(CmdLine)

Function fShellRun(sCommandStringToExecute)
' This function will accept a string as a DOS command to execute.
' It will then execute the command in a shell, and capture the output into a file.
' That file is then read in and its contents are returned as the value the function returns.
Dim oShellObject, oFileSystemObject, sShellRndTmpFile
Dim oShellOutputFileToRead, iErr
Set oShellObject = CreateObject("Wscript.Shell")
Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")
sShellRndTmpFile = oShellObject.ExpandEnvironmentStrings("%temp%") & oFileSystemObject.GetTempName
On Error Resume Next
oShellObject.Run sCommandStringToExecute & " > " & sShellRndTmpFile, 0, True
iErr = Err.Number
On Error GoTo 0
If iErr <> 0 Then
fShellRun = ""
Exit Function
End If
fShellRun = oFileSystemObject.OpenTextFile(sShellRndTmpFile,1).ReadAll
oFileSystemObject.DeleteFile sShellRndTmpFile, True
End Function

****************

tasks.bat
****************
@ECHO OFF

REM Relax security constraints for .NET
REM Run this in VBS to avoid a DOS WINDOW
START caspol.vbs

REM Pause until first command has executed
Set Count=1
:LOOP
Set /A Count=%Count%+1
If %Count% lss 70 GoTo :LOOP

REM Launch .NET application
"""SomeExecutable.exe"""

REM Remove relaxation of security constraints (The >NUL is to avoid showing the info on the processes terminated)
TASKKILL /im CasPol.exe >NUL

@ECHO OFF

****************


caspol.vbs
****************
On Error Resume Next

'The command below will also depend on the .NET version of the application you are running

CmdLine = """C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CasPol.exe"""
Params = "-s off"
CmdLine = CmdLine & " " & Params

'New way without window
wscript.echo fShellRun(CmdLine)

Function fShellRun(sCommandStringToExecute)
' This function will accept a string as a DOS command to execute.
' It will then execute the command in a shell, and capture the output into a file.
' That file is then read in and its contents are returned as the value the function returns.
Dim oShellObject, oFileSystemObject, sShellRndTmpFile
Dim oShellOutputFileToRead, iErr
Set oShellObject = CreateObject("Wscript.Shell")
Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")
sShellRndTmpFile = oShellObject.ExpandEnvironmentStrings("%temp%") & oFileSystemObject.GetTempName
On Error Resume Next
oShellObject.Run sCommandStringToExecute & " > " & sShellRndTmpFile, 0, True
iErr = Err.Number
On Error GoTo 0
If iErr <> 0 Then
fShellRun = ""
Exit Function
End If
fShellRun = oFileSystemObject.OpenTextFile(sShellRndTmpFile,1).ReadAll
oFileSystemObject.DeleteFile sShellRndTmpFile, True
End Function

****************

Sunday, June 22, 2008

ITIL Introduction videos

It has been a while since I have blogged here. My goal is to research a little into ITIL (Information Technology Infrastructure Libary)

I read "Foundations of IT Service Management Based on ITIL V3" a few months back and am trying to group some materials on an introduction to ITIL.

Let me say that up front the ITIL processes and lifecycle is very high level and hard to grasp at an implementation detail. I guess the key is to focus on a small portion of it and grow it out from there.

I found a couple youtube links that I think are easy to listen to.

Synopsis of the ITIL(r) V3 Foundations class:



EMC on ITIL: