My shared items

 

Thursday, August 30, 2007

"Add To Favorites" Dialog in JavaScript

JavaScript to launch the browser Favorites window to bookmark the current page.

function bookmarkThisSite(url, bookmarkName)
{
if (sidebar)
{
sidebar.addPanel(bookmarkName, url,"");
}
else if( document.all )
{
external.AddFavorite(url, bookmarkName);
}
else if( window.opera && window.print )
{
return true;
}
else
{
return true;
}
}

The JavaScript Programming Language

Tuesday, August 28, 2007

How Do I Get Paths and URL fragments from the HttpRequest object?

Visit...

http://www.cambiaresearch.com/c4/dfdb20ae-b335-48ae-a201-f2a5a8329342/How-Do-I-Get-Paths-and-URL-fragments-from-the-HttpRequest-object.aspx

DLL Register And UnRegister in Mouse Context Menu


Normal Case:
For register DLL or OCX:
rundll32 yourdll.dll,DLLRegisterServer
rundll32 yourocx.ocx,DLLRegisterServer

For unregister DLL or OCX:
rundll32 yourdll.dll,DLLUnregisterServer
rundll32 yourocx.ocx,DLLUnregisterServer

For Mouse Context Menu:

If do you want make a "Right mouse-click" option, enter in the REGEDIT and make the options:

For DLL Register:

HKEY_CLASSES_ROOT\dllfile
Make a new key "Shell":

HKEY_CLASSES_ROOT\dllfile\shell
Make a new key "Register":

HKEY_CLASSES_ROOT\dllfile\shell\register
In the "Default" value, type: "DLL Register"
And make a new key "Command":

HKEY_CLASSES_ROOT\dllfile\shell\register\command
In the "Default" value, type:
rundll32.exe "%1",DllRegisterServer

For DLL Unregister:

HKEY_CLASSES_ROOT\dllfile
Make a new key "Shell":

HKEY_CLASSES_ROOT\dllfile\shell
Make a new key "Unregister":

HKEY_CLASSES_ROOT\dllfile\shell\unregister
In the "Default" value, type: "DLL Unregister"
And make a new key "Command":

HKEY_CLASSES_ROOT\dllfile\shell\unregister\command
In the "Default" value, type:
rundll32.exe "%1",DllUnregisterServer


For OCX Register:

HKEY_CLASSES_ROOT\ocxfile
Make a new key "Shell":

HKEY_CLASSES_ROOT\ocxfile\shell
Make a new key "Register":

HKEY_CLASSES_ROOT\ocxfile\shell\register
In the "Default" value, type: "OCX Register"
And make a new key "Command":

HKEY_CLASSES_ROOT\ocxfile\shell\register\command
In the "Default" value, type:
rundll32.exe "%1",DllRegisterServer

For OCX Unregister:

HKEY_CLASSES_ROOT\ocxlfile
Make a new key "Shell":

HKEY_CLASSES_ROOT\ocxfile\shell
Make a new key "Unregister":

HKEY_CLASSES_ROOT\ocxfile\shell\unregister
In the "Default" value, type: "OCX Unregister"
And make a new key "Command":

HKEY_CLASSES_ROOT\ocxfile\shell\unregister\command
In the "Default" value, type:
rundll32.exe "%1",DllUnregisterServer

Client-Side JavaScript Reference

Client-Side JavaScript Reference:

"Client-Side JavaScript Reference This book is a reference manual for the JavaScript language, including both core and client-side JavaScript for version 1.3. JavaScript is Netscape's cross-platform, object-based scripting language for client and server applications."

http://docs.sun.com/source/816-6408-10/contents.htm

Saturday, August 25, 2007

Delegates and Events in C# / .NET

Overview

All of us have been exposed to event driven programming of some sort or the other. C# adds on value to the often mentioned world of event driven programming by adding support through events and delegates. The emphasis of this article would be to identify what exactly happens when you add an event handler to your common UI controls. A simple simulation of what could possibly be going on behind the scenes when the AddOnClick or any similar event is added to the Button class will be explained. This will help you understand better the nature of event handling using multi cast delegates.

