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;

Wednesday, November 30, 2011

LINQ to SQL HA HA HA

When contemplating the motivation for doing away with the impedance created between an Object Oriented app and a Relational Database, and thus ultimately LINQ and Entity Framework, I would struggle to feel convinced (I'm equally comfortable writing T-SQL in Management Studio as I am writing VB and C# in Visual Studio).

If anything stood out in my mind as inconvenient, it would certainly be the tedious and redundant variable/field names when writing queries.  I was always adept at solving such problems with a good text editor at my side that could use vertical highlighting and Regular Expressions (such as Textpad), so this wasn't that big a deal.  But nonetheless, I found (and am still finding) the 2008 SQL Server Management Studio's Intellisense capabilities (FINALLY!!) to be amazingly helpful.  So helpful that, if I did have any desires to lower the impedance between a OOP architected app and an RDBMS, the 2008 tool would have satisfied it.

So, this is the irony.  The tool's improvements were released the SAME TIME as the company (Microsoft) was pushing LINQ to SQL and Entity Framework.

And this seems a bit absurd to me.

But wait, there's more...“LINQ to SQL is dead!”