Saturday, October 20, 2012

Pure

1. While

2. Do..While

3. For (,While,)

Thursday, October 18, 2012

Version of IIS


VersionObtained fromOperating System
1.0Included with Windows NT 3.51 SP 3 (or as a self-contained download).Windows NT Server 3.51
2.0Included with Windows NT Server 4.0.Windows NT Server 4.0
3.0Included with Windows NT Server 4.0 Service Pack 3 (Internet Information Server 2.0 is automatically upgraded to Internet Information Server 3.0 during the install of SP3).Windows NT Server 4.0
4.0Self-contained download from www.microsoft.com or the Windows NT Option Pack compact disc.Windows NT Server 4.0 SP3 and Microsoft Internet Explorer 4.01
5.0Built-in component of Windows 2000.Windows 2000
5.1Built-in component of Windows XP Professional.Windows XP Professional
6.0Built-in component of Windows Server 2003.WIndows Server 2003
7.0Built-in component of Windows Vista and Windows Server 2008.Windows Vista and WIndows Server 2008
7.5Built-in component of Windows 7 and Windows Server 2008 R2.Windows 7 and Windows Server 2008 R2
8.0Built-in component of Windows 8 and Windows Server 2012.Windows 8 and Windows Server 2012

Tuesday, September 18, 2012

Oracle Schema

Quick way to generate your own schema:
select a.table_name,b.column_name, a.owner,a.tablespace_name
from all_all_tables a
inner join all_tab_columns b
on a.table_name = b.table_name

Tuesday, July 10, 2012

Everything in a Language Stems from a Historic Need

I remember wondering what the big deal was with the Exception type. I guess it was annoying not being able to return an error from, say, constructors:

"The use of exceptions adds to a consistent framework design and allows error reporting from members, such as constructors, that cannot have a return type." - http://msdn.microsoft.com/en-us/library/ms229014

Friday, July 6, 2012

XML to an HTML table in C#


Nodes aren't just elements...

Caught myself thinking that. So to set my mind right:


According to the DOM, everything in an XML document is a node.
The DOM says:
  • The entire document is a document node
  • Every XML element is an element node
  • The text in the XML elements are text nodes
  • Every attribute is an attribute node
  • Comments are comment nodes

Text is Always Stored in Text Nodes

A common error in DOM processing is to expect an element node to contain text.
However, the text of an element node is stored in a text node.
In this example: <year>2005</year>, the element node <year>, holds a text node with the value "2005".
"2005" is not the value of the <year> element!

This is exacerbated by JavaScript referring to nodeValue ....


XML Elements vs. Attributes


XML Elements vs. Attributes

Take a look at these examples:
<person sex="female">
  <firstname>Anna</firstname>
  <lastname>Smith</lastname>
</person>

<person>
  <sex>female</sex>
  <firstname>Anna</firstname>
  <lastname>Smith</lastname>
</person>
In the first example sex is an attribute. In the last, sex is an element. Both examples provide the same information.
There are no rules about when to use attributes or when to use elements.

However, YOU SHOULD AVOID USING ATTRIBUTES WHEN POSSIBLE.  USE ELEMENTS INSTEAD. (except for true MetaData)



The following three XML documents contain exactly the same information:
A date attribute is used in the first example:
<note date="10/01/2008">
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>
A date element is used in the second example:
<note>
  <date>10/01/2008</date>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>
An expanded date element is used in the third:
<note>
  <date>
    <day>10</day>
    <month>01</month>
    <year>2008</year>
  </date>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>


Avoid XML Attributes?

Some of the problems with using attributes are:
  • attributes cannot contain multiple values (elements can)
  • attributes cannot contain tree structures (elements can)
  • attributes are not easily expandable (for future changes)
Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data.
Don't end up like this:
<note day="10" month="01" year="2008"
to="Tove" from="Jani" heading="Reminder"
body="Don't forget me this weekend!">
</note>


XML Attributes for Metadata