Delegates

A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.


Events

The Event model in C# finds its roots in the event programming model that is popular in asynchronous programming. The basic foundation behind this programming model is the idea of "publisher and subscribers." In this model, you have publishers who will do some logic and publish an "event." Publishers will then send out their event only to subscribers who have subscribed to receive the specific event.


More Information:

http://www.akadia.com/services/dotnet_delegates_and_events.html

Thursday, August 9, 2007

enum at C# Online.NET (CSharp-Online.NET)

enum at C# Online.NET (CSharp-Online.NET)

enum

The Basics

An enum is a value type with a set of related named constants often referred to as an enumerator list. They allow code to look a lot cleaner and easier to read by getting rid of "magic numbers", that is to say, they get rid of numbers which have a purpose within a module of code, but make the code harder to read. If a single number needs a definition to make it easier to read then use a constant as shown below.

public const int North = 0;

However, if more than one related number needs a definition, then use an enumeration.


Declaration

An enum is declared as follows:

[attributes] [modifiers] enum identifier [:base-type]
{
enumerator-list [,]
}

The attributes is optional and is used to hold additional declarative information.

The modifier is optional. The allowed modifiers are new, public, protected, internal and private.

The keyword enum must be followed by an identifier that names the enum.

The base-type of an enumeration may be one of the following; byte, sbyte, short, ushort, int, uint, long or ulong. If no base-type is declared, than the default of int is used.

The enumerator-list contains the identifiers which are separated by commas (optionally including a value assignment).

The first enumerator begins at zero by default and each enumerator following is increased by 1. This can be overridden so that each member of the enumerator-list contains its own unrelated value (see second example below). Two items in an enumeration can hold the same value, however, this will cause problems if you use an automated switch statement where all elements are added.


Example 1 – A simple enumeration

An application may need to work with directions. Instead of using four numbers to represent the major directions, an enumeration works better. The numbers then become irrespective as the directions are named.

enum Direction
{
North,
East,
South,
West
}


Example 2 – Number specific

Now consider the same enumeration, but with each direction holding the value clockwise that they are from North.

enum Direction
{
North = 0,
East = 90,
South = 180,
West = 270
}

We would use the enumeration in the same manner, but the values have different meanings.


Casting

To get the underlying value of an item in an enumerator-list, you need to have an explicit cast to convert it from the enum type to its integral type. The following code displays this and makes use of the enum in example 2.

static void Main(string[] args)
{
Console.WriteLine("-------------------------------");
Console.WriteLine("Direction Enum Members by Name:");
Console.WriteLine("-------------------------------");

// get a list of member names from Direction enum,
// figure out the numeric value, and display
foreach (string direction in Enum.GetNames(typeof(Direction)))
{
Console.WriteLine("Direction Member: {0}\n Value: {1}",
direction, (int)Enum.Parse(typeof(Direction), direction));
}
}

And here is the output

-------------------------------
Direction Enum Members by Name:
-------------------------------
Direction Member: North
Value: 0
Direction Member: East
Value: 90
Direction Member: South
Value: 180
Direction Member: West
Value: 270


Some useful methods

  • Enum.GetName - retrieves the name of the constant in the enumeration that has a specific value.
  • Enum.GetNames - retrieves an array of the names of the constants in the enumeration.
  • Enum.GetValues - retrieves an array of the values of the constants in the enumeration.
  • Enum.IsDefined - returns an indication whether a constant with a specified value exists in a specified enumeration.

MSDN references

Tuesday, August 7, 2007

RegExLib.com Regular Expression Cheat Sheet (.NET Framework)

RegExLib.com Regular Expression Cheat Sheet (.NET Framework): "RegExLib.com Regular Expression Cheat Sheet (.NET)"

