3.9.07

Code Snippets in Visual Studio 2005

Code snippet files are XML-files with "*.snippet" -extension. These files reside under C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033 for C# (for VB just replace VC# with VB).

There are two type of snippets; insert and surround with. Insert, as the name says, inserts desired code in the cursor location. In order to use Surround with, the appropriate code-section must be chosen. It surrounds the selected code with brackets, i.e. try{..} catch{Exception}.

There are two main ways to add a snippet in the code;
- From the menu "Edit - Intellisence - Insert Snippet" or with shortcut keys Ctrl + K (visual studio waits for second key combination) Ctrl + X
- From the menu "Edit - Intellisence - Surround with" or with shortcut keys Ctrl + K (visual studio waits for second key combination) Ctrl + S

For more snippets check this site.

14.8.07

Oracle Tracing SQL Scripts

With the following code, you can enable ouput in Oracle, in order to debug your SQL scripts;

SET SERVEROUTPUT ON
DBMS_OUTPUT.ENABLE(1000000);

Then you can debug your trigger, procedure or functions by adding the following line, wherever you need an output in your code;

...
DBMS_OUTPUT.PUT_LINE('A test string.. ' | | 'another string..');


[ | | means concatenating the strings]


When you need to measure how much time is consumed between steps of your code, following may help further;

v_time := dbms_utility.get_time;
...

DBMS_OUTPUT.PUT_LINE('Time used: ' | | (dbms_utility.get_time - v_time) / 100 | | ' secs');


whereas v_time declared as number in Oracle;

declare
v_time number;

13.8.07

Debugging Windows Services in C# and .NET with Visual Studio 2005

You cannot debug or run a service application by pressing F5 or F11; you cannot immediately run a service or step into its code. Instead, you must install and start your service, and then attach a debugger to the service's process as follows;
  1. Install your service and start the service.


  2. Open the project in Visual Studio 2005.


  3. Place your breakpoints at appropriate places in your code.


  4. Choose "Attach to process" from the Debug menu.


  5. From the available processes, look for the process created by your service. The process name will be same as the executable file of the service. (If not, choose both options "Show processes from all users" and "Show processes in all sessions")


  6. After clicking on "Attach" you should be able to debug your service application.


Microsoft Certified Professionals Worldwide

Have you ever wondered how many people around the world already hold a Microsoft Certification? Just check this site.

10.8.07

Debugging Oracle PL/SQL from Visual Studio 2005

The new, integrated PL/SQL debugger in ODT 10.2.0.2 allows you to remain inside of Visual Studio for end-to-end debugging of your .NET and Oracle solution. You can now debug PL/SQL code such as procedures and functions (both stand-alone and packaged), object methods, and triggers from within the Visual Studio environment in the same way as you would debug your C# or VB.NET code. With the ODT integrated PL/SQL debugger, you can use traditional debugging features such as setting break points, viewing and modifying variable values, and examining the call stack.
Check this site for more information and step-by-step tutorial.

Keyboard Shortcuts for Visual Studio 2005


Have ever wanted to go to the "Last position" in your huge code just like you do in Visual Basic 6 editor?

Just click CTRL + MINUS SIGN for backward navigation, and

click CTRL + SHIFT + MINUS SIGN for forward navigation.

For the whole list of keyboard shortcuts refer to Visual C# 2005 Keyboard Shortcut Reference Poster



IIS Error and Skype



I was trying to start my IIS server recently but it could not start because of an unknown error with some number.
I've seen an entry in eventvwr.msc and searched for that in internet:
I should check whether any other process on the system uses one of http-ports (80 and 443) or better close Skype.

And really, I closed Skype and IIS worked!

My recommendation would be to check the system with TCPView from SysInternals for these ports and close the appropriate process before starting the IIS-Server.

3.8.07

Who started the fire?

Great Video from TeacherTube;
We didn't start the fire...

13.3.07

Command-Line Tool osql for SQL-Server 2005

If there is no management tool on the system, from which you want to access a SQL-Server, osql-tool can be used from command-line like SQLPlus in Oracle. Each command must be ended with "go".

The basic connection command is as follows;

c:\>osql -U sa -S srv-sql\SQLSERVER2005

-S switch stands for server name (and instance, if applicable). The whole switches of osql are;

osql [-U login id] [-P password]
[-S server] [-H hostname]
[-E trusted connection]

[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w columnwidth]
[-a packetsize] [-e echo input]
[-I Enable Quoted Identifiers]

[-L list servers] [-c cmdend] [-D ODBC DSN name]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-n remove numbering] [-m errorlevel]
[-r msgs to stderr] [-V severitylevel]
[-i inputfile] [-o outputfile]
[-p print statistics] [-b On error batch abort]
[-X[1] disable commands [and exit with warning]]
[-O use Old ISQL behavior disables the following]
batch processing
Auto console width scaling
Wide messages
default errorlevel is -1 vs 1

