Thursday, July 8, 2010

XML Escape Sequences

XML Escape
"   "
'   '
<   &lt;
>   &gt;
&   &amp;

Wednesday, July 7, 2010

Regex Samples

// Filter images file name
var regExp = /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF|.png|.PNG|.bmp|.BMP)$/;


// Check number format in integer and float, the symbol +, - or
// thousandsprate like(123,456,78.001) is no acceptable.
^((((\d+(\.)?)|(\d*\.\d+))(\d+)?))$


// Check XSS Meta-characters insid the input string. This 
// characters and string in the pattern is forbidden in input string.
[\r\n\\'"<>&\u0085]|(?i:\bjavascript|jscript)

Using command line for Windows Disk Defragmenter

Windows Disk Defragmenter
Copyright (c) 2003 Microsoft Corp. and Executive Software International, Inc.
Usage:
defrag <volume> [-a] [-f] [-v] [-?]
  volume  drive letter or mount point (d: or d:\vol\mountpoint)
  -a      Analyze only
  -f      Force defragmentation even if free space is low
  -v      Verbose output
  -?      Display this help text

for example if you want to defrag Dirve D: and analyze onlydefrag D: -a

result is show below:
Windows Disk Defragmenter
Copyright (c) 2003 Microsoft Corp. and Executive Software International, Inc.
Analysis Report
    51.16 GB Total,  14.92 GB (29%) Free,  5% Fragmented (10% file fragmentation)
You do not need to defragment this volume.

Friday, July 2, 2010

How To Handdle XSL output HTML charset

Some times we transfrom xsl to html will get a wrong html chartset.
In C# we usually using TextWriter or XmlTextWriter to output a stream from xsl transformation, but the default encoding of the TextWriter and XmlTextWriter have a potential pitfall makes you difficult to fine out the real reason cause the wrong html charset automatically reander by xsl transform.
By defaul TextWriter and XmlTextWriter using UTF-16 encoding, it cause XSL Trasformation automatically generate html charset to UTF-16, What if you already defined html chartset in your xsl you will find out there a duplicated content-type defined in your output html head like this:
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-16" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        .....
        .....
Solution:
      
      no more best guidance than a real sample code....
XmlDocument xDoc = new XmlDocument();
xDoc.Load(new Uri(Request.Url, xmlUrl).ToString());
XslCompiledTransform xTrans = new XslCompiledTransform();
xTrans.Load(new Uri(Request.Url, xslUrl).ToString());
StringBuilder sb = new StringBuilder();
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings()
{
    Encoding = Encoding.UTF8
    ,
    // if you don't want any xml declaration output such as <?xml ... ?>
    OmitXmlDeclaration = true    
};
          XmlWriter xWriter = XmlTextWriter.Create(sb, xmlWriterSettings);
          xTrans.Transform(xDoc, null, xWriter);
        
         // get result there
        System.Console.Write(sb.ToString());
       
        xWriter.Close();
        // if you want directly write to response
        XmlTextWriter xTxtWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
        xTxtWriter.Close();

Tuesday, June 8, 2010

Email raw data format

 
x-sender: admin@mail.test.com
x-receiver: friend1@mail.test.com
From: <admin@mail.test.com>
To: <friend1@mail.test.com>
Subject: Test mail raw data send
Date: Tue, 7 Jul 1998 13:38:12 +0100
This is a test message
 
This content can seve to a text file and drop it into the \Inetpub\mailroot\Pickup\ folder of the mail server , it will send by the mail server automatically.
 

Sunday, June 6, 2010

Efficient Data Paging for MS SQL

MS SQL seems missing an pageable functions allows you to query data in a range, for sample if you wanna query 10 data between index of row from 25  to 35 theres no way you can setting a start row and end row just like Mysql.
Fortunately MS SQL geving some tricky way do the same effect by using ROW_NUMBER() function in SQL Server 2005 and later version.
 
 
-- First index of row in the page you go.
DECLARE @startRowIndex INT
-- How many rows in a page
DECLARE @maximumRows INT
-- If you goto page 1 and each page have 10 rows, the index row of page 1 is 1, the index row of page 2 is 21 and so forth.
SET @startRowIndex = 1
SET @maximumRows = 10
-- This SQL statement returns 10 of rows data between the rows from @startRowIndex to (@startRowIndex + @maximumRows)-1
SELECT *
FROM
   (SELECT *,
         ROW_NUMBER() OVER(ORDER BY OrderDate DESC) as RowNum
    FROM Northwind.dbo.Orders
   ) as DerivedTableName
WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex + @maximumRows) - 1
 
related link:
 
 

Friday, June 4, 2010

How to changing Fedora GRUB boot order

to boot the 3rd menu entry as default
modify /boot/grub/menu.lst
change the "default 0" option to "default 2"
Please note the first title entry is 0 and then 1,2,3 etc
default=2
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz ?
hiddenmenu

title Fedora Core (2.6.10-1.741_FC3)
root (hd0,1)
kernel /vmlinuz-2.6.10-1.741_FC3 ro root=LABEL=/
initrd /initrd-2.6.10-1.741_FC3.img

title Fedora Core (2.6.9-1.667)
root (hd0,1)
kernel /vmlinuz-2.6.9-1.667 ro root=LABEL=/
initrd /initrd-2.6.9-1.667.img
title windows xp
rootnoverify (hd0,0)
chainloader +1