Sometimes ID references are assigned to elements. These IDs can be used to identify XML elements in much the same way as the id attribute in HTML. This example demonstrates this:
<messages>
  <note id="501">
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
  </note>
  <note id="502">
    <to>Jani</to>
    <from>Tove</from>
    <heading>Re: Reminder</heading>
    <body>I will not</body>
  </note>
</messages>
The id attributes above are for identifying the different notes. It is not a part of the note itself.
So, metadata (data about data) should be stored as attributes, and the data itself should be stored as elements.

excerpted from http://www.w3schools.com/xml/xml_attributes.asp

new line


In Windows applications, a new line is normally stored as a pair of characters: carriage return (CR) and line feed (LF). In Unix applications, a new line is normally stored as an LF character. Macintosh applications also use an LF to store a new line.
XML stores a new line as LF.

Monday, June 25, 2012

Industry Maneuvers

This is kind of big news for a whole cornocopia of developers because of what it says about the effect Apple ultimately has on Microsoft as well as Flash:

https://www.zdnet.com/blog/microsoft/xamarin-abandons-its-silverlight-for-linux-technology/12797

Friday, June 22, 2012

The worm turns: Embedded SQL vs Stored Procs

Written by James Kovacs about 5 years ago.
Historically Microsoft recommended stored procs because they gave much better performance. Query optimizers in SQL Server 2000 and 2005 have improved dramatically and this is no longer much of an issue. The biggest hassle with stored procs is you have two places to maintain and version code — namely your application and the database. Versioning is much more painful because even without database schema changes, you need the correct set of stored procs for the code base that is running against them. When you’re pulling apart the result set, you need to compare the columns in the stored proc select statements against the columns that your DataReaders are expecting. A trivial task, but mind-numbingly boring. It’s easier if the select is in close proximity to the code that parses it. Personally I’m a big fan of having an ORM tool such as NHibernate or LINQ generate the dynamic queries for me and perform the parsing. I honestly think that’s the way of the future and hand-optimized stored procs will be used for perf critical operations when needed.
And Microsoft doesn't provide a good way of organizing and managing Stored Procedures into folders.

Wednesday, June 20, 2012

Why Did Adobe Buy Macromedia?

Six years on and this is as good as the speculating got:



The fact that Slashdot never got beyond the superficial (and very unsatisfactory in my opinion) explanations might be an indication of Slashdot's non-designer fanbase.

Tuesday, June 19, 2012

Log4Net Logging

Isn't it interesting that by far the most popular .NET logging library is one "owned" now by Apache?  And which had its beginning in Java?

Here is an excellent page to quickly get you up and started with Log4Net:
http://www.justinrhinesmith.com/blog/2008/05/12/quick-and-easy-log4net-setup/
(thank you Justin)

And here is the answer to the question which usually follows:
Note: In log4net speak, an output destination is called an appender.
More than one appender can be attached to a logger.

Is it possible to direct log output to different appenders by level?

Yes it is. Setting the Threshold option of any appender will filter out all log events with a lower level than the value of the threshold option.

For example, setting the threshold of an appender to DEBUG will also allow INFO, WARN, ERROR and FATAL messages to log along with DEBUG messages. (DEBUG is the lowest level). Similarly, setting the threshold of an appender to ERROR will filter out DEBUG, INFO and WARN messages but not ERROR or FATAL messages.  See Example 1.

If you must filter events by exact level match, then you can attach a Filter, such as a  LevelMatchFilter, to any appender to filter out logging events by exact level match. See Example 2.

For more on the matter of Threshod vs. Filter vs. Evaluators, see further below.


Example 1:



<log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
        <threshold value="INFO" />
        .....other elements specific to FileAppender.....
    </appender>
    <appender name="" type="log4net.Appender.SmtpAppender">
        <threshold value="ERROR" />
          .....other elements specific to  SmtpAppender .....
    </appender>
</log4net>


Example 2:


<log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
         <filter type="log4net.Filter.LevelMatchFilter">
              <acceptOnMatch value="true" />
              <levelToMatch value="INFO" />
         </filter>
        .....other elements specific to FileAppender.....
    </appender>
    <appender name="" type="log4net.Appender.SmtpAppender">
         <filter type="log4net.Filter.LevelMatchFilter">
              <acceptOnMatch value="true" />
              <levelToMatch value="ERROR" />
         </filter>
          .....other elements specific to  SmtpAppender .....
    </appender>