Common Regular Expressions

Valid IP-Addresses: ^([\d]{1,3}\.){3}[\d]{1,3}

Valid Times (24 hours: ^([0|1|2]{1}\d):([0|1|2|3|4|5]{1}\d)

Valid Domainnames: ^(((\w+)|(\w+((-)+\w+)+))\.)+(\w+$)

Valid account names: ^([(\w+)|(\w+((\-|\.)+\w+)+)]+(\w+$))

Valid email adresses: ^(([(\w+)|(\w+((\-|\.)+\w+)+)]+(\w+))\@(((\w+)|(\w+((-)+\w+)+))\.)+(\w+$))

Valid int numbers: ^\d+$

21.2.07

OO-Basics and Patterns

Object-oriented programming is a programming paradigm that uses "objects" to design applications and computer programs.


  1. Abstraction: In object-oriented programming theory, abstraction is the facility to define objects that represent abstract "actors" that can perform work, report on and change their state, and "communicate" with other objects in the system.

  2. Encapsulation: The principle of information hiding is the hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. Protecting a design decision involves providing a stable interface which shields the remainder of the program from the implementation (the details that are most likely to change).

  3. Polymorphism: is the ability of objects belonging to different types to respond to function calls of methods of the same name, each one according to an appropriate type-specific behaviour. The programmer (and the program) does not have to know the exact type of the object in advance, so this behavior can be implemented at run time (this is called late binding or dynamic binding). Polymorphism allows client programs to be written based only on the abstract interfaces of the objects which will be manipulated (interface inheritance). This means that future extension in the form of new types of objects is easy, if the new objects conform to the original interface. In particular, with object-oriented polymorphism, the original client program does not even need to be recompiled (only relinked) in order to make use of new types exhibiting new (but interface-conformant) behaviour (many pieces of code being controlled by shared control code).

  4. Inheritance: is a way to form new classes (instances of which are called objects) using classes that have already been defined. The new classes, known as derived classes, take over (or inherit) attributes and behaviour of the pre-existing classes, which are referred to as base classes (or ancestor classes). It is intended to help reuse of existing code with little or no modification. The main advantage of inheritance is that modules with sufficiently similar interfaces can share a lot of code, reducing the complexity of the program. Inheritance is also sometimes called generalization, because the is-a relationships represent a hierarchy between classes of objects.


Patterns

Patterns shows you how to build systems with OO design qualities. Good OO-Designs are reusable, extensible and maintainable. Patterns are proven OO-experience and they give general solutions to design problems, which can be applied to any specific application (they don't give the code).


Strategy Pattern

Strategy Pattern defines a family of algorthms, encapsulates each one and makes them interchangeable. Strategy lets the algorithm vary independentyl from clients that use it. The strategy pattern is useful for situations where it is necessary to dynamically swap the algorithms used in an application. The strategy pattern is intended to provide a means to define a family of algorithms, encapsulate each one as an object, and make them interchangeable. The strategy pattern lets the algorithms vary independently from clients that use them. Each set of behaviour is thought as a family of algorithms, which are intercahngeable (algorithms can be selected on-the-fly at runtime).

The UML class diagram for the Strategy pattern is the same as the diagram for the Bridge pattern. However, these two design patterns aren't the same in their intent. While the Strategy pattern is meant for behavior, the Bridge pattern is meant for structure.

Observer Pattern

Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically. An example should be a newspaper subscription service with its publisher (i.e. Subject Object) and subscribers (i.e. Observers, one-to-many relationship). The Observer Pattern provides an object design where subjects and observers are loosely coupled, which means;



  • Changes to either the subject or an observer will not affect each other,

  • Subjects or observers can be used independently of each other,

  • Subject need not to be modified in order to add new types of observers,

  • New observers can be add any time,

  • The only thing the subject knows about an observer is: observer implements a certain interface.


8.2.07

Milliseconds in C#

If you want to see how long it takes executing a function in .Net (C#), you can use either Millisecond function or format a DateTime object with "f"-"ffffff" pattern.
using System;
using System.Collections;

public class MyClass
{
public static void Main()
{
DateTime start;
String format1;
format1
= "HH:mm:ss.fff";
start
= DateTime.Now;

WL(
"ToLongTimeString and Millisecond " +
DateTime.Now.ToLongTimeString()
+ "." +
DateTime.Now.Millisecond);

WL(
"");
WL(start.ToString(format1));
WL(String.Format(
"{0:D}", DateTime.Now));
RL();
}

+
#region Helper methods

}

7.2.07

Open and create a text file in VB

strInputFile = "c:\input.txt"
strOutputFile = "c:\output.txt"

intInputFileNr = FreeFile
Open strInputFile For Input As #intInputFileNr
intOutputFileNr = FreeFile
Open strOutputFile For Output As #intOutputFileNr

While Not EOF(intInputFileNr)
Line Input #intInputFileNr, strGetLine
If strGetLine <> "" Then
strGetLine = Mid(strGetLine, InStr(strGetLine, Chr(9)) + 1)
strGetSplitted = Split(strGetLine, ";")

For intLocIO = 0 To UBound(strGetSplitted)
strWriteOut = strDatenSatz & ";" & strGetSplitted(intLocIO)
Print #intOutputFileNr, strWriteOut
Next

End If
Wend
Close #intOutputFileNr
Close #intInputFileNr

Register DLL and OCX Files from Context-Menu

This adds the ability to Right-Click on a .dll- or .ocx-File
and get the Register / UnRegister options, which then registers using the "regsvr32.exe"-Program.

Copy and paste the following lines in your text-editor, save as "RegisterDLL.reg"-file and then run the file with double-click.


REGEDIT4

; .DLL files
[HKEY_CLASSES_ROOT\.dll]
"Content Type"="application/x-msdownload"
@="dllfile"
[HKEY_CLASSES_ROOT\dllfile]
@="Application Extension"
[HKEY_CLASSES_ROOT\dllfile\Shell\Register\command]
@="regsvr32.exe \"%1\""
[HKEY_CLASSES_ROOT\dllfile\Shell\UnRegister\command]
@="regsvr32.exe /u \"%1\""

; .OCX files
[HKEY_CLASSES_ROOT\.ocx]
@="ocxfile"
[HKEY_CLASSES_ROOT\ocxfile]
@="OCX"
[HKEY_CLASSES_ROOT\ocxfile\Shell\Register\command]
@="regsvr32.exe \"%1\""
[HKEY_CLASSES_ROOT\ocxfile\Shell\UnRegister\command]
@="regsvr32.exe /u \"%1\""

28.1.07

The Hubble Deep Field: The Most Important Image Ever Taken

In 2003, the Hubble Space Telescope took the image of a millenium. This is truly an amazing video. 
Here is more explanation.


26.1.07

Free Virtualizers (VMWare Alternatives)

InnoTek VirtualBox is a family of powerful x86 virtualization products. It is the only professional solution that is freely available as Open Source Software under the terms of the GNU Public License (GPL).

moka5's LivePC Engine LivePCs contain a complete PC software environment — operating system and applications — that users can create for themselves and share with others. LivePCs are played using the moka5 LivePC Engine™ and are created using tools inside the LivePC Engine. This is a portable virtual machine, which you can run from your USB-Stick!

Notepad Alternatives

Here are some Notepad alternatives, which you can also use without installation, i.e. compatible as portable application...

Note-X-Pad (Source-Code is also available)

Notepad++ (also as portable)

PSPad (PsPad does not require installation, wide range of languages)

Scite (A free source code editor for Win32)

Notepad2 (Yet another Notepad replacement)

NoteTab Light (A slimmer version of the award-winning NoteTab Pro)

Oracle SQL Developer is ready for free download

Oracle SQL Developer is a free graphical tool for database development. With SQL Developer, you can browse database objects, run SQL statements and SQL scripts, and edit and debug PL/SQL statements. You can access not only Oracle-DB, but also other SQL-vendors such as MySQL, MS SQL Server and MS Access.

Download here!

Creating a Delimited List from Table Rows in SQL Server 2005

DECLARE @rechtsfolgeList varchar(100)

SELECT @rechtsfolgeList =
COALESCE(@rechtsfolgeList + ', ', '') +
CAST(R.Recht_Code AS varchar(5))
FROM dbo.Rechtsfolgen R INNER JOIN
dbo.Verfahren_Rechtsfolge VR ON R.Code = VR.Ref_Rechtsfolge
WHERE VR.Ref_DKopf = 'BM-06-0346'

SELECT @rechtsfolgeList

 

Case-Sensitive SQL Searches

These are two possible coding examples for MS SQL-Server, to make a case-sensitive search.

You can either use CAST function, which is available fo SQL-Server down to MS SQL v7

SELECT * FROM TABLE_NAME WHERE CAST(mitarbeiterid AS varbinary(40)) = CAST('bbe' AS varbinary(40))

Or use the COLLATE function (available after MS SQL 2000) with an appropriate string pattern;

SELECT * FROM TABLE_NAME WHERE mitarbeiterid COLLATE Latin1_General_BIN LIKE '%[a-z]%'

Nvidia's GauGan App

NVIDIA's GauGAN AI Machine Learning Tool creates photorealistic images from Simple Hand Doodling http://nvidia-research-mingyuliu.com/...