Friday, August 5, 2011

Infinity plus one

In popular cultureinfinity plus 1 is a phrase used in relation to the notion of infinity as the largest possible number. The idea is that no such number should exist. 


The phrase is sometimes found in children's culture by those who have discovered the concept of infinity. When one child makes a reference to infinity, another may try to best them by making a similar reference to infinity plus one. One example of this is when children come up with a dare, and subsequently return the dare, multiplied by increasingly higher values[citation needed], for example:

Child 1: "I dare you ..."
Child 2: "I double dare you."
Child 1: "I triple dare you."
Child 2: "I dare you times a million."
Child 1: "I dare you times infinity."
Child 2: "I dare you times infinity plus one."

Thursday, August 4, 2011

SQL Indexes


Index architecture

Index architectures can be classified as clustered or non-clustered.

[edit]Non-clustered

The data is present in random order, but the logical ordering is specified by the index. The data rows may be randomly spread throughout the table. The non-clustered index tree contains the index keys in sorted order, with the leaf level of the index containing the pointer to the page and the row number in the data page. In non-clustered index:
  • The physical order of the rows is not the same as the index order.
  • Typically created on column used in JOIN, WHERE, and ORDER BY clauses.
  • Good for tables whose values may be modified frequently.
Microsoft SQL Server creates non-clustered indices by default when CREATE INDEX command is given. There can be more than one non-clustered index on a database table. There can be as many as 249 nonclustered indexes per table in SQL Server 2005 and 999 nonclustered indexes per table in SQL Server 2008. It also creates a clustered index on a primary key by default.[1]

[edit]Clustered

Clustering alters the data block into a certain distinct order to match the index, resulting in the row data being stored in order. Therefore, only one clustered index can be created on a given database table. Clustered indices can greatly increase overall speed of retrieval, but usually only where the data is accessed sequentially in the same or reverse order of the clustered index, or when a range of items is selected.
Since the physical records are in this sort order on disk, the next row item in the sequence is immediately before or after the last one, and so fewer data block reads are required. The primary feature of a clustered index is therefore the ordering of the physical data rows in accordance with the index blocks that point to them. Some databases separate the data and index blocks into separate files, others put two completely different data blocks within the same physical file(s). Create an object where the physical order of rows is same as the index order of the rows and the bottom(leaf) level of clustered index contains the actual data rows.
They are known as "index organized tables" under Oracle database.

[edit]Cluster (Oracle)

In Oracle database, multiple tables can be joined into a cluster (not to be confused with clustered index described above). The records for the tables sharing the value of a cluster key shall be stored together in the same or nearby data blocks. This may improve the joins of these tables on the cluster key, since the matching records are stored together and less I/O is required to locate them[2]. The data layout in the tables which are parts of the cluster is defined by the cluster configuration. A cluster can be keyed with a B-Tree index or a hash table. The data block in which the table record will be stored is defined by the value of the cluster key.

Wednesday, August 3, 2011

C# int.Max and Min Constants


You need minimum and maximum values in your program, such as by using int.MaxValue andint.MinValue. Every integer or typed number in the C# language has a specific max value, but that number is different for int, uint, short, and ushort. Here we see the values of and examples for these constants.

Values

First, here we look at MSDN to see what Microsoft says. It states that MaxValue is a "public const int". With a bit of exploration, I found this information about the MaxValue and MinValue constants.

short.MaxValue32767

short.MinValue-32768

ushort.MaxValue65535

ushort.MinValue0

int.MaxValue2,147,483,647

int.MinValue-2,147,483,648

uint.MaxValue4,294,967,295

uint.MinValue0

long.MaxValue9,223,372,036,854,775,807

long.MinValue-9,223,372,036,854,775,808

double.MinValueReally small

double.MaxValueReally big
Numbers. The above fields are constants and can be accessed anywhere with the composite name. By using these constants, you can avoid typing out 10-digit numbers in your programs. However, they are not equivalent to infinity.

Example

