Pages

Advertisement

Saturday, January 19, 2008

Changing Asp.net form's attribute using Response.filter

There are many ways to change the forms attribute and this is one of them ..

Here is the simple code for that ..

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text.RegularExpressions;
 
public class cdsnetFormActionModifier : Stream
{
    private Stream _sink;
    private long _position;
    string _url;
    public cdsnetFormActionModifier(Stream sink, string url)
    {
        _sink = sink;
        _url = "$1" + url + "$3";
    }
 
    public override bool CanRead
    {
        get { return true; }
    }
 
    public override bool CanSeek
    {
        get { return true; }
    }
 
    public override bool CanWrite
    {
        get { return true; }
    }
 
    public override long Length
    {
        get { return 0; }
    }
 
    public override long Position
    {
        get { return _position; }
        set { _position = value; }
    }
 
    public override long Seek(long offset, System.IO.SeekOrigin direction)
    {
        return _sink.Seek(offset, direction);
    }
 
    public override void SetLength(long length)
    {
        _sink.SetLength(length);
    }
 
    public override void Close()
    {
        _sink.Close();
    }
 
    public override void Flush()
    {
        _sink.Flush();
    }
 
    public override int Read(byte[] buffer, int offset, int count)
    {
        return _sink.Read(buffer, offset, count);
    }
 
    public override void Write(byte[] buffer, int offset, int count)
    {
        string s = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);
        Regex reg = new Regex("(<form.*action=\")([^\"]*)(\"[^>]*>)", RegexOptions.IgnoreCase);
        Match m = reg.Match(s);
        if (m.Success)
        {
            string form = reg.Replace(m.Value, _url);
            int iform = m.Index;
            int lform = m.Length;
            s = s.Substring(0, iform) + form + s.Substring(iform + lform);
        }
        byte[] yaz = System.Text.UTF8Encoding.UTF8.GetBytes(s);
        _sink.Write(yaz, 0, yaz.Length);
    }
}

 


And configure your load event of any page you want like below


  protected void Page_Load(object sender, EventArgs e)
{
this.Response.Filter = new cdsnetFormActionModifier(this.Response.Filter, "your_url");
}

Generating Stored Procedures dynamically

Create Stored Procedure

Create stored procedure to auto generate another stored procedure contain insert command for any tables.

CREATE PROCEDURE Create_procedure_To_insert

parameters


You must add two parameters:

1- Table Name: to generate insert command on it.

2- Developer Name: to set developer name in comments.

//
//

CREATE PROCEDURE create_procedure

@table varchar(200),

@DeveloperName varchar(200),

@Createtable varchar(20)

//

Declaration Variables


You need to declaration many variables to use in stored procedure see below code to know it.

declare @testTable varchar(8000)

declare @testTable2 varchar(8000)

declare @testTable3 varchar(8000)

declare @opration varchar(8000)

declare @final varchar(8000)

declare @OP varchar(100)

 

1- @testTable: used this variable to set all columns from table.

2- @testTable2:used this variable to set all datatype for columns from table.

3- @testTable3:used this variable to set all parameters for columns from table.

4- @opration :used this variable to set insert command.

5-@final :used this variable to set auto generate stored procedure.

6-@OP :used this variable to set name for the new stored procedure.

Initialization Variables


You need to set empty values in the below variables.

set @testTable=''

set @testTable2=''

set @final=''

set @testTable3=''

set @opration=''

declare @Datetime varchar(50)

set @Datetime=getdate()

Importents Code


You need to create three select statment :

1- The First Select statment to get all columns from information_schema.columns when table equal table name in parameters ,you must get 'isidentity'= zero becuase if 'isidentity'=one you can not insert data on identity columns

2-The second Select statment to get all datatype from information_schema.columns when table equal table name in parameters .you must get 'isidentity'= zero becuase if 'isidentity'=one you can not insert data on identity columns.

3-The Third Select statment to get columns name and set @columns name in parameters

after that you must generate the new stored procedure ,so you can create structure for procedure in string datatype and set the string in execute function to execution stored procedure "Exec(@final)"

select @testTable=@testTable+ ',

'+column_name from information_schema.columns where table_name=@table and (COLUMNPROPERTY(OBJECT_ID(@table), column_name, 'isidentity') = 0) AND (column_default IS NULL)