RegExLib.com Regular Expression Cheat Sheet (.NET)

Metacharacters Defined
MCharDefinition
^Start of a string.
$End of a string.
.Any character (except \n newline)
|Alternation.
{...}Explicit quantifier notation.
[...]Explicit set of characters to match.
(...)Logical grouping of part of an expression.
*0 or more of previous expression.
+1 or more of previous expression.
?0 or 1 of previous expression; also forces minimal matching when an expression might match several strings within a search string.
\Preceding one of the above, it makes it a literal instead of a special character. Preceding a special matching character, see below.
Metacharacter Examples
PatternSample Matches
^abcabc, abcdefg, abc123, ...
abc$abc, endsinabc, 123abc, ...
a.cabc, aac, acc, adc, aec, ...
bill|tedted, bill
ab{2}cabbc
a[bB]cabc, aBc
(abc){2}abcabc
ab*cac, abc, abbc, abbbc, ...
ab+cabc, abbc, abbbc, ...
ab?cac, abc
a\sca c
Character Escapes http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconcharacterescapes.asp
Escaped CharDescription
ordinary charactersCharacters other than . $ ^ { [ ( | ) ] } * + ? \ match themselves.
\aMatches a bell (alarm) \u0007.
\bMatches a backspace \u0008 if in a []; otherwise matches a word boundary (between \w and \W characters).
\tMatches a tab \u0009.
\rMatches a carriage return \u000D.
\vMatches a vertical tab \u000B.
\fMatches a form feed \u000C.
\nMatches a new line \u000A.
\eMatches an escape \u001B.
\040Matches an ASCII character as octal (up to three digits); numbers with no leading zero are backreferences if they have only one digit or if they correspond to a capturing group number. (For more information, see Backreferences.) For example, the character \040 represents a space.
\x20Matches an ASCII character using hexadecimal representation (exactly two digits).
\cCMatches an ASCII control character; for example \cC is control-C.
\u0020Matches a Unicode character using a hexadecimal representation (exactly four digits).
\*When followed by a character that is not recognized as an escaped character, matches that character. For example, \* is the same as \x2A.
Character Classes http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconcharacterclasses.asp
Char ClassDescription
.Matches any character except \n. If modified by the Singleline option, a period character matches any character. For more information, see Regular Expression Options.
[aeiou]Matches any single character included in the specified set of characters.
[^aeiou]Matches any single character not in the specified set of characters.
[0-9a-fA-F]Use of a hyphen (–) allows specification of contiguous character ranges.
\p{name}Matches any character in the named character class specified by {name}. Supported names are Unicode groups and block ranges. For example, Ll, Nd, Z, IsGreek, IsBoxDrawing.
\P{name}Matches text not included in groups and block ranges specified in {name}.
\wMatches any word character. Equivalent to the Unicode character categories [\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}]. If ECMAScript-compliant behavior is specified with the ECMAScript option, \w is equivalent to [a-zA-Z_0-9].
\WMatches any nonword character. Equivalent to the Unicode categories [^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}]. If ECMAScript-compliant behavior is specified with the ECMAScript option, \W is equivalent to [^a-zA-Z_0-9].
\sMatches any white-space character. Equivalent to the Unicode character categories [\f\n\r\t\v\x85\p{Z}]. If ECMAScript-compliant behavior is specified with the ECMAScript option, \s is equivalent to [ \f\n\r\t\v].
\SMatches any non-white-space character. Equivalent to the Unicode character categories [^\f\n\r\t\v\x85\p{Z}]. If ECMAScript-compliant behavior is specified with the ECMAScript option, \S is equivalent to [^ \f\n\r\t\v].
\dMatches any decimal digit. Equivalent to \p{Nd} for Unicode and [0-9] for non-Unicode, ECMAScript behavior.
\DMatches any nondigit. Equivalent to \P{Nd} for Unicode and [^0-9] for non-Unicode, ECMAScript behavior.