Here we clarify the logic in loops. One problem I have dealt with is keeping track of the lowest number found. You can use int.MaxValue to start the value really high, and then any lower number will be valid.
Program that uses int.MaxValue [C#]

using System;

class Program
{
    static void Main()
    {
 int[] integerArray = new int[]
 {
     10000,
     600,
     1,
     5,
     7,
     3,
     1492
 };

 // This will track the lowest number found
 int lowestFound = int.MaxValue;

 foreach (int i in integerArray)
 {
     // By using int.MaxValue as the initial value,
     // this check will succeed (almost) always.
     if (lowestFound > i)
     {
  lowestFound = i;
  Console.WriteLine(lowestFound);
     }
 }
    }
}

Output
    (All values are lower than int.MaxValue)

10000
600
1

How to Add a Configuration File to your Windows Forms application


When you are creating a new Windows Forms application, it isn’t immediately obvious how to get a configuration file for your application. Your application configuration file is supposed to be called executablename.exe.config, and should be in the same directory as your application in order for the .NET framework to automatically use it.
But when you create the configuration file in the \bin\debug directory, it gets overwritten immediately when you do a new build. That’s slightly annoying.
The proper way to add this file is to add new new configuration file called App.config to your project, which Visual Studio will automatically copy and rename to the same name as your executable’s name when you do a build.
There’s a really simple way to do this.. simply go to the File \ Add New Item menu, or hit Ctrl+Shift+A
You’ll notice that it’s already set to App.config for you. Just hit the Open button.
If you look in the Solution Explorer, you will see that the config file is in your project:

Now build your application, and take a look in the \bin\debug\ folder. You’ll see that the configuration file has automatically been generated and named correctly for your executable:
If you change the name of the outputted file, Visual Studio is smart enough to generate the new filename correctly.


By default, the app.config file will have the following content:
xml version="1.0" encoding="utf-8" ?> 

<configuration> 

</configuration>
To store values in the configuration file, you can create XML elements in the format:
<add key="MyKey" value="MyValue" />

And to read from this config file, just use the following code in your application:
string dbPath = 
  System.Configuration.ConfigurationSettings.AppSettings["DatabasePath"];
string email = 
  System.Configuration.ConfigurationSettings.AppSettings["SupportEmail"];


Enjoy Configuring!

HTML - Map - Area tag - Usage

JS script function

writeText(txt) fn
document.getElementById("desc").innerHTML=txt;


img src ="planets.gif" width ="145" height ="126" alt="Planets" usemap="#planetmap"

map name="planetmap"
area shape ="rect" coords ="0,0,82,126"
onmouseover="writeText('The Sun and the gas giant planets like Jupiter are by far the largest objects in our Solar System.')"
href ="sun.htm" target ="_blank" alt="Sun"

area shape ="circle" coords ="90,58,3"
onmouseover="writeText('The planet Mercury is very difficult to study from the Earth because it is always so close to the Sun.')"
href ="mercur.htm" target ="_blank" alt="Mercury"

area shape ="circle" coords ="124,58,8"
onmouseover="writeText('Until the 1960s, Venus was often considered a twin sister to the Earth because Venus is the nearest planet to us, and because the two planets seem to share many characteristics.')"
href ="venus.htm" target ="_blank" alt="Venus"

map tag end

p id="desc"
Mouse over the sun and the planets and see the different descriptions.


JS onChange event

The onChnage event fires when the user leaves the control.

eg.

onchange select-box
It doesnt fires when you select a select-box en use the arrow keys to navigate through the options, it fires when you leave the selectbox.

JS String Object


String Object Properties

PropertyDescription
constructorReturns the function that created the String object's prototype
lengthReturns the length of a string
prototypeAllows you to add properties and methods to an object

String Object Methods

MethodDescription
charAt()Returns the character at the specified index
charCodeAt()Returns the Unicode of the character at the specified index
concat()Joins two or more strings, and returns a copy of the joined strings
fromCharCode()Converts Unicode values to characters
indexOf()Returns the position of the first found occurrence of a specified value in a string
lastIndexOf()Returns the position of the last found occurrence of a specified value in a string
match()Searches for a match between a regular expression and a string, and returns the matches
replace()Searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring
search()Searches for a match between a regular expression and a string, and returns the position of the match
slice()Extracts a part of a string and returns a new string
split()Splits a string into an array of substrings
substr()Extracts the characters from a string, beginning at a specified start position, and through the specified number of character
substring()Extracts the characters from a string, between two specified indices
toLowerCase()Converts a string to lowercase letters
toUpperCase()Converts a string to uppercase letters
valueOf()Returns the primitive value of a String object

String HTML Wrapper Methods

The HTML wrapper methods return the string wrapped inside the appropriate HTML tag.
MethodDescription
anchor()Creates an anchor
big()Displays a string using a big font
blink()Displays a blinking string
bold()Displays a string in bold
fixed()Displays a string using a fixed-pitch font
fontcolor()Displays a string using a specified color
fontsize()Displays a string using a specified size
italics()Displays a string in italic
link()Displays a string as a hyperlink
small()Displays a string using a small font
strike()Displays a string with a strikethrough
sub()Displays a string as subscript text
sup()Displays a string as superscript text