select @testTable2=@testTable2+ ',

@'+column_name+' '+data_type+'(' + cast(character_maximum_length as varchar(10)) +')' + case is_nullable when 'no' then ' ' when 'yes' then '=null' end from information_schema.columns where table_name=@table and (COLUMNPROPERTY(OBJECT_ID(@table), column_name, 'isidentity') = 0)and character_maximum_length<>null AND (column_default IS NULL)and data_type<>'text'

select @testTable2=@testTable2+ ',

@'+column_name+' '+data_type from information_schema.columns where table_name=@table and (COLUMNPROPERTY(OBJECT_ID(@table), column_name, 'isidentity') = 0)and (character_maximum_length=null or data_type='text' ) AND (column_default IS NULL)

select @testTable3=@testTable3+ ',

@'+column_name from information_schema.columns where table_name=@table and (COLUMNPROPERTY(OBJECT_ID(@table), column_name, 'isidentity') = 0) AND (column_default IS NULL)

set @testTable=SUBSTRING(@testTable,2,len(@testTable))

set @testTable2=SUBSTRING(@testTable2,4,len(@testTable2))

set @testTable3=SUBSTRING(@testTable3,2,len(@testTable3))

set @opration=' insert into [' +@table+']

(

'+@testTable+'

)

values

(

'+ @testTable3 +'

)'

set @OP='InsertNew'+@table

set @final='/*

----------------------------------------------------------------------------------------

Store Procedure Name : SP__'+@OP +'

----------------------------------------------------------------------------------------

1- Creation Date :'+convert (varchar,getdate(),103) +'

2- Last Update :'+convert (varchar,getdate(),103)+'

3- Parametars No:6

4- Creation By :'+@DeveloperName+'

5- Last Update By :'+@DeveloperName+'

6- Return Value : Dataset

---------------------------------------------------------------------------------------

*/

Create PROCEDURE SP__'+@OP+'

(
'+ @testTable2 + '
)

AS

set nocount on

' + @opration + '

Select * from [' +@table +']'

exec (@final)

Thursday, January 3, 2008

A Second Earth in the Making

 

A new solar system containing an Earth-like planet is likely to be forming 424 light-years away around a 10 million-year-old star named HD 113766, a team of astronomers using NASA’s orbiting Spitzer Space Telescope have discovered.


At this point, the new solar system isn’t much to look at — it’s just a huge belt of warm dust, swirling around a star that is slightly bigger than the sun. But the dust is located smack in the middle of HD 113766’s habitable zone — that is, the region around a star in which the surface temperature on a planet would allow water to exist in liquid form. (The Earth, for example, is located precisely in the middle of the sun’s habitable zone, which sometimes also is called the ecosphere.) HD 113766 also happens to be just the right age for forming rocky planets like those in our inner solar system.


"The timing for this system to be building an Earth is very good," Casey Lisse, a senior research scientist in the space department of the Johns Hopkins University Applied Physics Laboratory in Baltimore, explained in a press release. “If the system was too young, its planet-forming disk would be full of gas, and it would be making gas-giant planets like Jupiter instead. If the system was too old, then dust aggregation or clumping would have already occurred and all the system's rocky planets would have already formed."


According to Lisse, the conditions for forming an Earth-like planet are more than just being in the right place at the right time and around the right star — it's also about the right mix of dusty materials. Using Spitzer’s infrared spectrometer, he determined that the material in the dust belt is more processed than the snowball-like ingredients of infant solar systems, but not as far along as mature planets. That means that the dust belt is in a transitional phase, where planets are just beginning to form.


"The material mix in this belt is most reminiscent of the stuff found in lava flows on Earth. I thought of Mauna Kea material when I first saw the dust composition in this system — it contains raw rock and is abundant in iron sulfides, which are similar to fool's gold," says Lisse.


Here’s a 2004 scientific journal article about the formation of solar systems around young stars. Here also is an artist's conception of the forming solar system.

Monday, December 17, 2007