</log4net>

Threshold vs. Filter vs. Evaluator

Threshold is the simplest, Filter gives you more flexibility, and Evaluator is only available with certain appenders, such as the one for sending emails. For more see:
Threshold vs. Filter vs. Evaluator


Finally...


What to actually write to the log? see:
http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html



For more on Log4Net, be sure to check out:

and of course:

Wednesday, May 2, 2012

Decent Age Algorithm for C# for string birthdate


When you have a birthdate in a string format, such as "3/17/1980":
strBirthdate = "3/17/1980" //common with HTML forms
DateTime birthdate = DateTime.Parse(strBirthdate);
int age = DateTime.Today.Year - birthdate.Year;
if (birthdate > DateTime.Today.AddYears(-age)) age--;

Tuesday, April 24, 2012

Scott Mitchell on Entity Framework

I detest Microsoft's name for this data technology because of the unbelievable vagueness...I mean, this takes the cake for ambiguity.  Interesting that Scott Mitchell has nary an article on it, although this is what a search on 4guysFromRolla.com gives you, from 1999:

"First things first:
"What's an object?" - An object is basically a container for a set of variables and functions, and an object is normally used to represent some kind of entity.
"What's an entity?" - An entity is literally a "thing". What I mean by "thing" is an idea or object of any kind. For instance, you could say a car is an entity because it is an object. You could also say that a sale of a product by your sales department is an entity, and you could then break that down and say that the salesperson that makes the sale is an entity and the customer is an entity, and the product is an entity....."

He's introducing Visual Basic and the idea of an object.

Wednesday, March 7, 2012

Create an INSERT Script from an existing Table to populate an existing table

Seems as if SQL Server doesn't have a readily available built-in tool for this, so thank you Nigel Rivett.


if exists (select * from sysobjects where id = object_id(N'[dbo].[sp_CreateDataLoadScript]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_CreateDataLoadScript]
GO

Create Procedure sp_CreateDataLoadScript
@TblName varchar(128)
as
/*
exec sp_CreateDataLoadScript 'MyTable'
*/


 create table #a (id int identity (1,1), ColType int, ColName varchar(128))

 insert  #a (ColType, ColName)
 select case when DATA_TYPE like '%char%' then 1 else 0 end ,
  COLUMN_NAME
 from  information_schema.columns
 where  TABLE_NAME = @TblName
 order by ORDINAL_POSITION
 
 if not exists (select * from #a)
 begin
  raiserror('No columns found for table %s', 16,-1, @TblName)
  return
 end

declare @id int ,
 @maxid int ,
 @cmd1 varchar(7000) ,
 @cmd2 varchar(7000)

 select  @id = 0 ,
  @maxid = max(id)
 from  #a

 select @cmd1 = 'select '' insert ' + @TblName + ' ( '
 select @cmd2 = ' + '' select '' + '
 while @id < @maxid
 begin
  select @id = min(id) from #a where id > @id

  select  @cmd1 = @cmd1 + ColName + ','
  from #a
  where id = @id

  select @cmd2 =  @cmd2
    + ' case when ' + ColName + ' is null '
    + ' then ''null'' '
    + ' else '
    +   case when ColType = 1 then  ''''''''' + ' + ColName + ' + ''''''''' else 'convert(varchar(20),' + ColName + ')' end
    + ' end + '','' + '
  from #a
  where id = @id
 end


 select @cmd1 = left(@cmd1,len(@cmd1)-1) + ' ) '' '
 select @cmd2 = left(@cmd2,len(@cmd2)-8) + ' from ' + @tblName

 select '/*' + @cmd1 + @cmd2 + '*/'

 exec (@cmd1 + @cmd2)
 drop table #a

go

Thursday, January 12, 2012

JQuery Version check

In web dev tools console (for whatever browser you are using), just issue the following command:

$().jquery;