Top 10 Tips for Linux Users

 Everyone develops their favorite tips and tricks for using Linux based on their own experience and the kind of work they are doing. Here are some of mine. These tips may seem simple, but I've found it's often the simple tricks that are the most useful in day-to-day work.

  1. Switch to another console. Linux lets you use "virtual consoles" to log on to multiple sessions simultaneously, so you can do more than one operation or log on as another user. Logging on to another virtual console is like sitting down and logging in at a different physical terminal, except you are actually at one terminal, switching between login sessions.

    Virtual consoles are especially useful if you aren't running X, but you can use them even if you are.

    In early versions of the kernel (pre-1.1.54), the number of available virtual consoles was compiled into the kernel. With more recent kernels, 63 virtual consoles are available, with 6 set up by default in the file /etc/inittab.

    Use the key combination Alt+Fn to switch between virtual consoles, where Fn is one of the function keys F1-F6. (If you are in X, you'll probably need to use Ctrl-Alt-Fn instead.) Alt+F7 gets you back to your X session, if one is running. You can rotate between consoles with the Alt-right arrow and Alt-left arrow key combinations.

  2. Temporarily use a different shell. Every user account has a shell associated with it. The default Linux shell is bash; a popular alternative is tcsh. The last field of the password table (/etc/passwd) entry for an account contains the login shell information. You can get the information by checking the password table, or you can use the finger command. For example, the command "finger ellen" shows, among other things, that I use /bin/tcsh.

    Related Reading

    Linux in a Nutshell The command chsh changes the login shell for all future logins; that is, it changes the account entry in the password table to reflect the new shell. However, you can also temporarily use another shell at any time by simply running the new shell. For example, if I want to try something out in bash, I can type "bash" at the prompt and be put into a bash shell. Typing either Ctrl-d or exit gets rid of that shell and returns me to my tcsh session.

Print a man page. Here are a few useful tips for viewing or printing manpages:

To print a manpage, run the command:

man <manpage> | col -b | lpr

The col -b command removes any backspace or other characters that would make the printed manpage difficult to read.

Also, if you want to print a manpage that isn't in a standard man directory (i.e., it's in a directory that isn't specified in the MANPATH environment variable), you can specify the full pathname of the manpage, including the full filename:

man /work/myapp/mymanpage.1

If you use the Emacs editor, you can view a manpage with the command Meta-x man; Emacs then prompts you for the name of the manpage. You can view the page or print it as you would any other Emacs buffer.

As a last resort, you can format the manpage directly with the groff command. However, the default output is a PostScript file, so you'll want to either send it to a PostScript printer or to a viewer such as ghostview:

groff -man /work/myapp/mymanpage.1 | ghostview -i

You can get ASCII output with the -a option, but the result is unformatted text. Not pretty to read, but it might suffice if nothing else works.

  1. Use command substitution to simplify complex operations. Command substitution lets you use the output of one command as an input argument to another command. To use command substitution, determine what command will generate the output you want, put that command in backquotes, and use it as an argument to another command. For example, I often use command substitution to recursively grep the files in a directory tree:

    grep 'Title' `find /work -type f -name 'chap*' -print` > chaptitles

    The portion of this command in backquotes is a find command that builds a list of chapter files in the /work directory. That list is then used to provide the set of input files for grep to search for titles. The output is saved in a file called chaptitles.

  2. Look inside a non-text file. Sometimes you really want to see inside a binary file. Maybe there isn't a manpage and you're looking for usage information, or perhaps you're looking for information about who wrote a program or what application a file is associated with.

    The strings command is perfect for that purpose--it searches through a file looking for sequences of printable character strings and writes them to standard output. You can pipe the output through a pager like more, or if you are looking for particular text, you can pipe the output to the grep command.

  3. Use the locate command. Looking for an easier way to find files than the find command? Try using locate. In contrast to find's complexity, locate is the ultimate in simplicity. The command:

    locate <string>

    searches an internal database and prints the pathnames of all files and directories that contain the given string in their names. You can narrow down the search by piping the output to grep. For example, the following finds all files containing the string "kde" that are in bin directories:

    locate kde | grep bin

    The strings don't have to be complete names; they can be partial strings, such as "gno" instead of spelling out "gnome". The -r option lets you use a regular expression (in quotes):

    locate -r 'gno*'

    One thing to be aware of is that locate is case-sensitive: Searching for HOWTO and for howto will give you different results.

    Rather than searching the disk each time, as find does, locate depends on the creation and maintenance of a database. Because it only has to search the database, not the disk, locate is faster than find. On the other hand, the results are only as current as the database.

    The locate database is generally updated daily by a cron job, but you can update it manually by running the command updatedb (usually as root). If you are adding new applications or deleting old files and you don't want to wait for the next day to have an up-to-date database, you might want to run it manually.

  4. Use dmesg to view startup messages. The dmesg command provides an easier way to see the boot messages than trying to read them before they scroll off the screen. When Linux boots, the kernel startup messages are captured in a buffer known as the kernel ring buffer; dmesg prints the contents of that buffer. By default, dmesg prints its output to the screen; you can of course redirect the output to a file:

    % dmesg > bootmsg

  5. Find out what kernel version you are using. Do you ever need to know what version of the Linux kernel is running on your system? You can find out with the uname command, which prints information about the system. Issued with the -r option, uname prints the kernel version:

    % uname -r
    2.2.14-5.0

    Other uname options provide information such as the machine type, the name of the operating system, and the processor. The --all option prints all the available information.

  6. Use df and du to maintain your disk. Use the df (display filesystem) command to keep an eye on how much space each of your filesystems occupies and how much room is left. It's almost inevitable that if you like to download new software and try it out, you'll eventually fill up your disk. df has some options, but running it without options provides the basic information--the column labeled Use% tells you how full each filesystem is:

    % df Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda3 1967156 1797786 67688 96% /

    Oops, time to clean house... and that's where du (disk usage) comes in handy. The du command provides the information you need to find the big space users, by printing the amount of disk space used for each file, subdirectory, and directory. You can specify the directory du is to start in, or let it default to the current directory.

    If you don't want to run du recursively through subdirectories, use the -s option to summarize. In that case, you need to specify all the directories you are interested in on the command line. For example:

    % du -s /usr/X11R6
    142264 /usr/X11R6

    % du -s /usr/X11R6/*
    34490 /usr/X11R6/bin
    1 /usr/X11R6/doc
    3354 /usr/X11R6/include

    97092 /usr/X11R6/lib
    7220 /usr/X11R6/man
    106 /usr/X11R6/share

    With the information provided by du, you can start in the directories that occupy the most disk space and delete or archive files you no longer actively use.

  7. Permit non-root users to mount or unmount drives. While hard drives are normally mounted automatically when the system is booted, other drives such as the floppy drive and the CD-ROM are generally not mounted until they are going to be used, so that disks can be inserted and removed. By default, root privileges are required for doing the mount (or unmount). However, you can modify the entries in the filesystem table, /etc/fstab, to let other users run the mount command. Do this by adding the option "user" to the appropriate entry:

    /dev/fd0 /mnt/floppy auto noauto,user 0 0 /dev/cdrom /mnt/cdrom iso9660 noauto,ro,user,unhide 0 0

    You can see what filesystems are currently mounted, and what options they were mounted with, by looking at the file /etc/mtab or by running the mount command with no options or arguments.


Parmalink

Excel Tips : The easiest way to find Duplicates of cell in a column

--------------------------------------------
Dates in column A   Text in Column B
--------------------------------------------
03/10/2003 | AAA
03/15/2003 | BBB
03/20/2003 | CCC
03/25/2003 | AAA
03/30/2003 | BBB
04/04/2003 | CCC
03/25/2003 | AAA
03/30/2003 | BBB
04/04/2003 | CCC
03/25/2003 | AAA
03/30/2003 | BBB
04/04/2003 | CCC



1> Enter the formula : =A1&B1 to cell C1 and copy / paste the formula to cells C2:C12

2> Enter the formula : =IF(COUNTIF($C$1:C1,C1)>1,"Duplicate","Unique")
                                      to cell E1 and copy / paste the formula to cells E2:E12

 

 

** (you can use the second formula directly if you have only a single column  : Like

Column A

--------------

<>
</>
Column A        
BBB        
CCC        
AAA        
BBB        
CCC        
AAA        
BBB        
CCC        
AAA        
BBB        
CCC        

Insert this Formula in Column B : =IF(COUNTIF($A$1:A1,A1>1),"Duplicate","Unique")

and  you are done ..

Technorati Tags: ,,,