<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-4752443593401370011</id><updated>2009-11-09T11:23:32.468-05:00</updated><title type='text'>!!--FuTuRe Of CoDiNg--!!</title><subtitle type='html'>This refers to transforming or changing the characteristics of a signal to make it more suitable for some intended application, usually for transmission from one location to another or for storage onto some medium that is different than the original medium. Coding can improve fidelity, optimize carrier bandwidth, increase essence carriage, improve security or provide error detection and correction.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default?start-index=26&amp;max-results=25'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>149</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-3628225606525286844</id><published>2009-07-16T13:23:00.000-05:00</published><updated>2009-07-16T13:24:10.186-05:00</updated><title type='text'>a new compression algorithm called Courgette to make Google Chrome updates small.</title><content type='html'>We have built Google Chrome to address multiple factors that affect browser security. One of the pillars of our approach is to keep the software up to date, so we push out updates to Google Chrome fairly regularly. On the stable channel these are mainly security bug fixes, but the updates are more adventurous and numerous on developer channel.&lt;br /&gt;&lt;br /&gt;It is an anathema to us to push out a whole new 10MB update to give you a ten line security fix. We want smaller updates because it narrows the window of vulnerability. If the update is a tenth of the size, we can push ten times as many per unit of bandwidth. We have enough users that this means more users will be protected earlier. A secondary benefit is that a smaller update will work better for users who don't have great connectivity.&lt;br /&gt;&lt;br /&gt;Rather then push put a whole new 10MB update, we send out a diff that takes the previous version of Google Chrome and generates the new version. We tried several binary diff algorithms and have been using bsdiff up until now. We are big fans of bsdiff - it is small and worked better than anything else we tried.&lt;br /&gt;&lt;br /&gt;But bsdiff was still producing diffs that were bigger than we felt were necessary. So we wrote a new diff algorithm that knows more about the kind of data we are pushing - large files containing compiled executables. Here are the sizes for the recent 190.1-&gt;190.4 update on the developer channel:&lt;br /&gt;&lt;br /&gt;    * Full update: 10,385,920 bytes&lt;br /&gt;    * bsdiff update: 704,512 bytes&lt;br /&gt;    * Courgette update: 78,848 bytes&lt;br /&gt;&lt;br /&gt;The small size in combination with Google Chrome's silent update means we can update as often as necessary to keep users safe.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-3628225606525286844?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/3628225606525286844/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=3628225606525286844' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3628225606525286844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3628225606525286844'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2009/07/new-compression-algorithm-called.html' title='a new compression algorithm called Courgette to make Google Chrome updates small.'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-3983979874041782276</id><published>2008-08-11T01:42:00.000-05:00</published><updated>2008-08-11T01:43:10.575-05:00</updated><title type='text'>Get Your Database Under Version Control</title><content type='html'>&lt;p&gt;When it comes to version control, the database is often a second or even  third-class citizen. From what I've seen, teams that would &lt;i&gt;never&lt;/i&gt; think of  writing code without version control in a million years-- and rightly so-- can  somehow be completely oblivious to the need for version control around the  critical databases their applications rely on. I don't know how you can call  yourself a software engineer and maintain a straight face when your database  isn't under &lt;i&gt;exactly&lt;/i&gt; the same rigorous level of source control as the rest  of your code. Don't let this happen to you. &lt;b&gt;Get your database under version  control&lt;/b&gt;.  &lt;/p&gt;&lt;p&gt;I was thinking about this again because my friend &lt;a href="http://www.codinghorror.com/blog/archives/000971.html"&gt;and co-author&lt;/a&gt;  K. Scott Allen just wrote a brilliant five part series on the philosophy and  practice of database version control:  &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://odetocode.com/Blogs/scott/archive/2008/01/30/11702.aspx"&gt;Three  rules for database work&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a href="http://odetocode.com/Blogs/scott/archive/2008/01/31/11710.aspx"&gt;The  Baseline&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a href="http://odetocode.com/Blogs/scott/archive/2008/02/02/11721.aspx"&gt;Change  Scripts&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a href="http://odetocode.com/Blogs/scott/archive/2008/02/02/11737.aspx"&gt;Views,  Stored Procedures and the Like&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a href="http://odetocode.com/Blogs/scott/archive/2008/02/03/11746.aspx"&gt;Branching  and Merging&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-3983979874041782276?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/3983979874041782276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=3983979874041782276' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3983979874041782276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3983979874041782276'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/08/get-your-database-under-version-control.html' title='Get Your Database Under Version Control'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-3542692018833675835</id><published>2008-05-29T23:09:00.000-05:00</published><updated>2008-05-29T23:11:24.165-05:00</updated><title type='text'>Silverlight - Basics - XAML</title><content type='html'>Silverlight 2.0 is on its way to an official release, and with beta 1, we are now seeing a fuller implementation, including a number of standard controls and richer support to accomplish common tasks. If you're new to Silverlight / Windows Presentation Foundation, the place to start is understanding XAML (pronounced zammel) - the Extensible Application Markup Language. XAML is an XML dialect, and thus, follows the traditional tree hierarchy of elements you're used to seeing in XML. The main features of XAML are:&lt;br /&gt;&lt;br /&gt;    * Element names correspond to objects. A "&lt;UserControl ...&gt;" in XAML corresponds to the System.Windows.Controls.UserControl class, for example.&lt;br /&gt;    * Type converters understand string property values. Type converters are used to convert a property value, such as Background="White" or Background="#FF0000" to the class behind the property. A type converter parses and understands what you're asking for (as long as you specify something it can convert)&lt;br /&gt;    * Markup extensions. A markup extension is a special way of saying "interpret this property value, don't take it literally or type convert it." Markup extensions are using for referencing resources, creating control templates and data binding.&lt;br /&gt;    * Dependency properties and attached properties. A dependency property is a property that depends on potentially many things - including animation, data binding and the value you explicitly set. An attached property is a special type of dependency property that an object doesn't define. It is "attached" in that the object with the attached property has the property, but it is meaningless to the object itself. The attached property IS meaningful, however, to elements enclosing the object. A great example is a container such as Canvas (it provides absolute positioning) and the attached property Canvas.Left and Canvas.Top - specify these on a child object, such as an Image, and the Canvas knows where to place the Image.&lt;br /&gt;    * Direct connection to code-behind. When built, the XAML file causes generation of a piece of the class specified by the x:Class attribute, and it is here that object identifiers are created to connect to the objects specified by elements in the XAML (as long as the element in XAML has an x:Name attribute defined) This connection also includes connecting to event handlers in the code-behind.&lt;br /&gt;&lt;br /&gt;This is a rather quick overview of XAML - over time we will delve deeper into these features and all the aspects of Silverlight.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-3542692018833675835?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/3542692018833675835/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=3542692018833675835' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3542692018833675835'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3542692018833675835'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/05/silverlight-basics-xaml.html' title='Silverlight - Basics - XAML'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-2036239102136597279</id><published>2008-05-17T01:52:00.000-05:00</published><updated>2008-05-17T01:54:02.662-05:00</updated><title type='text'>Silverlight Tips, Tricks, and Best Practices</title><content type='html'> Unless you've been stuck on a desert island for the past several months, you've undoubtedly heard about Silverlight™, the new cross-browser, cross-platform solution from Microsoft that helps you build rich Internet applications and rich, immersive media experiences in the browser. Version 1.0, which combines a XAML rendering engine with a JavaScript API, shipped in September 2007. Version 2.0, which will enter beta soon, will pair an enhanced XAML engine with a version of the CLR that runs in the browser, a Silverlight version of the Microsoft® .NET Framework Base Class Library (BCL), and a managed API. (That's right: C# in the browser!)&lt;br /&gt;Silverlight 1.0 applications are proliferating on the Web, thanks in part to some of the high-profile companies that adopted it early and helped spread the love. The programming model is simple enough for an experienced developer to begin building Silverlight applications in a matter of hours. What's missing for this still very young platform, however, is that wealth of knowledge and resources that accompanies more mature platforms.&lt;br /&gt;I've been developing Silverlight apps for more than a year now and have put together a list of best practices that I and other developers on my team use to build better applications. This column contains some of the most helpful ones.&lt;br /&gt;&lt;br /&gt;Take Performance Tips to Heart&lt;br /&gt;Not long before Silverlight 1.0 shipped, Microsoft published a document titled "Performance Tips for Silverlight-Based Applications" (msdn2.microsoft.com/bb693295). This guide is a compilation of tips for optimizing performance by avoiding some common mistakes. The best practices you'll find include:&lt;br /&gt;&lt;br /&gt;    * Use the Visibility property rather than Opacity to hide objects.&lt;br /&gt;    * Don't use the Width and Height properties of MediaElement and Path objects.&lt;br /&gt;    * Detach programmatically registered event handlers after use.&lt;br /&gt;    * Use transparent control backgrounds sparingly.&lt;br /&gt;&lt;br /&gt;Most of these make sense when you read them. It's not hard to imagine why it's better to encode videos using the width and height at which you intend to display them (rather than encode them at one scale and display them at another). It's because the Silverlight rendering engine can avoid resizing each frame on the fly. Still, it's good to see them written down and to know that Silverlight doesn't do something fancy to resize video without incurring a performance penalty.&lt;br /&gt;One best practice that I would add to that document is to avoid redundant calls to FindName. I often see event handlers structured this way:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;function onClick(sender, args)&lt;br /&gt;{&lt;br /&gt;    var rect = sender.findName('Rect');&lt;br /&gt;    rect.fill = 'red';&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The problem is that FindName has to walk the tree of XAML objects to find its target. If you're going to be referencing the XAML object named "Rect" many times over the lifetime of the app, you should initialize it once—for instance, in an event handler for the root canvas's Loaded event—and store the reference in a global variable. Then, instead of calling FindName every time onClick is called, you can do this:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;function onClick(sender, args)&lt;br /&gt;{&lt;br /&gt;    _rect.fill = 'red';&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The resulting code will be faster than the original. But if a developer does this, he should be sure to release that reference when finished with the plugin. In normal pages this is never an issue, but in an AJAX app where whole pieces may be coming and going, its crucial to release those references to avoid a memory leak. For that reason, the Sys.UI.Silverlight.Control ajax type that is used when using the ASP.NET Silverlight Control (currently available in the Extensions 3.5 Preview Community Technology Preview) provides a pluginDispose method you can override to release references and event handlers.&lt;br /&gt;&lt;br /&gt;Offer a Compelling Installation Experience&lt;br /&gt;Too often the Silverlight-based application installation experience is not friendly enough to users who don't have Silverlight installed, as exemplified by the barren landscape displayed in Figure 1. Silverlight.createObjectEx—the function that's typically called to instantiate a Silverlight control—displays a "Get Microsoft Silverlight" button when Silverlight isn't present. Clicking the button transports the user to the Silverlight Web site to download and install it. You can improve the experience somewhat by setting Silverlight.createObjectEx's inplaceInstallPrompt parameter to true, enabling the user to download and install Silverlight without leaving the Web page. But even that leaves something to be desired, especially when Silverlight comprises most or all of the content on the page.&lt;br /&gt;Figure 1 Default Silverlight Installation Experience (Click the image for a larger view)&lt;br /&gt;Microsoft recently published a document that should be required reading for all developers using Silverlight—"Silverlight Installation Experience Guide." It's available for downloading along with sample code at go.microsoft.com/fwlink/?LinkId=106023. The document outlines a general technique for displaying HTML content (including a "Get Microsoft Silverlight" button and browser-specific instructions) in a Silverlight DIV when Silverlight isn't installed, and XAML content when it is. The idea is to paint a picture of what the user would see if Silverlight were installed and hopefully to entice him to click the button.&lt;br /&gt;This column is accompanied by a sample application named RevolvingAuto that demonstrates some of the best practices presented here, including how to build a better installation experience. I'll show you key portions of its source code shortly.&lt;br /&gt;RevolvingAuto is notable for its installation experience. Figure 2 shows what the home page looks like to a visitor who doesn't have Silverlight installed. Behind the "Get Microsoft Silverlight" button is a shaded version of the same user experience the user would see if Silverlight were installed. Because the call to Silverlight.createObjectEx includes an inplaceInstallPrompt="true" parameter, the user can install Silverlight without leaving the Web page. And to top it off, the home page includes logic to create the Silverlight control after installation is complete, eliminating the need for a manual refresh. (This feature works great in Internet Explorer® because it doesn't have to be restarted after Silverlight is installed. It's powerless in browsers that require a restart, unfortunately.)&lt;br /&gt;Figure 2 RevolvingAuto before Silverlight Is Installed (Click the image for a larger view)&lt;br /&gt;The JavaScript that drives the install experience lives within Default.html (see Figure 3). To create a Silverlight control, most Silverlight applications structure the code and markup like this:&lt;br /&gt; Figure 3 RevolvingAuto Application—Default.html&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;&lt;html &gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;    &lt;title&gt;Revolving Auto&lt;/title&gt;&lt;br /&gt;    &lt;script type="text/javascript" src="Silverlight.js"&gt;&lt;/script&gt;&lt;br /&gt;    &lt;script type="text/javascript" src="Default.html.js"&gt;&lt;/script&gt;&lt;br /&gt;    &lt;style&gt;&lt;br /&gt;        .AgInstalled { &lt;br /&gt;            margin-left: auto; margin-right: auto; &lt;br /&gt;            width: 612px; height: 700px; text-align: left }&lt;br /&gt;        .AgNotInstalled { &lt;br /&gt;            margin-left: auto; margin-right: auto;&lt;br /&gt;            width: 612px; height: 700px; text-align: left;&lt;br /&gt;            background-image: url(Images/Install.jpg);&lt;br /&gt;            background-repeat: no-repeat; padding-top: 100px }&lt;br /&gt;    &lt;/style&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;br /&gt;&lt;body style="background-color: black; text-align: center"&gt;&lt;br /&gt;    &lt;div style="height: 40px"&gt;&lt;/div&gt;&lt;br /&gt;    &lt;div id="Container" class="AgInstalled"&gt;&lt;br /&gt;        &lt;div id="SilverlightPlugInHost" style="padding-left: 200px"&gt;&lt;br /&gt;        &lt;/div&gt;&lt;br /&gt;    &lt;/div&gt;&lt;br /&gt;    &lt;script type="text/javascript"&gt;&lt;br /&gt;        var _id;&lt;br /&gt;&lt;br /&gt;        if (!Silverlight.isInstalled('1.0'))&lt;br /&gt;        {&lt;br /&gt;            document.getElementById('Container').className =&lt;br /&gt;                'AgNotInstalled';&lt;br /&gt;            _id = window.setTimeout('checkInstall()', 3000);&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;            document.getElementById ('SilverlightPlugInHost')&lt;br /&gt;                .removeAttribute('style');&lt;br /&gt;        &lt;br /&gt;        createSilverlight();&lt;br /&gt;&lt;br /&gt;        function checkInstall()&lt;br /&gt;        {&lt;br /&gt;            if (Silverlight.isInstalled('1.0'))&lt;br /&gt;            {&lt;br /&gt;                window.clearInterval(_id);&lt;br /&gt;                document.getElementById('Container')&lt;br /&gt;                    .className = 'AgInstalled';&lt;br /&gt;                document.getElementById ('SilverlightPlugInHost')&lt;br /&gt;                    .removeAttribute('style');&lt;br /&gt;                createSilverlight();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    &lt;/script&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;&lt;div id="SilverlightPlugInHost"&gt;&lt;br /&gt;  &lt;script type="text/javascript"&gt;&lt;br /&gt;    createSilverlight();&lt;br /&gt;  &lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;RevolvingAuto structures it this way instead:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;&lt;div id="Container"&gt;&lt;br /&gt;  &lt;div id="SilverlightPlugInHost"&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;   // Code to create the control&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;The code inside the &lt;script&gt; element calls Silverlight.isInstalled (which is implemented in Silverlight.js along with Silverlight.createObjectEx) to determine whether Silverlight is installed. If the answer is yes, the script calls createSilverlight to create the control. If the answer is no, the script dynamically styles the DIV containing the Silverlight DIV to show a background image, and then calls createSilverlight to display the "Get Microsoft Silverlight" button. The background image is the one behind the button in Figure 2.&lt;br /&gt;If it determines that Silverlight is not installed, the creation script also uses window.setTimeout to set up calls to a local function named checkInstall every three seconds. Once installation is complete, checkInstall removes the background image, clears the timer so the function won't be called again, and calls createSilverlight again to create the Silverlight control.&lt;br /&gt;&lt;br /&gt;Don't Make the User Wait&lt;br /&gt;The hallmark of Silverlight 1.0 is a rich media experience for images, audio, and video. But files such as these can be large (very large!), and if you declare Image or MediaElement objects in XAML and declare media to go along with them, the download time can be tremendous. The problem is that Silverlight doesn't display one speck of XAML until all of the XAML and the assets that it references have been downloaded. The user, meanwhile, is left wondering what's going on—or if anything is going on at all. It's not a big deal if the user waits a couple of seconds, but if seconds become minutes, the user is likely to give up and move on to better-built sites.&lt;br /&gt;That's why well-designed Silverlight apps don't statically link to media assets; instead, they use the built-in Silverlight downloader object, which piggybacks on the browser's XmlHttpRequest stack to download those assets asynchronously. Instead of doing this&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;&lt;MediaElement Source="FunnyVideo.wmv" /&gt;&lt;br /&gt;&lt;br /&gt;you declare the MediaElement without a Source attribute, which prevents the Silverlight control from waiting for a video to download before rendering any XAML. Then you create a downloader object and asynchronously download the video, calling the MediaElement's SetSource method to pass the video to the MediaElement once the download has finished. If you like, you can update a progress indicator here as well. The downloader fires downloadProgressChanged and Completed events to aid in the process.&lt;br /&gt;Silverlight also makes it easy to download multiple assets rather than just one. Just package all your assets—audio, video, images, even XAML or XML—in a ZIP file and use the downloader to download it. Then, when you call SetSource to assign content to an object, specify the name of the file inside the ZIP file in the second parameter. It couldn't be much simpler.&lt;br /&gt;Here's an example:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;downloader.open('GET', 'Assets.zip');&lt;br /&gt;downloader.send();&lt;br /&gt;  ...&lt;br /&gt;// In the Completed event handler&lt;br /&gt;_media.setSource(sender, 'FunnyVideo.wmv');&lt;br /&gt;&lt;br /&gt;The RevolvingAuto application uses a downloader object to asynchronously download a ZIP file containing 105 image files. Together, these files comprise a 360-degree view of an automobile at 3.5-degree increments. At run time, the application swaps images in and out to revolve the automobile.&lt;br /&gt;The DownloadProgressChanged event handler updates a progress bar, which is nothing more than a XAML rectangle whose width increases as the download progresses. The Completed event handler assigns the downloaded images to dynamically created Image objects. It also hides the progress bar and unregisters the two downloader event handlers in accordance with the performance document referenced in the first section of this article.&lt;br /&gt;Speaking of not making the user wait, most browsers drive the UI and execute JavaScript on the same thread. Consequently, if you engage in a long-running JavaScript task (say, some number crunching that takes 5 or 10 seconds to execute), the UI will be unresponsive for the duration. The aforementioned performance-tips document recommends breaking long-running JavaScript tasks into smaller, more granular tasks for this reason. In Silverlight 2.0, you'll be able to delegate long-running tasks to background threads. In version 1.0, however, that's not an option.&lt;br /&gt;&lt;br /&gt;Use CreateFromXaml to Reduce XAML Size&lt;br /&gt;Another takeaway from the sample application is how it uses CreateFromXaml to create XAML Image objects dynamically rather than cluttering the XAML file with scores of nearly identical Image declarations. The XAML file you see in Figure 4, Scene.xaml, is nearly empty. It declares a couple of Canvases and Rectangles, a Storyboard, and a ScaleTransform, but it doesn't declare a single Image object. Instead, a for loop in Default.html.js creates 105 Image objects—one per image in the animation—and initializes them with image bits from the downloader (see Figure 5).&lt;br /&gt; Figure 5 RevolvingAuto Application —Default.html.js&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;function createSilverlight()&lt;br /&gt;{&lt;br /&gt;  Silverlight.createObjectEx({&lt;br /&gt;    source: 'Scene.xaml',&lt;br /&gt;    parentElement: document.getElementById('SilverlightPlugInHost'),&lt;br /&gt;    id: 'SilverlightPlugIn',&lt;br /&gt;    properties: {&lt;br /&gt;      width: '900',&lt;br /&gt;      height: '700',&lt;br /&gt;      background:'black',&lt;br /&gt;      isWindowless: false,&lt;br /&gt;      inplaceInstallPrompt: true,&lt;br /&gt;      version: '1.0'&lt;br /&gt;    },&lt;br /&gt;    events: {&lt;br /&gt;      onError: null,&lt;br /&gt;      onLoad: null&lt;br /&gt;    },        &lt;br /&gt;    context: null &lt;br /&gt;  });&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var _zoom = 1;                  // Zoom factor&lt;br /&gt;var _index = 0;                 // Image index&lt;br /&gt;var _progressBar;               // Progress bar&lt;br /&gt;var _progressBarContainer;      // Progress bar container&lt;br /&gt;var _progressBarCanvas;         // Progress bar canvas&lt;br /&gt;var _progressBarWidth;          // Full width of progress bar&lt;br /&gt;var _control                    // Silverlight control&lt;br /&gt;var _transform;                 // Zoom transform&lt;br /&gt;var _timer;                     // Timer storyboard&lt;br /&gt;var _token1, _token2;           // Event handler tokens&lt;br /&gt;var _images = new Array(36);    // References to XAML images&lt;br /&gt;var _photos = 105;              // Number of photos&lt;br /&gt;&lt;br /&gt;function onLoaded(sender)&lt;br /&gt;{&lt;br /&gt;  // Initialize XAML references and other variables&lt;br /&gt;  transform = sender.findName('ZoomTransform');&lt;br /&gt;  timer = sender.findName('TimerStoryboard');&lt;br /&gt;  progressBar = sender.findName('ProgressBar');&lt;br /&gt;  progressBarContainer = sender.findName('ProgressBarContainer');&lt;br /&gt;  progressBarCanvas = sender.findName('ProgressBarCanvas');&lt;br /&gt;  progressBarWidth = _progressBarContainer.width - 4;&lt;br /&gt;  control = sender.getHost();&lt;br /&gt;&lt;br /&gt;  var downloader = _control.createObject('downloader');&lt;br /&gt;  token1 = downloader.addEventListener('downloadProgressChanged',&lt;br /&gt;    downloadProgressChanged);&lt;br /&gt;  token2 = downloader.addEventListener('completed', downloadCompleted);&lt;br /&gt;  downloader.open('GET', 'Assets/AutoPhotos.zip');&lt;br /&gt;  downloader.send();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function downloadProgressChanged(sender, args)&lt;br /&gt;{&lt;br /&gt;  // Update the progress bar&lt;br /&gt; _progressBar.width = _progressBarWidth * sender.downloadProgress;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function downloadCompleted(sender, args)&lt;br /&gt;{&lt;br /&gt;  // Hide the progress bar&lt;br /&gt;  progressBarCanvas.visibility = 'Collapsed';&lt;br /&gt;&lt;br /&gt;  // Deregister downloader event handlers&lt;br /&gt;  sender.removeEventListener('downloadProgressChanged', _token1);&lt;br /&gt;  sender.removeEventListener('completed', _token2);&lt;br /&gt;&lt;br /&gt;  // Create XAML images and assign downloaded bits to them&lt;br /&gt;  var canvas = sender.findName('AutoCanvas');&lt;br /&gt;&lt;br /&gt;  for (i=0; i&lt;_photos; i++)&lt;br /&gt;  {&lt;br /&gt;    var xaml =&lt;br /&gt;      '&lt;Image Canvas.Left="225" Width="450" Visibility="Collapsed" /&gt;';&lt;br /&gt;    var image = _control.content.createFromXaml(xaml);&lt;br /&gt;    image.setSource(sender, (i + 1).toString() + '.JPG');&lt;br /&gt;    canvas.children.add(image);&lt;br /&gt;    images[i] = image;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  // Register mousewheel event handler&lt;br /&gt;  if (window.addEventListener)&lt;br /&gt;    window.addEventListener('DOMMouseScroll', onMouseWheelTurned, false);&lt;br /&gt;  else&lt;br /&gt;    window.onmousewheel = document.onmousewheel = onMouseWheelTurned;&lt;br /&gt;        &lt;br /&gt;  // Make the first image visible&lt;br /&gt;  images[0].visibility = 'Visible';&lt;br /&gt;&lt;br /&gt;  // Start rotating&lt;br /&gt;  timer.begin();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function onTick(sender, args)&lt;br /&gt;{&lt;br /&gt;  // Hide the current image&lt;br /&gt;  images[_index].visibility = 'Collapsed';&lt;br /&gt;&lt;br /&gt;  // Update the image index&lt;br /&gt;  if (++_index == _photos)&lt;br /&gt;    index = 0; // Wrap around&lt;br /&gt;&lt;br /&gt;  // Show the new image&lt;br /&gt;    images[_index].visibility = 'Visible';    &lt;br /&gt;&lt;br /&gt;  // Restart the timer&lt;br /&gt;  timer.begin();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function onMouseWheelTurned(event)&lt;br /&gt;{&lt;br /&gt;  var delta = 0;&lt;br /&gt;  if (!event) // Internet Explorer&lt;br /&gt;    event = window.event;&lt;br /&gt;&lt;br /&gt;  if (event.wheelDelta) // Internet Explorer&lt;br /&gt;  {&lt;br /&gt;    delta = event.wheelDelta;&lt;br /&gt;    if (window.opera)&lt;br /&gt;      delta = -delta;&lt;br /&gt;  }&lt;br /&gt;  else if (event.detail) // Mozilla&lt;br /&gt;    delta = -event.detail;&lt;br /&gt;&lt;br /&gt;  if (delta != 0)&lt;br /&gt;  {&lt;br /&gt;    if (delta &gt; 0)&lt;br /&gt;    {&lt;br /&gt;      // Zoom in&lt;br /&gt;      zoom = Math.min(2, _zoom + 0.05);&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;    {&lt;br /&gt;      // Zoom out&lt;br /&gt;      zoom = Math.max(1, _zoom - 0.05);&lt;br /&gt;    }&lt;br /&gt;    transform.scaleX = _transform.scaleY = _zoom;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  if (event.preventDefault)&lt;br /&gt;    event.preventDefault();&lt;br /&gt;&lt;br /&gt;  event.returnValue = false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; Figure 4 RevolvingAuto Application—Scene.xaml&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;&lt;Canvas&lt;br /&gt;  xmlns="http://schemas.microsoft.com/client/2007"&lt;br /&gt;  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&lt;br /&gt;  Loaded="onLoaded"&gt;&lt;br /&gt;  &lt;Canvas x:Name="ProgressBarCanvas"&lt;br /&gt;    Canvas.Left="260" Canvas.Top="100"&gt;&lt;br /&gt;    &lt;Rectangle x:Name="ProgressBarContainer" Canvas.Left="0"&lt;br /&gt;      Canvas.Top="0" Width="380" Height="12" Stroke="#606060" /&gt;&lt;br /&gt;    &lt;Rectangle x:Name="ProgressBar" Canvas.Left="2" Canvas.Top="2"&lt;br /&gt;      Width="0" Height="8" Fill="#303030" /&gt;&lt;br /&gt;  &lt;/Canvas&gt;&lt;br /&gt;  &lt;Canvas x:Name="AutoCanvas"&gt;&lt;br /&gt;    &lt;Canvas.Resources&gt;&lt;br /&gt;      &lt;Storyboard x:Name="TimerStoryboard" Duration="0:0:0.2"&lt;br /&gt;        Completed="onTick" /&gt;&lt;br /&gt;    &lt;/Canvas.Resources&gt;&lt;br /&gt;    &lt;Canvas.RenderTransform&gt;&lt;br /&gt;      &lt;ScaleTransform x:Name="ZoomTransform" CenterX="450" /&gt;&lt;br /&gt;    &lt;/Canvas.RenderTransform&gt;&lt;br /&gt;  &lt;/Canvas&gt;&lt;br /&gt;&lt;/Canvas&gt;&lt;br /&gt;&lt;br /&gt;It's always advisable to keep XAML files as small as possible to reduce the application's load time. And it's no slower. (Parsing XML is, after all, not an inexpensive proposition.) Anytime you find yourself declaring XAML objects repetitively, consider using CreateFromXaml instead.&lt;br /&gt;&lt;br /&gt;For Accessibility, Support Interactive Zooms&lt;br /&gt;"Section 508" is a buzzword in usability circles these days and for good reason: it spells out U.S. Federal requirements for making software accessible to people with disabilities. If you haven't been asked about 508 compliance yet, just wait—if you live in the U.S., you'll need to know about it and probably sooner than you think. (For details regarding Section 508, see section508.gov.)&lt;br /&gt;Section 508 covers a lot of ground, from requiring that information conveyed by color coding also be accessible by means other than color coding (for example, through labels or popup tooltips) to imposing upper and lower limits on the frequency of page flicker. Strangely enough, it doesn't specify a minimum font size to aid vision-impaired users. Text size strikes close to home for me, because I've reached an age where I have to use reading glasses to read small print. That's why I often go ahead and build a zoom feature into the Silverlight apps that I author. Fortunately, Silverlight makes my job very easy.&lt;br /&gt;Silverlight ScaleTransforms can be used to scale any XAML object, including Canvas objects containing other objects. Implementing interactive zooms is as simple as declaring a ScaleTransform and modifying its ScaleX and ScaleY properties in response to mouse-wheel actions or other events. To scale the entire Silverlight display, simply apply the ScaleTransform to the root Canvas.&lt;br /&gt;When RevolvingAuto's home page first appears, the rotating automobile images are relatively small. However, you can enlarge the display up to two times by rolling the mouse wheel (see Figure 6). The key code is found in the onMouseWheelTurned function in Figure 6 (Default.html.js). It does some work to account for differences in the way browsers report mouse-wheel events and then increments or decrements the ScaleX and ScaleY properties of a ZoomTransform.&lt;br /&gt;Figure 6 RevolvingAuto before and after Zooming (Click the image for a larger view)&lt;br /&gt;Observe that you don't lose resolution when you zoom in on the rotating car. That's because the downloaded images are twice the size of the Image objects that they're assigned to. As you zoom, the ScaleTransform increases the dimensions of the currently displayed Image object, allowing the Image object more real estate to display the information available to it.&lt;br /&gt;&lt;br /&gt;Use Storyboards for Manual Animations&lt;br /&gt;One of the coolest features of Silverlight is its rich support for animations. You can make objects fade in and out, zoom across the page, and pop in and out of view with a few lines of XAML. But you can't animate just anything, at least not declaratively. You can easily animate numeric properties, Color properties, and Point properties. But if you want to, say, animate an image by varying its Source property over time (swapping one image for another on each tick), you'll have to write some code, and the way you structure that code will affect the quality of the animation.&lt;br /&gt;Silverlight 1.0 lacks an explicit timer object, and window.setTimeout is less than ideal for animations. That's why savvy Silverlight developers use Storyboard objects when they need programmable timers. All you have to do is declare an empty Storyboard object in XAML and designate a handler for its completed event, like so:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;&lt;Storyboard x:Name="Timer"&lt;br /&gt;  Duration="0:0:0.05"&lt;br /&gt;  Completed="onTick"&gt;&lt;br /&gt;&lt;/Storyboard&gt;&lt;br /&gt;&lt;br /&gt;When you're ready to start the animation, you call the Storyboard's begin method:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;_timer.begin();&lt;br /&gt;&lt;br /&gt;Finally, in the Completed event handler, do whatever you need to do (for example, modify an Image object's Source property) and call begin to start the timer running again:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;function onTick(sender, args)&lt;br /&gt;{&lt;br /&gt;    // TODO: Do work&lt;br /&gt;    _timer.begin();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In this example, _timer is a variable that refers to the XAML Storyboard object named "Timer."&lt;br /&gt;This is precisely the technique that RevolvingAuto uses to render revolving animations. The onTick function in Figure 5, which is called in response to Storyboard.Completed events, advances the animation one frame by turning the previous image's Visibility property off (Collapsed) and the next image's Visibility property on (Visible).&lt;br /&gt;&lt;br /&gt;Use the Tag Property to Store Per-Object Data&lt;br /&gt;Every XAML object that a Silverlight application creates has a read/write property named Tag that can be used to store user-defined strings. The Tag property provides a powerful and easy-to-use means for associating arbitrary data with XAML objects.&lt;br /&gt;Members of my team and I have used Tag in a variety of ways. In one project whose requirements included giving the user the ability to search through content rendered by Silverlight, we embedded keywords in the page's XAML objects and built a search feature that scanned the XAML from top to bottom inspecting each object's Tag property. In another instance, we used Tag to include metadata in our XAML elements. At run time we used the metadata, which was stored in the form of name/value pairs, to build more complex XAML around the XAML elements in the XAML document. A designer building content for our application could, for example, declare an Image object this way:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;&lt;Image Source="ProductDemo.jpg"&lt;br /&gt;  Tag="Mode:Lightbox" /&gt;&lt;br /&gt;&lt;br /&gt;Our application would see "Mode:Lightbox" and wrap a lightbox around the image, enabling users to zoom in and out, pan around the image, and more.&lt;br /&gt;One very pragmatic use for the Tag property is as a means for attaching descriptions to images. Imagine a canvas containing hundreds of images, accompanied by a requirement to pop up an image description when the cursor hovers over one. You could use the Tag property to attach descriptions to each image and read the Tag property of the image under the cursor prior to popping up a description.&lt;br /&gt;&lt;br /&gt;Use ASP.NET AJAX for Server Callbacks&lt;br /&gt;Developers sometimes bemoan the fact that Silverlight 1.0 has such a limited networking stack. Other than the downloader object, version 1.0 offers little in terms of networking. This will change in Silverlight 2.0, which will have a rich, multiprotocol networking stack. Until then, however, you can use ASP.NET AJAX to fire off calls from a browser hosting a Silverlight application to the server.&lt;br /&gt;The Silverlight viewer in the MyComix comic-cataloging application I recently published offers a concrete example. To see for yourself, type in the URL mycomix.wintellect.com/Spotlight.aspx?Item=1166 and wait for a comic book cover to appear. Then move the cursor into the upper part of the window; an info panel will slide into view to display information about the comic, including its title, issue number, grade, and year of publication. The data in the panel comes from a database stored on the server, and it's retrieved by calling an ASP.NET AJAX Web service.&lt;br /&gt;The Web service, MyComix.asmx, exposes a method named GetComicInfo that accepts a comic ID as an input parameter and returns a ComicInfo object containing all the information available regarding the comic. (An ASP.NET AJAX Web service is basically a conventional ASMX with the Web service class attributed ScriptService rather than WebService.) The viewer page declares a reference to the Web service like this:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;&lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;&lt;br /&gt;    &lt;Services&gt;&lt;br /&gt;        &lt;asp:ServiceReference Path="~/MyComix.asmx" /&gt;&lt;br /&gt;    &lt;/Services&gt;&lt;br /&gt;&lt;/asp:ScriptManager&gt;&lt;br /&gt;&lt;br /&gt;Then, it fires an asynchronous call to the Web service's GetComicInfo method, as shown here:&lt;br /&gt;Copy Code&lt;br /&gt;&lt;br /&gt;MyComixScriptService.GetComicInfo(_id, OnGetComicInfoCompleted);&lt;br /&gt;&lt;br /&gt;The call is extremely efficient on the wire because it uses JavaScript Object Notation (JSON) encoding and because no view state or other unnecessary data is transmitted. And because the call is asynchronous, the browser doesn't freeze up waiting for it to complete. If the user displays the info panel before the call returns, the panel simply shows up empty.&lt;br /&gt;You can download the MyComix source code, including the ASP.NET AJAX Web service, from wintellect.com/Downloads/MyComix.zip. The Silverlight viewer can be found in the files that are named Spotlight.aspx and Spotlight.xaml.&lt;br /&gt;As you're playing around with Silverlight you may find you have best practices of your own and would like to add them to those presented here. If so, shoot me some e-mail at wicked@microsoft.com. Meanwhile, happy Silverlight developing!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-2036239102136597279?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/2036239102136597279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=2036239102136597279' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/2036239102136597279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/2036239102136597279'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/05/silverlight-tips-tricks-and-best.html' title='Silverlight Tips, Tricks, and Best Practices'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-7751340547347066874</id><published>2008-04-16T00:21:00.001-05:00</published><updated>2008-04-16T00:21:26.375-05:00</updated><title type='text'>The Ten Commandments for C Programmers</title><content type='html'>Henry Spencer &lt;br /&gt;1. &lt;br /&gt;Thou shalt run lint frequently and study its pronouncements with care, for verily its perception and judgement oft exceed thine. &lt;br /&gt;2. &lt;br /&gt;Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end. &lt;br /&gt;3. &lt;br /&gt;Thou shalt cast all function arguments to the expected type if they are not of that type already, even when thou art convinced that this is unnecessary, lest they take cruel vengeance upon thee when thou least expect it. &lt;br /&gt;4. &lt;br /&gt;If thy header files fail to declare the return types of thy library functions, thou shalt declare them thyself with the most meticulous care, lest grievous harm befall thy program. &lt;br /&gt;5. &lt;br /&gt;Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. &lt;br /&gt;6. &lt;br /&gt;If a function be advertised to return an error code in the event of difficulties, thou shalt check for that code, yea, even though the checks triple the size of thy code and produce aches in thy typing fingers, for if thou thinkest ``it cannot happen to me'', the gods shall surely punish thee for thy arrogance. &lt;br /&gt;7. &lt;br /&gt;Thou shalt study thy libraries and strive not to re-invent them without cause, that thy code may be short and readable and thy days pleasant and productive. &lt;br /&gt;8. &lt;br /&gt;Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. &lt;br /&gt;9. &lt;br /&gt;Thy external identifiers shall be unique in the first six characters, though this harsh discipline be irksome and the years of its necessity stretch before thee seemingly without end, lest thou tear thy hair out and go mad on that fateful day when thou desirest to make thy program run on an old system. &lt;br /&gt;10. &lt;br /&gt;Thou shalt foreswear, renounce, and abjure the vile heresy which claimeth that ``All the world's a VAX'', and have no commerce with the benighted heathens who cling to this barbarous belief, that the days of thy program may be long even though the days of thy current machine be short.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-7751340547347066874?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/7751340547347066874/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=7751340547347066874' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/7751340547347066874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/7751340547347066874'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/04/ten-commandments-for-c-programmers.html' title='The Ten Commandments for C Programmers'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-4632772507079162906</id><published>2008-04-08T10:20:00.000-05:00</published><updated>2008-04-08T10:23:27.204-05:00</updated><title type='text'>Java API Design Guidelines</title><content type='html'>by Eamonn McManus&lt;br /&gt;December 28, 2005&lt;br /&gt;&lt;br /&gt;Summary&lt;br /&gt;There are tons of books and articles about how to design and write good Java code, but surprisingly little about the specific topic of API design. Here's a summary of what I've learnt on the subject from various sources and my own experience. &lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;Advertisement &lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;I recently attended an excellent talk at JavaPolis, Elliotte Rusty Harold's XOM Design Principles. Although the talk is nominally about XOM (an API for XML documentation manipulation), in fact more than half of it is about API design principles in general. This is a curiously neglected subject. There are tons of books and articles about how to design and write good Java code, but surprisingly little about the specific topic of API design. Yet with the proliferation of new Java APIs, whether through JSRs or through Open Source projects, this is an increasingly important subject.&lt;br /&gt;&lt;br /&gt;I've been closely involved with the evolution of the JMX API for over five years and have learnt a great deal about what works and what doesn't during that time. During the talk, I had the odd experience of continually wanting to cheer as Elliotte made point after point that I hugely agreed with.&lt;br /&gt;&lt;br /&gt;I'm going to try to summarize here what I see as being the key points from this talk, from my own experience, and from a couple of other sources:&lt;br /&gt;&lt;br /&gt;An excellent tutorial on netbeans.org, How to Design a (module) API. &lt;br /&gt;A related NetBeans BOF at JavaOne 2005 by Tim Boudreau and Jaroslav Tulach, entitled How to write APIs that will stand the test of time. &lt;br /&gt;Of course, Josh Bloch's Effective Java book. &lt;br /&gt;[Update: Although I was unaware of it when writing this blog entry, the slides referenced by Josh Bloch in a comment here cover some of the same ground and add much of interest.]&lt;br /&gt;&lt;br /&gt;Design to evolve&lt;br /&gt;If your API is worth anything, it will evolve over time. You should plan for this from the outset. A key part of the planning is to decide what sort of compatibility you will guarantee between revisions.&lt;br /&gt;&lt;br /&gt;The best approach is to say that once something is in the API it will stay there and it will continue to work. Tweaking the API incompatibly between revisions will result in user reactions ranging from annoyance to murderous rage. The problem is particularly severe if your API ends up being used by different modules that are part of the same application. If Module 1 uses Commons Banana 1.0 and Module 2 uses Commons Banana 2.0 then life will be a whole lot easier if 2.0 is completely compatible with 1.0. Otherwise your users risk wasting huge amounts of time tweaking classpaths in a futile endeavour to make things work. They might end up having to play mind-destroying games with class-loaders, which is a clear signal that you have failed.&lt;br /&gt;&lt;br /&gt;For APIs that are part of Java SE, we have an extreme form of compatibility. The aim is that no code whatsoever should break when you update from one version to the next. This means that classes and methods are never removed. It also means that we try to avoid changes that might break code that was depending on certain implementation details, even if the code shouldn't have been doing that.&lt;br /&gt;&lt;br /&gt;The no-code-breakage rule applies to already-compiled code (binary compatibility). In some rare circumstances we might make changes that mean some existing code no longer compiles (source compatibility). For example, adding an overloaded method or constructor can sometimes produce ambiguity errors from the compiler when a parameter is null. We do try to find a way to avoid changes that break source compatibility in this way, but sometimes the best approach does imply that some source code might stop compiling. As an example, in Java SE 6 the constructors for javax.management.StandardMBean have been generified. Some existing source code might conceivably stop compiling because it does not respect the constraints that are expressed using generics here, but that code is easily fixed by adding a cast, and the rare cases where that happens are outweighed by cases where the constraints will catch programming errors at compile time.&lt;br /&gt;&lt;br /&gt;In general, you can't know what users of your API will do with it. When contemplating a change that might break existing code, you have to reason conservatively. Only if you can honestly say that it is next to impossible that a change will break code can you reasonably make it. You should certainly rule out completely a signature change, which basically means removing or renaming a visible method or class or changing the parameters of a visible method. (But you can remove a method if it overrides a method in a parent class without changing the parent method's semantics.)&lt;br /&gt;&lt;br /&gt;Since the very earliest versions of your API are sure to have many mistakes in them, and you don't want to freeze those mistakes for all time, it's a good idea to bring out one or more 0.x versions before the 1.0 version. Users of these versions know that the API is unstable and won't curse you if it changes. Once you've brought out 1.0 you're committing to compatibility. For APIs that are developed through the JCP, these 0.x versions correspond to the phases before the final release (Early Draft Review, Public Review, Proposed Final Draft). If possible, it's a good idea to make an implementation of the API available at the same time as these intermediate specifications.&lt;br /&gt;&lt;br /&gt;If at some stage you decide that there's really too much accumulated cruft from previous versions and you want to start over, then create a new API with different package names. Then code that uses the old version and code that uses the new version can co-exist easily.&lt;br /&gt;&lt;br /&gt;API design goals&lt;br /&gt;What should the design goals of your API be? Apart from compatibility, the following goals from Elliotte's presentation seem like an excellent set:&lt;br /&gt;&lt;br /&gt;It must be absolutely correct. In the case of XOM, this meant that the API could never produce malformed XML documents no matter what the caller did. For the JMX API, for example, it means that you can never get the MBean Server into an inconsistent state by registering strange MBeans in it or using funny ObjectNames or performing several operations concurrently. &lt;br /&gt;It must be easy to use. This is hard to quantify. A good way to get an idea is to write lots of example code. Are there groups of operations that you keep having to repeat? Do you have to keep looking up your own API because you forget what things are called? Are there cases where the API doesn't do what you might expect? &lt;br /&gt;It must be easy to learn. This overlaps considerably with ease of use. But there are some obvious principles to make learning easier. The smaller the API, the less there is to learn. Documentation should include examples. Where appropriate, the API should look like familiar APIs. &lt;br /&gt;It must be fast enough. Elliotte was careful to put this in the list after the above items. Make sure the API is simple and correct. Then think about performance. You might be inclined to make API changes because the original API could only be implemented in an inefficient way. By all means change it to allow a more efficient implementation, provided you don't compromise correctness or simplicity. Don't rely on your intuition to know what performs well. Measure. Then tweak the API if you've determined that it really matters. &lt;br /&gt;It must be small enough. This covers the size of the compiled code and especially the amount of memory it needs as it runs. The same principles as for speed apply. Make it simple and correct first; measure; and only then think about tweaking the API. &lt;br /&gt;Be minimalist&lt;br /&gt;Because of the compatibility requirement, it's much easier to put things in than to take them out. So don't add anything to the API that you're not sure you need.&lt;br /&gt;&lt;br /&gt;There's an approach to API design which you see depressingly often. Think of everything a user could possibly want to do with the API and add a method for it. Toss in protected methods so users can subclass to tweak every aspect of your implementation. Why is this bad?&lt;br /&gt;&lt;br /&gt;The more stuff there is in the API, the harder it is to learn. Which classes and methods are the important ones? Which of the five different ways to do what I need is the best?&lt;br /&gt;&lt;br /&gt;The situation is exacerbated by the Javadoc tool, which dumps all the classes in a package, and all the methods in a class, in an undifferentiated lump. We can expect that JSR 260 will update the Javadoc tool to allow you to produce "views" of the API, and in that case fatter APIs will not be so overwhelming.&lt;br /&gt;&lt;br /&gt;The bigger the API, the more things can go wrong. The implementation isn't going to be perfect, but the same investment in coding and testing will yield better results for a smaller API.&lt;br /&gt;&lt;br /&gt;If your API has more methods than it needs, then it's taking up more space than it needs.&lt;br /&gt;&lt;br /&gt;The right approach is to base the API on example code. Think of problems a user might want to solve with the API. Add just enough classes and methods to solve those problems. Code the solutions. Remove anything from the API that your examples don't need. This allows you to check that the API is useful. As a happy side-effect, it gives you some basic tests. And you can (and should) share the examples with your users.&lt;br /&gt;&lt;br /&gt;Interfaces are overvalued&lt;br /&gt;There's a certain style of API design that's very popular in the Java world, where everything is expressed in terms of Java interfaces (as opposed to classes). Interfaces have their place, but it is basically never a good idea for an entire API to be expressed in terms of them. A type should only be an interface if you have a good reason for it to be. Here's why:&lt;br /&gt;&lt;br /&gt;Interfaces can be implemented by anybody. Suppose String were an interface. Then you could never be sure that a String you got from somewhere obeyed the semantics you expect: it is immutable; its hashCode() is computed in a certain way; its length is never negative; and so on. Code that used String, whether user code or code from the rest of the J2SE platform, would have to go to enormous lengths to ensure it was robust in the face of String implementations that were accidentally incorrect. And to even further lengths to ensure that its security could not be compromised by deliberately evil String implementations.&lt;br /&gt;&lt;br /&gt;In practice, implementations of APIs that are defined entirely in terms of interfaces often end up cheating and casting objects to the non-public implementation class. DOM typically does this for example. So you can't give your own implementation of the DocumentType interface as a parameter to DOMImplementation.createDocument and expect it to work. Then what's the point in having interfaces?&lt;br /&gt;&lt;br /&gt;Interfaces cannot have constructors or static methods. If you need an instance of an interface, you either have to implement it yourself, or you have to ask some other object for it. If Integer were an interface, then to get the Integer for a given int you could no longer use the obvious new Integer(n) (or, less obvious but still documented inside Integer, Integer.valueOf(n)). You would have to use IntegerFactory.newInteger(n) or whatever. This makes your API harder to understand and use.&lt;br /&gt;&lt;br /&gt;Interfaces cannot evolve. Suppose you add a new method to an interface in version 2 of your API. Then user code that implemented the interface in version 1 will no longer compile because it doesn't implement the new method. You can still preserve binary compatibility by catching AbstractMethodError around calls to the new method but that is clunky. If you use an abstract class instead of an interface you don't have this problem. If you tell users not to implement the interface then you don't have this problem either, but then why is it an interface?&lt;br /&gt;&lt;br /&gt;Interfaces cannot be serialized. Java serialization has its problems, but you can't always get away from it. The JMX API relies heavily on serialization, for example. For better or worse, the way serialization works is that the name of the actual implementation class is serialized, and an instance of that exact same class is reconstructed at deserialization. If the implementation class is not a public class in your API, then you won't interoperate with other implementations of your API, and it will be very hard for you to ensure that you even interoperate between different versions of your own implementation. If the implementation class is a public class in your API, then do you really need the interface as well?&lt;br /&gt;&lt;br /&gt;Of course, there are sometimes good reasons for a type to be interface. Here are some common ones:&lt;br /&gt;&lt;br /&gt;Callbacks. If the interface is intended to be implemented by user code, then it is often more appropriate than an abstract class. See Runnable for example. This is mostly true of interfaces with just one method. Once there start being several methods you often find that an implementation class only needs to do something in one of them, and it's annoying to have to implement all the others. Furthermore if an interface has three methods today then you might want it to have four tomorrow, which is not usually possible as we saw. An abstract class can avoid these problems.&lt;br /&gt;&lt;br /&gt;Multiple inheritance. It is occasionally useful to be able to implement an interface deep in the inheritance hierarchy. A good example is Comparable, where for example Integer is Comparable but its parent class Number is not. However, there aren't many other good examples of this in the core Java classes. It is usually bad practice to implement some random interface in a class whose primary purpose is something else. Implementing the interface in a private inner class is usually cleaner, and then of course it could just as well be an abstract class.&lt;br /&gt;&lt;br /&gt;Dynamic proxies. The invaluable java.lang.reflect.Proxy class allows you to make an implementation of any interface at runtime, where calling any of the interface's methods results in a call to a single invoke method. There's no way to construct a dynamic proxy for an abstract class, so if you think it will be useful for users to make dynamic proxies that is one reason to favour an interface. (cglib can sometimes be used to achieve the same effect for abstract classes, but with several limitations, plus the documentation is really poor.)&lt;br /&gt;&lt;br /&gt;Be careful with packages&lt;br /&gt;The Java language has fairly limited ways of controlling the visibility of classes and methods. In particular, if a class or method is visible outside its package, then it is visible to all code in all packages. This means that if you define your API in several packages, you have to be careful to avoid being forced to make things public just so that code in other packages in the API can access them.&lt;br /&gt;&lt;br /&gt;The simplest solution to avoid this is to put your whole API in one package. For an API with fewer than about 30 public classes this is usually the best approach.&lt;br /&gt;&lt;br /&gt;If your API is too big for a single package to be appropriate, then you should plan to have private implementation packages. That is, some packages in your implementation are excluded from the Javadoc output and are not part of the public API, even though their contents are accessible. If you look at the JDK, for example, there are many sun.* and com.sun.* packages of this sort. Users who rely on the Javadoc output will not know of their existence. Users who browse the source code can see them, and can access the public classes and methods, but they are discouraged from doing so and warned that there is no guarantee that these classes will remain unchanged across revisions.&lt;br /&gt;&lt;br /&gt;A good convention for private packages is to put internal in the name. So the Banana API might have public packages com.example.banana and com.example.banana.peel plus private packages com.example.banana.internal and com.example.banana.internal.peel.&lt;br /&gt;&lt;br /&gt;Don't forget that the private packages are accessible. There may be security implications if arbitrary code can access these internals. Various techniques exist to address these. The NetBeans API tutorial describes one. In the JMX API, we use another. There is a class javax.management.JMX which contains only static methods and has no public constructor. This means that user code can never have an instance of this class. So in the private com.sun.jmx packages, we sometimes add a parameter of type JMX to sensitive public methods. If a caller can supply a non-null instance of this class, it must be coming from the javax.management package.&lt;br /&gt;&lt;br /&gt;Other random tips&lt;br /&gt;Here are some other random tips based on our experience with the JMX API and on the sources I mentioned.&lt;br /&gt;&lt;br /&gt;Immutable classes are good. If a class can be immutable, then it should be. Rather than spelling out the reasons, I'll refer you to Item 13 in Effective Java. You wouldn't think of designing an API without having this book, right?&lt;br /&gt;&lt;br /&gt;The only visible fields should be static and final. Again this one is pretty banal and I mention it only because certain early APIs in the core platform violated it. Not an example to follow.&lt;br /&gt;&lt;br /&gt;Avoid eccentricity. There are many well-established conventions for Java code, with regard to identifier case, getters and setters, standard exception classes, and so on. Even if you think these conventions could have been better, don't replace them in your API. By doing so you force users to throw away what they already know and learn a new way of doing an old thing.&lt;br /&gt;&lt;br /&gt;For instance, don't follow the bad example of java.nio and java.lang.ProcessBuilder where the time-honoured T getThing() and void setThing(T) methods are replaced by T thing() and ThisClass thing(T). Some people think this is neato-keen and others that it is an abomination, but either way it's not a well-known idiom so don't force your users to learn it.&lt;br /&gt;&lt;br /&gt;Don't implement Cloneable. It is usually less useful than you might think to create a copy of an object. If you do need this functionality, rather than having a clone() method it's generally a better idea to define a "copy constructor" or static factory method. So for example class Banana might have a constructor or factory method like this:&lt;br /&gt;&lt;br /&gt;      public Banana(Banana b) {      // copy constructor&lt;br /&gt;       this(b.colour, b.length);&lt;br /&gt;      }&lt;br /&gt;      // ...or...&lt;br /&gt;      public static Banana newInstance(Banana b) {&lt;br /&gt;       return new Banana(b.colour, b.length);&lt;br /&gt;      }&lt;br /&gt;    &lt;br /&gt;The advantage of the constructor is that it can be called from a subclass's constructor. The advantage of the static method is that it can return an instance of a subclass or an already-existent instance.&lt;br /&gt;&lt;br /&gt;Item 10 of Effective Java covers clone() in excruciating detail.&lt;br /&gt;&lt;br /&gt;Exceptions should usually be unchecked. Item 41 of Effective Java gives an excellent summary here. Use a checked exception "if the exceptional condition cannot be prevented by proper use of the API and the programmer using the API can take some useful action once confronted with the exception." In practice this usually means that a checked exception reflects a problem in interaction with the outside world, such as the network, filesystem, or windowing system. If the exception signals that parameters are incorrect or than an object is in the wrong state for the operation you're trying to do, then an unchecked exception (subclass of RuntimeException) is appropriate.&lt;br /&gt;&lt;br /&gt;Design for inheritance or don't allow it. Item 15 of Effective Java tells you all you might want to know about this. The summary is that every method should be final by default (perhaps by virtue of being in a final class). Only if you can clearly document what happens if you override the method should it be possible to do so. And you should only do that if you have coded useful examples that do override the method.&lt;br /&gt;&lt;br /&gt;Summary&lt;br /&gt;Design to evolve. &lt;br /&gt;Correctness, then simplicity, then efficiency. &lt;br /&gt;Interfaces are overvalued. &lt;br /&gt;Be careful with packages. &lt;br /&gt;Read Effective Java.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-4632772507079162906?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/4632772507079162906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=4632772507079162906' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/4632772507079162906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/4632772507079162906'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/04/java-api-design-guidelines.html' title='Java API Design Guidelines'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-2307223678456854926</id><published>2008-04-04T05:17:00.001-05:00</published><updated>2008-04-04T05:19:19.598-05:00</updated><title type='text'>SQL Server TSQL Coding Conventions, Best Practices, and Programming Guidelines</title><content type='html'>Databases are the heart and soul of many enterprise applications, and it is very essential to pay special attention to database programming. I've seen in many occasions where database programming is overlooked, thinking that it's something easy that be done by anyone. This is wrong.&lt;br /&gt;&lt;br /&gt;For a better performing database you need a real DBA and a specialist database programmer, let it be for Microsoft SQL Server, Oracle, Sybase, DB2 or whatever! If you don't use database specialists during your development cycle, databases often end up becoming the performance bottleneck. I decided to write this article in order to put together some of the database programming best practices so that my fellow DBAs and database developers can benefit!&lt;br /&gt;&lt;br /&gt;Here are some programming guidelines and best practices, keeping quality, performance and maintainability in mind. This list many not be complete at this moment, and will be constantly updated. BTW, special thanks to Tibor Karaszi (SQL Server MVP) and Linda (lindawie) for taking time to read this article and providing suggestions.&lt;br /&gt;&lt;br /&gt;Decide upon a database naming convention, standardize it across your organization, and be consistent in following it. It helps make your code more readable and understandable. Click here to see the database object naming convention that I follow.&lt;br /&gt;&lt;br /&gt;Make sure you normalize your data at least to the 3rd normal form. At the same time, do not compromise on query performance. A little bit of denormalization helps queries perform faster.&lt;br /&gt;&lt;br /&gt;Write comments in your stored procedures, triggers and SQL batches generously, whenever something is not very obvious. This helps other programmers understand your code clearly. Don't worry about the length of the comments, as it won't impact the performance, unlike interpreted languages like ASP 2.0.&lt;br /&gt;&lt;br /&gt;Do not use SELECT * in your queries. Always write the required column names after the SELECT statement, like: SELECT CustomerID, CustomerFirstName, City&lt;br /&gt;This technique results in reduced disk I/O and better performance.&lt;br /&gt;&lt;br /&gt;Try to avoid server side cursors as much as possible. Always stick to a 'set-based approach' instead of a 'procedural approach' for accessing and manipulating data. Cursors can often be avoided by using SELECT statements instead.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;articles &gt;&gt; developer &gt;&gt; SQL Server TSQL Coding Conventions, Best Practices, ... SQL Server TSQL Coding Conventions, Best Practices, and Programming GuidelinesBy : Vyas Kondreddi&lt;br /&gt;May 10, 2001 Printer friendly  &lt;br /&gt;&lt;br /&gt;Databases are the heart and soul of many enterprise applications, and it is very essential to pay special attention to database programming. I've seen in many occasions where database programming is overlooked, thinking that it's something easy that be done by anyone. This is wrong.&lt;br /&gt;&lt;br /&gt;For a better performing database you need a real DBA and a specialist database programmer, let it be for Microsoft SQL Server, Oracle, Sybase, DB2 or whatever! If you don't use database specialists during your development cycle, databases often end up becoming the performance bottleneck. I decided to write this article in order to put together some of the database programming best practices so that my fellow DBAs and database developers can benefit!&lt;br /&gt;&lt;br /&gt;Here are some programming guidelines and best practices, keeping quality, performance and maintainability in mind. This list many not be complete at this moment, and will be constantly updated. BTW, special thanks to Tibor Karaszi (SQL Server MVP) and Linda (lindawie) for taking time to read this article and providing suggestions.&lt;br /&gt;&lt;br /&gt;Decide upon a database naming convention, standardize it across your organization, and be consistent in following it. It helps make your code more readable and understandable. Click here to see the database object naming convention that I follow.&lt;br /&gt;&lt;br /&gt;Make sure you normalize your data at least to the 3rd normal form. At the same time, do not compromise on query performance. A little bit of denormalization helps queries perform faster.&lt;br /&gt;&lt;br /&gt;Write comments in your stored procedures, triggers and SQL batches generously, whenever something is not very obvious. This helps other programmers understand your code clearly. Don't worry about the length of the comments, as it won't impact the performance, unlike interpreted languages like ASP 2.0.&lt;br /&gt;&lt;br /&gt;Do not use SELECT * in your queries. Always write the required column names after the SELECT statement, like: SELECT CustomerID, CustomerFirstName, City&lt;br /&gt;This technique results in reduced disk I/O and better performance.&lt;br /&gt;&lt;br /&gt;Try to avoid server side cursors as much as possible. Always stick to a 'set-based approach' instead of a 'procedural approach' for accessing and manipulating data. Cursors can often be avoided by using SELECT statements instead. If a cursor is unavoidable, use a WHILE loop instead. I have personally tested and concluded that a WHILE loop is always faster than a cursor. But for a WHILE loop to replace a cursor you need a column (primary key or unique key) to identify each row uniquely. I personally believe every table must have a primary or unique key. Click here to see some examples of using a WHILE loop.&lt;br /&gt;&lt;br /&gt;Avoid the creation of temporary tables while processing data as much as possible, as creating a temporary table means more disk I/O. Consider using advanced SQL, views, SQL Server 2000 table variable, or derived tables, instead of temporary tables.&lt;br /&gt;&lt;br /&gt;Try to avoid wildcard characters at the beginning of a word while searching using the LIKE keyword, as that results in an index scan, which defeats the purpose of an index. The following statement results in an index scan, while the second statement results in an index seek:&lt;br /&gt;&lt;br /&gt;SELECT LocationID FROM Locations WHERE Specialities LIKE '%pples'&lt;br /&gt;SELECT LocationID FROM Locations WHERE Specialities LIKE 'A%s' &lt;br /&gt;&lt;br /&gt;Also avoid searching using not equals operators (&lt;&gt; and NOT) as they result in table and index scans.&lt;br /&gt;&lt;br /&gt;Use 'Derived tables' wherever possible, as they perform better. Consider the following query to find the second highest salary from the Employees table:&lt;br /&gt;&lt;br /&gt;SELECT MIN(Salary) &lt;br /&gt;FROM Employees &lt;br /&gt;WHERE EmpID IN&lt;br /&gt;(&lt;br /&gt;SELECT TOP 2 EmpID &lt;br /&gt;FROM Employees &lt;br /&gt;ORDER BY Salary Desc&lt;br /&gt;) &lt;br /&gt;&lt;br /&gt;The same query can be re-written using a derived table, as shown below, and it performs twice as fast as the above query:&lt;br /&gt;&lt;br /&gt;SELECT MIN(Salary) &lt;br /&gt;FROM &lt;br /&gt;(&lt;br /&gt;SELECT TOP 2 Salary &lt;br /&gt;FROM Employees &lt;br /&gt;ORDER BY Salary DESC&lt;br /&gt;) AS A &lt;br /&gt;&lt;br /&gt;This is just an example, and your results might differ in different scenarios depending on the database design, indexes, volume of data, etc. So, test all the possible ways a query could be written and go with the most efficient one.&lt;br /&gt;&lt;br /&gt;While designing your database, design it keeping "performance" in mind. You can't really tune performance later, when your database is in production, as it involves rebuilding tables andindexes, re-writing queries, etc. Use the graphical execution plan in Query Analyzer or SHOWPLAN_TEXT or SHOWPLAN_ALL commands to analyze your queries. Make sure your queries do an "Index seek" instead of an "Index scan" or a "Table scan." A table scan or an index scan is a very bad thing and should be avoided where possible. Choose the right indexes on the right columns.&lt;br /&gt;&lt;br /&gt;Prefix the table names with the owner's name, as this improves readability and avoids any unnecessary confusion. Microsoft SQL Server Books Online even states that qualifying table names with owner names helps in execution plan reuse, further boosting performance.&lt;br /&gt;&lt;br /&gt;Use SET NOCOUNT ON at the beginning of your SQL batches, stored procedures and triggers in production environments, as this suppresses messages like '(1 row(s) affected)' after executing INSERT, UPDATE, DELETE and SELECT statements. This improves the performance of stored procedures by reducing network traffic.&lt;br /&gt;&lt;br /&gt;Use the more readable ANSI-Standard Join clauses instead of the old style joins. With ANSI joins, the WHERE clause is used only for filtering data. Where as with older style joins, the WHERE clause handles both the join condition and filtering data. The first of the following two queries shows the old style join, while the second one shows the new ANSI join syntax:&lt;br /&gt;&lt;br /&gt;SELECT a.au_id, t.title &lt;br /&gt;FROM titles t, authors a, titleauthor ta&lt;br /&gt;WHERE &lt;br /&gt;a.au_id = ta.au_id AND&lt;br /&gt;ta.title_id = t.title_id AND &lt;br /&gt;t.title LIKE '%Computer%'&lt;br /&gt;&lt;br /&gt;SELECT a.au_id, t.title&lt;br /&gt;FROM authors a &lt;br /&gt;INNER JOIN&lt;br /&gt;titleauthor ta &lt;br /&gt;ON &lt;br /&gt;a.au_id = ta.au_id&lt;br /&gt;INNER JOIN&lt;br /&gt;titles t&lt;br /&gt;ON&lt;br /&gt;ta.title_id = t.title_id&lt;br /&gt;WHERE t.title LIKE '%Computer%'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-2307223678456854926?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/2307223678456854926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=2307223678456854926' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/2307223678456854926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/2307223678456854926'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/04/sql-server-tsql-coding-conventions-best.html' title='SQL Server TSQL Coding Conventions, Best Practices, and Programming Guidelines'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-8312180783676950427</id><published>2008-04-01T00:36:00.001-05:00</published><updated>2008-04-01T00:36:40.645-05:00</updated><title type='text'>File Operations in perl</title><content type='html'>chmod(LIST)&lt;br /&gt;chmod LIST&lt;br /&gt;Changes the permissions of a list of files. The first element of the list must be the numerical mode. Returns the number of files successfully changed. &lt;br /&gt; $cnt = chmod 0755, 'foo', 'bar';&lt;br /&gt; chmod 0755, @executables;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;chown(LIST)&lt;br /&gt;chown LIST&lt;br /&gt;Changes the owner (and group) of a list of files. The first two elements of the list must be the NUMERICAL uid and gid, in that order. Returns the number of files successfully changed. &lt;br /&gt; $cnt = chown $uid, $gid, 'foo', 'bar';&lt;br /&gt; chown $uid, $gid, @filenames;&lt;br /&gt;&lt;br /&gt;Here's an example that looks up non-numeric uids in the passwd file: &lt;br /&gt; print "User: ";&lt;br /&gt; $user = &lt;STDIN&gt;;&lt;br /&gt; chop($user);&lt;br /&gt; print "Files: "&lt;br /&gt; $pattern = &lt;STDIN&gt;;&lt;br /&gt; chop($pattern);&lt;br /&gt; open(pass, '/etc/passwd')&lt;br /&gt;  || die "Can't open passwd: $!\n";&lt;br /&gt; while (&lt;pass&gt;) {&lt;br /&gt;  ($login,$pass,$uid,$gid) = split(/:/);&lt;br /&gt;  $uid{$login} = $uid;&lt;br /&gt;  $gid{$login} = $gid;&lt;br /&gt; }&lt;br /&gt; @ary = &lt;${pattern}&gt;; # get filenames&lt;br /&gt; if ($uid{$user} eq '') {&lt;br /&gt;  die "$user not in passwd file";&lt;br /&gt; }&lt;br /&gt; else {&lt;br /&gt;  chown $uid{$user}, $gid{$user}, @ary;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;link(OLDFILE,NEWFILE)&lt;br /&gt;Creates a new filename linked to the old filename. Returns 1 for success, 0 otherwise. &lt;br /&gt;&lt;br /&gt;lstat(FILEHANDLE)&lt;br /&gt;lstat FILEHANDLE &lt;br /&gt;lstat(EXPR)&lt;br /&gt;lstat SCALARVARIABLE&lt;br /&gt;Does the same thing as the stat() function, but stats a symbolic link instead of the file the symbolic link points to. If symbolic links are unimplemented on your system, a normal stat is done. &lt;br /&gt;&lt;br /&gt;mkdir(FILENAME,MODE)&lt;br /&gt;Creates the directory specified by FILENAME, with permissions specified by MODE (as modified by umask). If it succeeds it returns 1, otherwise it returns 0 and sets $! (errno). &lt;br /&gt;&lt;br /&gt;readlink(EXPR)&lt;br /&gt;readlink EXPR&lt;br /&gt;Returns the value of a symbolic link, if symbolic links are implemented. If not, gives a fatal error. If there is some system error, returns the undefined value and sets $! (errno). If EXPR is omitted, uses $_. &lt;br /&gt;&lt;br /&gt;rename(OLDNAME,NEWNAME)&lt;br /&gt;Changes the name of a file. Returns 1 for success, 0 otherwise. Will not work across filesystem boundaries. &lt;br /&gt;&lt;br /&gt;rmdir(FILENAME)&lt;br /&gt;rmdir FILENAME&lt;br /&gt;Deletes the directory specified by FILENAME if it is empty. If it succeeds it returns 1, otherwise it returns 0 and sets $! (errno). If FILENAME is omitted, uses $_. &lt;br /&gt;&lt;br /&gt;select(RBITS,WBITS,EBITS,TIMEOUT)&lt;br /&gt;This calls the select system call with the bitmasks specified, which can be constructed using fileno() and vec(), along these lines: &lt;br /&gt; $rin = $win = $ein = '';&lt;br /&gt; vec($rin,fileno(STDIN),1) = 1;&lt;br /&gt; vec($win,fileno(STDOUT),1) = 1;&lt;br /&gt; $ein = $rin | $win;&lt;br /&gt;&lt;br /&gt;If you want to select on many filehandles you might wish to write a subroutine: &lt;br /&gt; sub fhbits {&lt;br /&gt;     local(@fhlist) = split(' ',$_[0]);&lt;br /&gt;     local($bits);&lt;br /&gt;     for (@fhlist) {&lt;br /&gt;  vec($bits,fileno($_),1) = 1;&lt;br /&gt;     }&lt;br /&gt;     $bits;&lt;br /&gt; }&lt;br /&gt; $rin = &amp;fhbits('STDIN TTY SOCK');&lt;br /&gt;&lt;br /&gt;The usual idiom is: &lt;br /&gt; ($nfound,$timeleft) =&lt;br /&gt;   select($rout=$rin, $wout=$win, $eout=$ein, $timeout);&lt;br /&gt;&lt;br /&gt;or to block until something becomes ready: &lt;br /&gt; $nfound = select($rout=$rin, $wout=$win,&lt;br /&gt;    $eout=$ein, undef);&lt;br /&gt;&lt;br /&gt;Any of the bitmasks can also be undef. The timeout, if specified, is in seconds, which may be fractional. NOTE: not all implementations are capable of returning the $timeleft. If not, they always return $timeleft equal to the supplied $timeout. &lt;br /&gt;&lt;br /&gt;stat(FILEHANDLE)&lt;br /&gt;stat FILEHANDLE &lt;br /&gt;stat(EXPR)&lt;br /&gt;stat SCALARVARIABLE&lt;br /&gt;Returns a 13-element array giving the statistics for a file, either the file opened via FILEHANDLE, or named by EXPR. Returns a null list if the stat fails. Typically used as follows: &lt;br /&gt;    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,&lt;br /&gt;       $atime,$mtime,$ctime,$blksize,$blocks)&lt;br /&gt;           = stat($filename);&lt;br /&gt;&lt;br /&gt;If stat is passed the special filehandle consisting of an underline, no stat is done, but the current contents of the stat structure from the last stat or filetest are returned. Example: &lt;br /&gt; if (-x $file &amp;&amp; (($d) = stat(_)) &amp;&amp; $d &lt; 0) {&lt;br /&gt;  print "$file is executable NFS file\n";&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;(This only works on machines for which the device number is negative under NFS.) &lt;br /&gt;&lt;br /&gt;symlink(OLDFILE,NEWFILE)&lt;br /&gt;Creates a new filename symbolically linked to the old filename. Returns 1 for success, 0 otherwise. On systems that don't support symbolic links, produces a fatal error at run time. To check for that, use eval: &lt;br /&gt; $symlink_exists = (eval 'symlink("","");', $@ eq '');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;truncate(FILEHANDLE,LENGTH)&lt;br /&gt;truncate(EXPR,LENGTH)&lt;br /&gt;Truncates the file opened on FILEHANDLE, or named by EXPR, to the specified length. Produces a fatal error if truncate isn't implemented on your system. &lt;br /&gt;&lt;br /&gt;unlink(LIST)&lt;br /&gt;unlink LIST&lt;br /&gt;Deletes a list of files. Returns the number of files successfully deleted. &lt;br /&gt; $cnt = unlink 'a', 'b', 'c';&lt;br /&gt; unlink @goners;&lt;br /&gt; unlink &lt;*.bak&gt;;&lt;br /&gt;&lt;br /&gt;Note: unlink will not delete directories unless you are superuser and the -U flag is supplied to perl. Even if these conditions are met, be warned that unlinking a directory can inflict damage on your filesystem. Use rmdir instead. &lt;br /&gt;&lt;br /&gt;utime(LIST)&lt;br /&gt;utime LIST&lt;br /&gt;Changes the access and modification times on each file of a list of files. The first two elements of the list must be the NUMERICAL access and modification times, in that order. Returns the number of files successfully changed. The inode modification time of each file is set to the current time. Example of a "touch" command: &lt;br /&gt; #!/usr/bin/perl&lt;br /&gt; $now = time;&lt;br /&gt; utime $now, $now, @ARGV;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-8312180783676950427?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/8312180783676950427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=8312180783676950427' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/8312180783676950427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/8312180783676950427'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/04/file-operations-in-perl.html' title='File Operations in perl'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-3861824209086963821</id><published>2008-03-30T21:54:00.000-05:00</published><updated>2008-03-30T21:56:20.220-05:00</updated><title type='text'>text to speach recognition</title><content type='html'>About: Text to speach (where the computer can read out text) has long been availalbe, mainly through the L&amp;H TruVoice Text-To-Speech. More recently, Microsofts agent programs have allowed text to speach in web pages and speach recognition.&lt;br /&gt;&lt;br /&gt;Quick info. on programming with Ms Agent in Visual basic:&lt;br /&gt;&lt;br /&gt;Right-click on the Toolbox. &lt;br /&gt;Select "Components". &lt;br /&gt;Scroll down the list until you see "Microsoft Agent Control 2.0". Select it and press OK to return to the main window. &lt;br /&gt;Double-click on the "Agent" control in the Toolbox.&lt;br /&gt;&lt;br /&gt;In the General | Declarations section of you form, add this code:&lt;br /&gt;&lt;br /&gt;Dim Merlin As IAgentCtlCharacter 'This _&lt;br /&gt;"creates" Merlin&lt;br /&gt;Const MERLINPATH = "Merlin.acs" '"Merlin.acs" _&lt;br /&gt;is Merlin's character file. &lt;br /&gt;Next, add the following code to the form's Load event: &lt;br /&gt;Agent1.Characters.Load "Merlin", MERLINPATH '"Loads" _&lt;br /&gt;Merlin. &lt;br /&gt;Set Merlin = Agent1.Characters("Merlin") 'Without _&lt;br /&gt;this code, every time you wanted you make Merlin _&lt;br /&gt;do something, you would have to type _&lt;br /&gt;"Agent1.Characters("Merlin")". With this _&lt;br /&gt;code, you just have to type "Merlin". &lt;br /&gt;To get Merlin to appear, say "Hello", point left and then hide, add this code to the form's Load event: &lt;br /&gt;Merlin.Show 'Makes Merlin apear.&lt;br /&gt;Merlin.Speak "Hello" 'Makes Merlin say "Hello".&lt;br /&gt;Merlin.Play "GestureLeft" 'Makes Merlin point left.&lt;br /&gt;Merlin.Hide 'Makes Merlin hide.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-3861824209086963821?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/3861824209086963821/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=3861824209086963821' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3861824209086963821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3861824209086963821'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/text-to-speach-recognition.html' title='text to speach recognition'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-3050754918470239397</id><published>2008-03-28T21:17:00.000-05:00</published><updated>2008-03-28T21:19:11.118-05:00</updated><title type='text'>Top 10 Ajax Security Holes and Driving Factors</title><content type='html'>One of the central ingredients of Web 2.0 applications is Ajax encompassed by JavaScripts. This phase of evolution has transformed the Web into a superplatform. Not surprisingly, this transformation has also given rise to a new breed of worms and viruses such as Yamanner, Samy and Spaceflash. Portals like Google, NetFlix, Yahoo and MySpace have witnessed new vulnerabilities in the last few months. These vulnerabilities can be leveraged by attackers to perform Phishing, Cross-site Scripting (XSS) and Cross-Site Request Forgery (XSRF) exploitation.&lt;br /&gt;&lt;br /&gt;There is no inherent security weakness in Ajax but adaptation of this technology vector has changed the Web application development approach and methodology significantly. Data and object serialization was very difficult in the old days when DCOM and CORBA formed the core middleware tier. Ajax can consume XML, HTML, JS Array, JSON, JS Objects and other customized objects using simple GET, POST or SOAP calls; all this without invoking any middleware tier. This integration has brought about a relatively seamless data exchange between an application server and a browser. Information coming from the server is injected into the current DOM context dynamically and the state of the browser’s DOM gets recharged. Before we take a look at security holes let’s examine the key factors that seem to be driving Web 2.0 vulnerabilities.&lt;br /&gt;&lt;br /&gt;Multiple scattered end points and hidden calls – One of the major differences between Web 2.0 applications and Web 1.0 is the information access mechanism. A Web 2.0 application has several endpoints for Ajax as compared to its predecessor Web 1.0. Potential Ajax calls are scattered all over the browser page and can be invoked by respective events. Not only does this scattering of Ajax calls make it difficult for developers to handle, but also tends to induce sloppy coding practices given the fact that these calls are hidden and not easily obvious.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Qualys: This free security guide describes the scanning requirements for PCI-DSS and provides a quick-reference requirements matrix for both Merchants and Service Providers of all levels.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Validation confusion – One of the important factors in an application is input and outgoing content validation. Web 2.0 applications use bridges, mashups, feeds, etc. In many cases it is assumed that the “other party” (read server-side or client-side code) has implemented validation and this confusion leads to neither party implementing proper validation control.&lt;br /&gt;&lt;br /&gt;Untrusted information sources – Web 2.0 applications fetch information from various untrusted sources such as feeds, blogs, search results. This content is never validated prior to being served to the end browser, leading to cross-site exploitation. It is also possible to load JavaScript in the browser that forces the browser to make cross-domain calls and opens up security holes. This can be lethal and leveraged by virus and worms.&lt;br /&gt;Data serialization – Browsers can invoke an Ajax call and perform data serialization. It can fetch JS array, Objects, Feeds, XML files, HTML blocks and JSON. If any of these serialization blocks can be intercepted and manipulated, the browser can be forced to execute malicious scripts. Data serialization with untrusted information can be a lethal combination for end-user security.&lt;br /&gt;&lt;br /&gt;Dynamic script construction &amp; execution – Ajax opens up a backend channel and fetches information from the server and passes it to the DOM. In order to achieve this one of the requirements is the dynamic execution of JavaScripts to update the state of the DOM or the browser’s page memory. This is achieved by calling customized functions or the eval() function. The consequence of not validating content or of making an insecure call can range from a session compromise to the execution of malicious content.&lt;br /&gt;&lt;br /&gt;Web 2.0 applications can become vulnerable with one or more lapses mentioned above. If developers have not taken enough precautions in putting in place security controls, then security issues can be opened up on both the server as well as browser ends. Here is a list and brief overview of ten possible security holes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Qualys: This free security guide describes the scanning requirements for PCI-DSS and provides a quick-reference requirements matrix for both Merchants and Service Providers of all levels.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(1) Malformed JS Object serialization&lt;br /&gt;&lt;br /&gt;JavaScript supports Object-Oriented Programming (OOP) techniques. It has many different built-in objects and allows the creation of user objects as well. A new object can be created using new object() or simple inline code as shown next:&lt;br /&gt;&lt;br /&gt;message = {&lt;br /&gt;&lt;br /&gt;from : "john@example.com",&lt;br /&gt;&lt;br /&gt;to : "jerry@victim.com",&lt;br /&gt;&lt;br /&gt;subject : "I am fine",&lt;br /&gt;&lt;br /&gt;body : "Long message here",&lt;br /&gt;&lt;br /&gt;showsubject : function(){document.write(this.subject)}&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;Here is a simple message object that has different fields required for email. This object can be serialized using Ajax and consumed by JavaScript code. The programmer can either assign it to the variable and process it or make eval(). If an attacker sends a malicious “subject” line embedded with script then it makes the reader a victim of cross-site scripting attacks. A JS object can have both data and methods. Improper usage of JS object serialization can open up a security hole that can be exploited by crafty packet injection code.&lt;br /&gt;&lt;br /&gt;(2) JSON pair injection&lt;br /&gt;&lt;br /&gt;JavaScript Object Notation (JSON) is a simple and effective lightweight data exchange format and one that can contain object, array, hash table, vector and list data structures. JSON is supported by JavaScript, Python, C, C++, C# and Perl languages. Serialization of JSON is a very effective exchange mechanism in Web 2.0 applications. Developers choose JSON over Ajax very frequently and fetch and pass required information to the DOM. Here is a simple JSON object “bookmarks” object with different name-value pair.&lt;br /&gt;&lt;br /&gt;{"bookmarks":[{"Link":"www.example.com","Desc":"Interesting link"}]}&lt;br /&gt;&lt;br /&gt;It is possible to inject a malicious script in either Link or Desc. If it gets injected into the DOM and executes, it falls into the XSS category. This is another way of serializing malicious content to the end-user.&lt;br /&gt;(3) JS Array poisoning&lt;br /&gt;&lt;br /&gt;JS array is another very popular object for serialization. It is easy to port across platforms and is effective in a cross-language framework. Poisoning a JS array spoils the DOM context. A JS array can be exploited with simple cross-site scripting in the browser. Here is a sample JS array:&lt;br /&gt;&lt;br /&gt;new Array(“Laptop”, “Thinkpad”, “T60”, “Used”, “900$”, “It is great and I have used it for 2 years”)&lt;br /&gt;&lt;br /&gt;This array is passed by an auction site for a used laptop. If this array object is not properly sanitized on the server-side, a user can inject a script in the last field. This injection can compromise the browser and can be exploited by an attack agent.&lt;br /&gt;&lt;br /&gt;(4) Manipulated XML stream&lt;br /&gt;&lt;br /&gt;An Ajax call consumes XML from various locations. These XML blocks originate from Web services running on SOAP, REST or XML-RPC. These Web services are consumed over proxy bridges from third-parties. If this third-party XML stream is manipulated by an attacker then the attacker can inject malformed content.&lt;br /&gt;&lt;br /&gt;The browser consumes this stream from its own little XML parser. This XML parser can be vulnerable to different XML bombs. It is also possible to inject a script in this stream which can again, lead to cross-site scripting (XSS). XML consumption in the browser without proper validation can compromise the end-client.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Qualys: This free security guide describes the scanning requirements for PCI-DSS and provides a quick-reference requirements matrix for both Merchants and Service Providers of all levels.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(5) Script injection in DOM&lt;br /&gt;&lt;br /&gt;The first four holes were the result of issues with serialization. Once this serialized stream of object is received in the browser, developers make certain calls to access the DOM. The objective is to “repaint” or “recharge” the DOM with new content. This can be done by calling eval(), a customized function or document.write(). If these calls are made on untrusted information streams, the browser would be vulnerable to a DOM manipulation vulnerability. There are several document.*() calls that can be utilized by attack agents to inject XSS into the DOM context.&lt;br /&gt;&lt;br /&gt;For example, consider this line of JavaScript code, Document.write(product-review)&lt;br /&gt;&lt;br /&gt;Here, “Product-review” is a variable originating from a third-party blog. What if it contains JavaScript? The answer is obvious. It will get executed in the browser.&lt;br /&gt;&lt;br /&gt;(6) Cross-domain access and Callback&lt;br /&gt;&lt;br /&gt;Ajax cannot access cross-domains from the browser. One of the browser security features that exists in all flavors of browsers is the blocking of cross-domain access. There are several Web services that provide a callback mechanism for object serialization. Developers can use this callback mechanism to integrate Web services in the browser itself. The callback function name can be passed back so that as soon as the callback object stream is retrieved by the browser it gets executed by the specific function name originally passed from the browser.&lt;br /&gt;This callback puts an extra burden on developers to have in-browser validation. If the incoming object stream is not validated by the browser then developers are putting the end client’s fate at the mercy of cross-domain targets. Intentionally or unintentionally, this cross domain service can inject malicious content into the browser. This cross domain call runs in the current DOM context and so makes the current session vulnerable as well. This entire cross-domain mechanism needs to be looked at very closely before implementation into an application.&lt;br /&gt;&lt;br /&gt;(7) RSS &amp; Atom injection&lt;br /&gt;&lt;br /&gt;Syndicated feeds, RSS and Atom, are one of the most popular ways of passing site-updated information over the Internet. Several news, blogs, portals, etc. share more than one feed over the Internet. A feed is a standard XML document and can be consumed by any application. Web 2.0 applications integrate syndicated feeds using widgets or in-browser components. These components make Ajax calls to access feeds.&lt;br /&gt;&lt;br /&gt;These feeds can be selected by end-users easily. Once selected, these feeds are parsed and injected into the DOM. But if the feed is not properly validated prior to injecting it into the DOM, several security issues can crop up. It is possible to inject a malicious link or JavaScript code into the browser. Once this malicious code injected into the DOM, the game is over. The end result is XSS and session hijacking.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Qualys: This free security guide describes the scanning requirements for PCI-DSS and provides a quick-reference requirements matrix for both Merchants and Service Providers of all levels.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(8) One-click bomb&lt;br /&gt;&lt;br /&gt;Web 2.0 applications may not be compromised at the first instance itself, but it is possible to make an event-based injection. A malicious link with “onclick” can be injected with JavaScript. In this case, the browser is sitting on an exploit bomb waiting for the right event from the end-user to trigger the bomb. The exploit succeeds if that particular event is fired by clicking the link or button. This can lead to session hijacking through malicious code.&lt;br /&gt;&lt;br /&gt;Once again this security hole is opened up as a result of information processing from untrusted sources without the right kind of validation. To exploit this security hole an event is required to be fired from an end-client. This event may be an innocuous event such as clicking a button or a link but the consequences can be disastrous. A malicious event that is fired may send current session information to the target or execute fancy inline exploit scripts in current browser context.&lt;br /&gt;(9) Flash-based cross domain access&lt;br /&gt;&lt;br /&gt;It is possible to make GET and POST requests from JavaScripts within a browser by using a Flash plugin’s Ajax interface. This also enables cross-domain calls to be made from any particular domain. To avoid security concerns, the Flash plugin has implemented policy-based access to other domains. This policy can be configured by placing the file crossdomain.xml at the root of the domain. If this file is left poorly configured – as is quite often the case – it opens up the possibility of cross-domain access. Here is a sample of a poorly configured XML file:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now, it is possible to make cross-domain calls from within the browser itself. There are a few other security issues concerning this framework as well. Flash-based Rich Internet Applications (RIA) can be vulnerable to a cross-domain access bug over Ajax if deployment is incorrect.&lt;br /&gt;&lt;br /&gt;(10) XSRF&lt;br /&gt;&lt;br /&gt;Cross-Site Request Forgery is an old attack vector in which a browser can be forced to make HTTP GET or POST requests to cross-domains; requests that may trigger an event in the application logic running on the cross-domain. These can be requests for a change of password or email address. When the browser makes this call it replays the cookie and adopts an identity. This is the key aspect of the request. If an application makes a judgment on the basis of cookies alone, this attack will succeed.&lt;br /&gt;&lt;br /&gt;In Web 2.0 applications Ajax talks with backend Web services over XML-RPC, SOAP or REST. It is possible to invoke them over GET and POST. In other words, it is also possible to make cross-site calls to these Web services. Doing so would end up compromising a victim’s profile interfaced with Web services. XSRF is an interesting attack vector and is getting a new dimension in this newly defined endpoints scenario. These endpoints may be for Ajax or Web services but can be invoked by cross-domain requests.&lt;br /&gt;&lt;br /&gt;Exploitation of security holes and Countermeasures&lt;br /&gt;&lt;br /&gt;Web 2.0 applications have several endpoints; each an entry point for threat modeling. To provide proper security it is imperative to guard each of these entry points. Third-party information must be processed thoroughly prior to sending it to the end-client.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Qualys: This free security guide describes the scanning requirements for PCI-DSS and provides a quick-reference requirements matrix for both Merchants and Service Providers of all levels.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To deal with Ajax serialization issues validation must be placed on incoming streams before they hit the DOM. XML parsing and cross-domain security issues need extra attention and better security controls. Follow the simple thumb rule of not implementing cross-domain information processing into the browser without proper validation. Interestingly, up until now, the use of client-side scripts for input validation was thoroughly discouraged by security professionals because they can be circumvented easily.&lt;br /&gt;&lt;br /&gt;Web 2.0 opens up several new holes around browser security. Exploitation of these security holes is difficult but not impossible. Combinations of security issues and driving factors can open up exploitable holes that impact the sizeable Web community, such as those that can be leveraged by attackers, worms and viruses. Identity compromise may be the final outcome.&lt;br /&gt;&lt;br /&gt;Conclusion&lt;br /&gt;&lt;br /&gt;This article has briefly touched upon a few likely security holes around Ajax. There are a few more lurking around, such as the ones leveraging cross-domain proxies to establish a one-way communication channel or memory variable access in the browser.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-3050754918470239397?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/3050754918470239397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=3050754918470239397' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3050754918470239397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3050754918470239397'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/top-10-ajax-security-holes-and-driving.html' title='Top 10 Ajax Security Holes and Driving Factors'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-1541355109471584865</id><published>2008-03-27T02:00:00.002-05:00</published><updated>2008-03-27T02:04:54.856-05:00</updated><title type='text'>Screens: A Screen-Saver Manager</title><content type='html'>When you come back from lunch or finish a long phone call, you may find your computer's monitor filled with moving lines, bouncing pictures, a scrolling message--even a view from a Web camera thousands of miles away! It's your screen saver, of course, and tapping a key or bumping the mouse will dismiss it. The selected screen saver is activated automatically when a specified number of minutes pass with no keyboard or mouse activity. Screen savers are controlled by the desktop's Display Properties dialog, which is invoked either by right-clicking the desktop and choosing Properties or by launching the Display applet in Control Panel. The Display Properties dialog lets you select your favorite screen saver and preview or invoke its configuration dialog. You can also set the wait period--the number of minutes of inactivity before the screen saver becomes active--and control password protection.&lt;br /&gt;&lt;br /&gt;Wouldn't it be nice if you could schedule screen savers by the day of the week or special dates such as holidays, birthdays, or anniversaries? For example, you might want to have the marquee screen saver that comes with Windows display "I hate work" on Monday, "Hump Day" on Wednesday, and "Thank Goodness It's Friday!" on, what else, Friday. Or how about "Happy Birthday" on your birthday or--this could be a lifesaver--Call your wife" on your anniversary? For some, an important reminder at the beginning of January, April, June, and September would be "Pay quarterly taxes to avoid penalty." Maybe you have a special Christmas screen saver you've been waiting to use? It would be nice if the screen saver came up automatically on Christmas Day.&lt;br /&gt;&lt;br /&gt;You can change the screen saver with the Control Panel Display dialog, but you have to do it manually, and that takes all the fun out of it. With this issue's utility--Screens--you can preschedule a screen saver for a special event, or for a specific day of the week, and have it become the screen-saver-of-the-day automatically when you turn on the computer. If the current day has no special-event or daily screen saver, Screens can activate a default screen saver or choose one at random. Screens also lets you turn the screen saver on or off with a single click of a button without having to select or deselect the current screen saver.&lt;br /&gt;&lt;br /&gt;Screens is a 32-bit utility that runs under Windows 95 or Windows NT 3.51 or higher. The source code for Screens, which was written with Borland's visual programming tool Delphi, is also provided for those interested in seeing how it works.&lt;br /&gt;&lt;br /&gt;Using Screens&lt;br /&gt;To install Screens, simply run the INSTALL program. It will install the necessary files in a subdirectory on your hard disk, create an icon for Screens in your shell, and also put a shortcut into your StartUp folder so that Screens can activate the screen-saver-of-the-day each time you start the system.&lt;br /&gt;&lt;br /&gt;When you first launch Screens, you'll see a dialog with a list of screen savers down the left-hand side (see Figure 1 ). These are all the screen savers found in your Windows and System directories (the same ones found in the Display Properties list). You can choose a screen saver from this list and preview it or change its configuration settings. The Wait box above the list shows the current screen-saver delay in minutes. Pressing the Apply Now button will select the highlighted screen saver as the system screen saver, and it will also apply any changes you've made to the wait time.&lt;br /&gt;&lt;br /&gt;You'll note that there is not a (None) selection in the screen-saver list as there is in the desktop Display Properties dialog. Instead, at the top-left corner of the dialog are ON and OFF buttons for enabling and disabling the screen saver. These buttons provide a quick and easy way to turn the screen saver on or off before running, for example, a backup application. You don't have to choose (None) and then later relocate your favorite screen saver in the list.&lt;br /&gt;&lt;br /&gt;The rest of the dialog is occupied by three tabbed pages that let you define screen savers for special events, days of the week, and days for which no screen savers are defined (the default screen saver). To determine the screen saver for the current day, Screens first checks to see if the day matches any of the special-event dates; if a match is found, it uses that date's screen saver. If not, it checks whether a screen saver is defined for the current day of the week. If so, it uses that one. If there's no daily screen saver, it uses the default screen saver. Let's look at those three tabs in more detail.&lt;br /&gt;&lt;br /&gt;Special-Events Screen Saver&lt;br /&gt;The grid on this page is initially blank, so your first task is to define the dates for which you want special screen savers. Clicking the Insert Date button brings up the Choose Date dialog (see Figure 2 ). This dialog lets you choose a date in three different ways, each with its own tab: Calendar, Holidays, or Calculated Date.&lt;br /&gt;&lt;br /&gt;First, and simplest, you can choose a date from the calendar. If the Annual box is checked, the utility knows that the event will recur every year on the specified date. If the Annual box is blank, the utility knows that the event will occur just once, on the exact date (month, day, and year) you've selected.&lt;br /&gt;&lt;br /&gt;The second tab lets you quickly select a number of standard holidays. Some, such as Valentine's Day, always occur on a particular date--in this case February 14. Others, such as Thanksgiving, are defined by month and day of week. Thanksgiving is the fourth Thursday in November, which Screens expresses as Nov-Thu #4. Easter is a special case, as it can occur on a wide range of dates in March or April. When you choose a holiday, the appropriate date code will be inserted in the grid. You can also create user-defined events based on month, day of week, and day-index, where day-index is the month's first, second, third, fourth, or last occurrence of the day of week. (The last instance is represented internally as -1.)&lt;br /&gt;&lt;br /&gt;For each special event in the grid, you must define a screen saver. Either drag the screen saver from the list at the left, or highlight it and press the Add SS to Date button. Windows 95 comes with a screen saver called Scrolling Marquee, which scrolls text horizontally across the screen; if you are using the marquee screen saver (identified by the word marquee in its name), you can also enter marquee text for an event. For example, you might define your anniversary as a special event, add the Scrolling Marquee, and define the marquee text as "Don't forget flowers!"&lt;br /&gt;&lt;br /&gt;The Remove Date button removes the currently highlighted date from your special-events list. You can also select the date and click Delete. The Erase All Dates button should be used with caution, as it completely empties the list of special events.&lt;br /&gt;&lt;br /&gt;Daily Screen Saver&lt;br /&gt;At the top of the Daily Screen Saver tab, you'll find a three-column list. The first column contains the days of the week, the second column holds the screen saver associated with each day, and the third column is labeled Marquee Text. To attach a screen saver to a day of the week, simply drag it from the list at the left to the appropriate row. If you prefer, you can highlight the desired screen saver and then press the Add SS to Day button.&lt;br /&gt;&lt;br /&gt;If the selected screen saver's name contains marquee, you can enter in the cell next to the screen saver the text that scrolls across the screen when the screen saver is active. For example, if you want to see "I hate work" on Monday, first place the marquee screen saver in the column next to "Mon" and then edit the text in the Marquee Text column to "I hate work." The Marquee Text column only has meaning when you select a marquee screen saver; it is grayed and inaccessible otherwise.&lt;br /&gt;&lt;br /&gt;To change the screen saver for a day of the week, simply drag a new screen saver into place, or highlight the screen-saver cell and click the Add SS to Day button. Other buttons clear the screen saver for the highlighted day and clear all daily screen savers.&lt;br /&gt;&lt;br /&gt;Default Screen Saver&lt;br /&gt;If Screens doesn't find a special-event screen saver or daily screen saver, it uses the default screen saver, defined on the Default tab. To select a default screen saver, place its name in the one-row grid at the top of the page, then check the radio button titled Use the default Screen Saver shown here.&lt;br /&gt;&lt;br /&gt;If you prefer, you can use the previously selected screen saver as the default by checking the radio button titled Do not change the screen saver. For example, you might want to define a special-event screen saver for the first of each month and use that as the default screen saver on subsequent days in the month. In that case, you'd leave the screen saver unchanged.&lt;br /&gt;&lt;br /&gt;Finally, if you like surprises, you can check the box titled Choose a screen saver at random. The list from which this choice is made is updated each time you configure Screens. If you add or remove screen savers from your system, simply run Screens, make any changes you wish, and click the Close button.&lt;br /&gt;&lt;br /&gt;Commad Line Parameters&lt;br /&gt;Screens accepts three command line arguments: /C for Choose, /D for Disable, and /E for Enable. So far, we've been looking at Screens' main window, which is what you get if you don't specify any command line arguments. Most days, you won't need to see this configuration dialog--you'll just want Screens to activate the day's screen saver. The command line switch /C invokes this behavior. Since you'll normally want Screens to choose the day's screen saver each time Windows starts, the INSTALL program places a shortcut for the command SCREENS /C in the StartUp folder. If you want to prevent Screens from running at start-up, just move this shortcut to another folder.&lt;br /&gt;&lt;br /&gt;Run Screens with the /D parameter to disable the screen saver, just as if you were to click the OFF button in the main window. The /E parameter enables the screen-saver activation, as if you were to click the ON button. You could take advantage of these parameters in a batch file to run a program with no screen-saver interruption:&lt;br /&gt;&lt;br /&gt;SCREENS /D&lt;br /&gt;&lt;br /&gt;START /W PROGRAM.EXE&lt;br /&gt;&lt;br /&gt;SCREENS /E&lt;br /&gt;&lt;br /&gt;START /W, in the second line, launches the program and waits for it to terminate before letting the batch file continue execution.&lt;br /&gt;&lt;br /&gt;Programming Screens&lt;br /&gt;Manipulating screen savers programmatically is straightforward for the most part, but finding a descriptive name to display in the selection list can be tricky. For 32-bit screen savers, the long filename is the descriptive name, but for 16-bit screen savers the description must be extracted from the executable header. Screens digs deep to give you an understandable list. Defining holidays is another challenge, since many don't occur on specific dates; the contortions required to calculate the date of Easter in particular are amazing. We'll also look at a grab bag of functions for getting and changing information about screen savers.&lt;br /&gt;Screen-Saver Name&lt;br /&gt;Screen savers normally reside in the Windows directory or the System directory; that's where the Display Properties dialog looks for them. So to make its list of screen savers, Screens examines each file in those directories with the extension .SCR. A screen saver's descriptive name is stored differently, depending on whether it's a 16-bit screen saver for Windows 3.x, a 32-bit screen saver for Windows 95, or a 32-bit screen saver for Windows NT. So the first step is to figure out what type of screen saver it is.&lt;br /&gt;&lt;br /&gt;Every Windows program (including screen savers) starts with an old-style DOS executable header that Screens defines as the data structure OldExeHdr. Windows requires much more information to load and run a program than OldExeHdr provides, so Microsoft has added the "new executable header" (NewExeHdr, in Screens) and placed a pointer to it in OldExeHdr. (Note that 32-bit Windows defines yet another format--called the portable executable header--but that as we'll see below, Screens doesn't need to read this one. Screens only needs to know if it's there.) The first 2 bytes of NewExeHdr constitute a "signature" that defines whether the header is a new executable ("NE") or a portable executable ("PE").&lt;br /&gt;&lt;br /&gt;Screens starts by opening each .SCR file and reading a block of data sized to match the old-style DOS-based executable header (defined as the data structure OldExeHdr). After reading the header, Screens does a sanity check to confirm it's actually an OldExeHdr, by looking at the EXE signature--the very first 2 bytes of the file. This signature is "4D, 5A" in hex; in ASCII it's "MZ," the initials of Mark Zbikowski (one of the three developers of DOS 2.0). The location of NewExeHdr is found at offset 3Ch of OldExeHdr. Screens reads the NewExeHdr signature to see whether it's an NE or PE header.&lt;br /&gt;&lt;br /&gt;The Win32 SDK documentation says that the descriptive name for a 32-bit screen saver (the PE signature) is stored as a string resource with a numeric ID of IDS_DESCRIPTION. (The value of IDS_DESCRIPTION is 1.) Windows NT honors this convention, but Windows 95 does not, using instead the screen saver's filename. If Screens detects that it is running under Windows NT, it loads the screen saver into memory using LoadLibraryEx--with the LOAD_LIBRARY_AS_DATAFILE flag--and extracts the IDS_DESCRIPTION resource string. If the string is blank, or if Windows 95 is the operating system, Screens uses the filename for the descriptive name.&lt;br /&gt;&lt;br /&gt;For a 16-bit screen saver (with an NE signature), Screens reads NewExeHdr. The descriptive name is stored as the first entry in the nonresident names table, and this table's location is found in NewExeHdr. Screens reads a block of data from the screen-saver file, starting at the nonresident names table's offset. The first byte is the descriptive name's length. The descriptive name for a screen saver is supposed to be prefaced with SCRNSAVE. In practice, this usage is inconsistent--sometimes the prefix is absent, and sometimes it's followed by a colon, or a colon and a space. Screens strips off the prefix (if found) before storing the descriptive name.&lt;br /&gt;&lt;br /&gt;Is Today Special?&lt;br /&gt;When you start Screens with the /C parameter, its first task is to determine whether the current date matches any of the special events you've defined. It reads the list of special-event dates from SCREENS.INI and compares each date string with the current date until it either finds a match or reaches the end of the list. The function MatchesToday handles this comparison.&lt;br /&gt;&lt;br /&gt;There are four kinds of special events: specific dates, annual dates, calculated dates, and Easter. Here are some examples, showing a string representation of each event type. Note that all four of the example strings match the date April 12, 1998.&lt;br /&gt;&lt;br /&gt;"EASTER" (Easter--a special case)&lt;br /&gt;&lt;br /&gt;"Apr-Sun #2" (calculated date-- second Sunday in April)&lt;br /&gt;&lt;br /&gt;"Apr 12" (annual date--April 12&lt;br /&gt;of any year)&lt;br /&gt;&lt;br /&gt;"Apr 12, 1998" (specific date)&lt;br /&gt;&lt;br /&gt;First, MatchesToday looks to see if the date string is "EASTER." If so, it calls the function Easter, described below, to get the date of Easter for the current year. If that date matches the current date, the Easter screen saver is selected.&lt;br /&gt;&lt;br /&gt;If it's not Easter, MatchesToday checks for a calculated date by looking for the character "#" in the date string's ninth position. If the date string represents a calculated date, MatchesToday converts the current date into a calculated date for comparison.&lt;br /&gt;&lt;br /&gt;A calculated date is built from the month name, the day of the week, and the day-index. The first occurrence of a particular day of week in the month has a day-index of 1, the second a day-index of 2, and so on. The last occurrence (which may be either the fourth or fifth occurrence) is represented by a day-index of -1. Note that the fifth occurrence of a particular day in the month is always the last, while the fourth occurrence may be the last.&lt;br /&gt;&lt;br /&gt;To calculate the day-index, we subtract 1 from the day of the month, divide the result by 7, discard any remainder, and add 1. For example, December 25, 1997, is a Thursday; subtracting 1 from 25 yields 24; dividing 24 by 7 without remainder gives 3; and adding 1 to 3 yields 4, meaning this is the fourth Thursday in December. Screens never uses a day-index of 5, so if this calculation yields 5, the MatchesToday function automatically changes the index to -1.&lt;br /&gt;&lt;br /&gt;As noted above, the fourth occurrence of a given day of the week may also be the last. To determine whether this is the case, MatchesToday adds seven days to the current date and checks whether the result is within the same month. If it is not, MatchesToday creates a new representation of the current date as a calculated date, using a day-index of -1, and checks the representation once more against the date string.&lt;br /&gt;&lt;br /&gt;If the date string is neither "EASTER" nor a calculated date, MatchesToday tries to convert the current date into a string with the same format used by Screens for storing specific dates. This format is represented by the string "mmm d, yyyy," where mmm is replaced by the three-letter month abbreviation, d is the day of the month with no leading 0, and yyyy is the four-digit year. If this format precisely matches the passed string, a specific-date match has been found. Otherwise, if the month and day (the portion of this format before the comma) precisely match the passed string, an annual-date match has been found.&lt;br /&gt;&lt;br /&gt;The date of Easter varies from year to year, sometimes occurring in March, sometimes in April. To figure out whether a given date is Easter requires some complicated calculations. I searched the Internet for algorithms and found one that does the job. Easter is defined as the first Sunday after the paschal full moon. The paschal full moon is not an actual astronomical event; rather, it is a day identified by an artificial value, which is determined from tables and calculations. It may differ from the date of the true full moon by as much as two days. This calculation-based definition is necessary, because the actual full moon can occur on different calendar days in different parts of the world. The Easter function (which is available for downloading from PC Magazine Online) performs the necessary calculations to determine the paschal full moon, and it returns the date corresponding to the following Sunday.&lt;br /&gt;&lt;br /&gt;Screen-Saver Miscellany&lt;br /&gt;Controlling screen savers programmatically requires the use of quite a few specialized API functions, and there are some surprises along the way. We'll hit a few of the high points so you don't have to learn the hard way.&lt;br /&gt;&lt;br /&gt;A screen saver has two executable sections in it: a configuration dialog and the actual screen saver. When the screen saver is invoked with /C or -C on the command line or with nothing on the command line, the configuration dialog is invoked. When the command line switch /S or -S is used, the screen saver itself is launched. In Screens, pressing Preview launches the highlighted screen saver with the /S switch, and pressing Settings launches it with the /C switch.&lt;br /&gt;&lt;br /&gt;The ShellExecute function can't be used to launch the screen saver, because this function always invokes preview mode, regardless of the command line switch. ShellExecute seems to include some special-case code for screen savers. The solution that I found is simple--Screens calls the screen saver using the antique WinExec function, carried over from Windows 3.x. Another solution would have been to launch the screen saver using the Win32 function CreateProcess, but this seemed unduly complicated.&lt;br /&gt;&lt;br /&gt;There are other oddities as well. For example, you'd think Windows 95 would refer to the current screen saver using long filenames. You'd be wrong! The current screen saver is defined by the SCRNSAVE.EXE= entry in the [Boot] section of SYSTEM.INI, and it must be stored using a short filename. Screens uses the handy API function GetShortPathName to convert the selected screen-saver name before storing the file in SYSTEM.INI.&lt;br /&gt;&lt;br /&gt;Any time your programs need to get or set system information, chances are good you'll wind up using the Windows API function SystemParametersInfo. Screens uses this function to enable and disable the screen saver, check whether the screen saver is enabled, and get or set the screen-saver time-out delay. SystemParamatersInfo takes four parameters:&lt;br /&gt;&lt;br /&gt;uiAction defines the desired action&lt;br /&gt;&lt;br /&gt;uiParam varies depending on the action&lt;br /&gt;&lt;br /&gt;pvParam varies depending on the action&lt;br /&gt;&lt;br /&gt;fWinIni defines how a SET action will be communicated to the system&lt;br /&gt;&lt;br /&gt;That last parameter deserves further explanation. When SystemParametersInfo changes one of the system parameters, the change takes place immediately. However, programs that are already running may still be using the old value. Also, if the parameter in question is initialized through WIN.INI, it will be restored to its old value the next time Windows restarts. Two flag values for the fWinIni parameter prevent these two problems. The SPIF_UPDATEINIFILE flag causes SystemParametersInfo to record the parameter change in WIN.INI, if indeed the parameter value is stored there. And the SPIF_SENDWININICHANGE flag causes SystemParametersInfo to broadcast a WM_WININICHANGE message to all top-level windows, giving them the opportunity to obtain and use the new parameter value. Any time Screens calls this function to set new values for system parameters, the utility includes both of these flags.&lt;br /&gt;&lt;br /&gt;In most cases, a SystemParametersInfo call that sets a new value will pass the value in&lt;br /&gt;&lt;br /&gt;SystemParametersInfo(SPI_SETSCREEN-SAVEACTIVE, 0, nil, SPIF_UPDATEINI-FILE OR SPIF_SENDWININICHANGE);&lt;br /&gt;&lt;br /&gt;To reenable screen-saver activity, it uses this call:&lt;br /&gt;&lt;br /&gt;SystemParametersInfo(SPI_SETSCREEN-SAVEACTIVE, 1, nil, SPIF_UPDATE-INIFILE OR SPIF_SENDWININICHANGE);&lt;br /&gt;&lt;br /&gt;If you're not already familiar with SystemParametersInfo, look it up in the Windows help. You'll be amazed by the number of different parameters it can query and change!&lt;br /&gt;&lt;br /&gt;In Closing&lt;br /&gt;Screen savers can be fun. They can be even more fun if a relevant screen saver runs automatically according to a prearranged schedule. Try scheduling a screen-saver message for a far-off event. Screens will pleasantly remind you when the event arrives, long after you've forgotten about the date. Or simply have Screens randomly choose a screen saver for you each day. I hope Screens brings you some fun.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-1541355109471584865?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/1541355109471584865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=1541355109471584865' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1541355109471584865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1541355109471584865'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/screens-screen-saver-manager.html' title='Screens: A Screen-Saver Manager'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-639680572376233044</id><published>2008-03-26T00:07:00.000-05:00</published><updated>2008-03-26T00:09:00.592-05:00</updated><title type='text'>Coding Windows Screen Savers with Delphi</title><content type='html'>Screen Shuffling with Delphi&lt;br /&gt;&lt;br /&gt;1.Screen Shuffling with Delphi&lt;br /&gt;Delphi code that divides the current desktop into blocks and then swaps the blocks. It includes an option that lets you adjust the shuffling speed, and the size of the blocks. Great intro to sliding puzzle game or to screen saver development.&lt;br /&gt; &lt;br /&gt; More of this Feature&lt;br /&gt;• Project's CODE&lt;br /&gt;&lt;br /&gt;Printer friendly versionPrinter friendly version&lt;br /&gt; Join the Discussion&lt;br /&gt;"Post your views, comments, questions and doubts to this article."&lt;br /&gt;Discuss!&lt;br /&gt; Related Resources&lt;br /&gt;• Graphics programming&lt;br /&gt;• Custom shaped forms&lt;br /&gt;• Zoom - Desktop loupe&lt;br /&gt;• TScreen object&lt;br /&gt;• Changing Screen size&lt;br /&gt;• Screen savers with Delphi&lt;br /&gt;About Poll&lt;br /&gt;This [082801] article is:&lt;br /&gt; Awesome (5)&lt;br /&gt; Great (4)&lt;br /&gt; Ok (3)&lt;br /&gt; Not bad (2)&lt;br /&gt; Poor (1)&lt;br /&gt;Current Results&lt;br /&gt;&lt;br /&gt;The Idea&lt;br /&gt;Screen shuffling in actionI'm sure you've seen it. When the program starts it takes a picture of the current desktop, the picture is then "cut" into a number of rectangular pieces (all of the same size). The piece at some random position is "removed". The main code randomly swaps that piece with the one next to it. Only pieces adjacent to the removed one can be moved into it.&lt;br /&gt;&lt;br /&gt;   Implementation&lt;br /&gt;Start a new Delphi project with a blank form. Set the Name property to be 'Shuffler'. Add an Image (Image1) and a Timer (Timer1) component to a form. Image will hold the (scrambled) picture of the Desktop and Timer will fire the drawing procedure. The Interval property of the Timer component determines how often the swapping takes place (the value of 1000 is equal to one second, 2000 is two seconds).&lt;br /&gt;Several global variables are required by the project. Place the next code above the implementation part of the form unit:&lt;br /&gt;&lt;br /&gt;var&lt;br /&gt;  //this was added by Delphi&lt;br /&gt;  Shuffler: TShuffler; &lt;br /&gt;&lt;br /&gt;  DesktopBitmap   : TBitmap; &lt;br /&gt;  gx, gy          : Integer; &lt;br /&gt;  redRect         : TBitmap; &lt;br /&gt;&lt;br /&gt;  rW, rH          : Integer; &lt;br /&gt;&lt;br /&gt;const&lt;br /&gt;  DELTA = 8; //should be 2^n&lt;br /&gt;&lt;br /&gt;• The constant (integer) DELTA value determines in how many pieces (preciselly, rows and columns) the screen shot will be split into. The DELTA number should be 2^n where n is a signed integer number. Bigger DELTA results in smaller pieces. For example if DELTA is 16 and the screen resolution is 1024 x 768 then the screen is divided in 64x48 matrix forming 256 pieces.&lt;br /&gt;• DesktopBitmap bitmap holds the captured image of the current Desktop screen - we get this picture by taking the screen shoot.&lt;br /&gt;• redRect is a bitmap picture that replaces the "removed" piece of the picture. The redRect is created in the form's OnCreate event.&lt;br /&gt;• gx, gy hold the current x and y position (Left, Top) of the redRect inside the scrambled picture.&lt;br /&gt;• rW, rH are width and Height of a rectangular part of the picture. For the 1024x768 and DELTA=16 the rW is 64 and rH is 48.&lt;br /&gt;&lt;br /&gt;The project starts in the form's OnCreate event handler:&lt;br /&gt;&lt;br /&gt;procedure TShuffler.FormCreate(Sender: TObject);&lt;br /&gt;begin&lt;br /&gt;  rW := Screen.Width div DELTA;&lt;br /&gt;  rH := Screen.Height div DELTA;&lt;br /&gt;&lt;br /&gt;  redRect:=TBitmap.Create;&lt;br /&gt;  with redRect do begin&lt;br /&gt;    Width := rW;&lt;br /&gt;    Height := rH;&lt;br /&gt;    Canvas.Brush.Color := clRed;&lt;br /&gt;    Canvas.Brush.Style := bssolid;&lt;br /&gt;    Canvas.Rectangle(0,0,rW,rH);&lt;br /&gt;    Canvas.Font.Color := clNavy;&lt;br /&gt;    Canvas.Font.Style := Canvas.Font.Style + [fsBold];&lt;br /&gt;    Canvas.TextOut(2,2,'About');&lt;br /&gt;    Canvas.Font.Style := Canvas.Font.Style - [fsBold];&lt;br /&gt;    Canvas.TextOut(2,17,'Delphi');&lt;br /&gt;    Canvas.TextOut(2,32,'Programming');&lt;br /&gt;  end;&lt;br /&gt;&lt;br /&gt;  Timer1.Enabled := False;&lt;br /&gt;  Image1.Align := alClient;&lt;br /&gt;  Visible := False;&lt;br /&gt;  BorderStyle := bsNone;&lt;br /&gt;  Top := 0;&lt;br /&gt;  Left := 0;&lt;br /&gt;  Width := Screen.Width;&lt;br /&gt;  Height := Screen.Height;&lt;br /&gt;  InitScreen;&lt;br /&gt;//  SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,&lt;br /&gt;                 SWP_NOSIZE + SWP_NOMOVE);&lt;br /&gt;  Visible := True;&lt;br /&gt;  Timer1.Interval := 10; // smaller := faster&lt;br /&gt;  Timer1.Enabled  := True; // start calling DrawScreen&lt;br /&gt;end;&lt;br /&gt;&lt;br /&gt;First, the rW and rH values are determined by the DELTA value. As explained, if the screen dimension is 800x600 and DELTA is 8 than the screen picture is "divided" into 8x8 matrix thus forming small 100x75 peaces (rW = 100, rH = 75). In Delphi the TScreen object represents the state (resolution, color depth, etc.) of the screen in which an application runs.&lt;br /&gt;&lt;br /&gt;Second, the redRect bitmap is created that will be placed inside the picture so that it replaces the "removed" slide. The redRect is simply a red rectangle with a sample (blue) text inside it. You could use some ready made graphics, some logo or something.&lt;br /&gt;&lt;br /&gt;Finally, the code sets the form to be wide and tall as the Screen. The (commented) call to the API SetWindowPos could be used to set the form to be always OnTop, non movable and non resizable. The InitScreen procedure is called. Timer Interval is set and the OnTimer event starts executing the DrawScreen procedure.&lt;br /&gt;&lt;br /&gt;InitScreen - Screen shot&lt;br /&gt;The InitScreen procedure, called from the form's OnCreate event handler, is used to take a screen shot of the current Desktop screen, set the starting position of the redRect and to draw the grid. The code that draws the grid is optional.&lt;br /&gt;&lt;br /&gt;To take a screen shoot of the Desktop the GetDC along GetDesktopWindow are used. The BitBt API function is used to transfer the picture of the Desktop to the DesktopBitmap. GetDC(GetDesktopWindow) retrieves a handle of a display device context for the specified window - the window returned by the GetDesktopWindow call. Finally DesktopBitmap is then assigned to Image1 component. Take a look at Delphi help files for more info.&lt;br /&gt;&lt;br /&gt;Initial position of the redRect piece is randomly selected. Trunc(Random * DELTA) returns an integer number between 0 and DELTA. Next, the redRect is drawn on the gx, gy position using the CopyRect function of the Canvas object. Again, if you are unfamiliar with drawing algorithms in Delphi - please consider the help system for more info.&lt;br /&gt;&lt;br /&gt;Finally, the grid is drawn by using the MoveTo and LineTo. Grid is optional and is used to better differentiate each peace of the picture.&lt;br /&gt;&lt;br /&gt;procedure InitScreen;&lt;br /&gt;var i,j:integer;&lt;br /&gt;begin&lt;br /&gt;  //get Desktop bitmap&lt;br /&gt;  DesktopBitmap := TBitmap.Create;&lt;br /&gt;  with DesktopBitmap do begin&lt;br /&gt;    Width := Screen.Width;&lt;br /&gt;    Height := Screen.Height;&lt;br /&gt;  end;&lt;br /&gt;  BitBlt(DesktopBitmap.Canvas.Handle,&lt;br /&gt;         0,0,Screen.Width,Screen.Height,&lt;br /&gt;         GetDC(GetDesktopWindow),0,0,SrcCopy);&lt;br /&gt;&lt;br /&gt;  Shuffler.Image1.Picture.Bitmap := DesktopBitmap;&lt;br /&gt;&lt;br /&gt;  //initial position of the redRect&lt;br /&gt;  Randomize;&lt;br /&gt;  gx := Trunc(Random * DELTA);&lt;br /&gt;  gy := Trunc(Random * DELTA);&lt;br /&gt;&lt;br /&gt;  Shuffler.Image1.Canvas.CopyRect(&lt;br /&gt;    Rect(rW * gx, rH * gy, rW * gx + rW, rH * gy + rH),&lt;br /&gt;    redRect.Canvas,&lt;br /&gt;    Rect(0,0,rW,rH));&lt;br /&gt;&lt;br /&gt;  //draw grid&lt;br /&gt;  for i:=0 to DELTA-1 do begin&lt;br /&gt;    Shuffler.Image1.Canvas.MoveTo(rW * i,0);&lt;br /&gt;    Shuffler.Image1.Canvas.LineTo(rW * i,Screen.Height);&lt;br /&gt;&lt;br /&gt;    Shuffler.Image1.Canvas.MoveTo(0, rH * i);&lt;br /&gt;    Shuffler.Image1.Canvas.LineTo(Screen.Width, rH * i);&lt;br /&gt;  end;&lt;br /&gt;end;&lt;br /&gt;&lt;br /&gt;Draw Screen&lt;br /&gt;The main code is in the DrawScreen procedure. This procedure is called inside the Ontimer event of a Timer component.&lt;br /&gt;&lt;br /&gt;procedure DrawScreen;&lt;br /&gt;var&lt;br /&gt;  r1,r2:TRect;&lt;br /&gt;  Direction:integer;&lt;br /&gt;begin&lt;br /&gt;  r1:=Rect(rW * gx , rH * gy,&lt;br /&gt;           rW * gx + rW, rH * gy + rH);&lt;br /&gt;&lt;br /&gt;  Direction := Trunc(Random*4);&lt;br /&gt;  case Direction of&lt;br /&gt;   0: gx := Abs((gx + 1) MOD DELTA); //right&lt;br /&gt;   1: gx := Abs((gx - 1) MOD DELTA); //left&lt;br /&gt;   2: gy := Abs((gy + 1) MOD DELTA); //down&lt;br /&gt;   3: gy := Abs((gy - 1) MOD DELTA); //up&lt;br /&gt;  end; //case&lt;br /&gt;&lt;br /&gt;  r2 := Rect(rW * gx , rH * gy,&lt;br /&gt;             rW * gx + rW, rH * gy + rH);&lt;br /&gt;&lt;br /&gt;  with Shuffler.Image1.Canvas do begin&lt;br /&gt;    CopyRect(r1, Shuffler.Image1.Canvas, r2);&lt;br /&gt;    CopyRect(r2, redRect.Canvas, redRect.Canvas.ClipRect);&lt;br /&gt;  end;&lt;br /&gt;end;&lt;br /&gt;&lt;br /&gt;The code may seam strange but is really simple. Since only pieces adjacent to the redRect one can be swapped with it, there are just 4 possible directions. The r1 rectangle holds the current position of the redRect, r2 points to the rectangle with the peace that will be replaced. The CopyRect is used to transfer the "selected" part on the redRect position and again to draw the redRect on it's new position - thus swapping those two peaces.&lt;br /&gt;It would be much eye-frienldy if the swapping is animated - I'll leave this for yopu to implement.&lt;br /&gt;&lt;br /&gt;This is how my 640x480 Desktop looks, after several OnTimer events, with DELTA=4. My Screen is usually 1024x768, but I've changed my display properties to take a better screen shoot. Note that you have to hit ALT+F4 in order to stop the program execution. Here is the Project's CODE.&lt;br /&gt;&lt;br /&gt;Screen shuffling in action&lt;br /&gt;&lt;br /&gt;Note: If you run this application under Delphi 6 the screen will flicker. In Delphi 6 the csOpaque (in TControlStyle) is only set when the Proportional property is False, Stretch is True and Transparent is False. In Delphi 5 (and &lt;) csOpaque is set if Transparent is False and Stretch is True (or the bitmap you want to display is greater or equal size of the Timage) which make sense.&lt;br /&gt;Conclusion. To shuffle the screen without the flicker effect (in D6) you have to set the Stretch property to TRUE - even when you don't want the bitmap to get stretched (if a graphics is of the equal size to the TImage in which it is displayed - as in our case.)&lt;br /&gt;&lt;br /&gt;   Final words&lt;br /&gt;You've probably saw something like this as a screen saver. If you would like to make one with this code - go ahead. More info on Screen Saver development can also be found on this site.&lt;br /&gt;&lt;br /&gt;For a bit of entertainment - the code is the starting point for the popular slide type puzzle. Those little hand puzzles with tiles numbered 1 to 15 that you must slide into numeric order. All you have to do is to stop the DrawScreen routine after some time to get the puzzled image. The idea of the game is to move the pieces back to reform the picture. In general, add the code that receives user clicks on the shuffled picture. Clicking on a piece next to the redRect should swap that piece with the redRect.&lt;br /&gt;Once you have the game done, you could post it to our Free Source Area.&lt;br /&gt;&lt;br /&gt;Of course, if you have any questions or comments on this article please post to the Delphi Programming Forum.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-639680572376233044?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/639680572376233044/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=639680572376233044' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/639680572376233044'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/639680572376233044'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/coding-windows-screen-savers-with.html' title='Coding Windows Screen Savers with Delphi'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-4186573906200507773</id><published>2008-03-24T00:04:00.001-05:00</published><updated>2008-03-24T00:07:53.771-05:00</updated><title type='text'>Shell Scripting With PHP</title><content type='html'>Who says you have to use Perl to shell script? Jayesh definetly doesn't, and in this article he will show you how to shell script with PHP instead!I know that you all want to get rid of Perl Scripts because of their complexity and the fact that Perl is not an easy language to learn. With the introduction of PHP version 4.2, PHP has started supporting a new SAPI (Server Application Programming Interface) called CLI (Command Line Interface). This facility was introduced to help developers create small shell application (scripts) with PHP, meaning that you can kiss Perl goodbye forever! &lt;br /&gt;&lt;br /&gt;The CLI SAPI was released for the first time with PHP 4.2.0, but was still experimental back then and had to be explicitly enabled with --enable-cli when running ./configure. With PHP 4.3.0, the CLI SAPI will no longer be experimental and therefore will always be built and installed as the PHP (called php.exe on Windows) binary. &lt;br /&gt;&lt;br /&gt;In this tutorial I will show you how to use PHP's CLI feature to interpret shell scripts. I will assume that you have a fair understanding of PHP and that PHP is installed and working properly on your computer. You can have PHP installed on Linux or Windows (the examples in this tutorial are demonstrated with PHP installed under Windows but they should work the same on a Linux machine).&lt;br /&gt;Normally shells are interactive, but not always. This means that the shell accepts commands from you through your keyboard and executes them. But instead of issuing command one by one, we can store this sequence of commands in a text file and tell PHP to execute this text file instead of entering the commands manually. This is known as PHP shell scripting. &lt;br /&gt;&lt;br /&gt;PHP shell scripts are just like batch files in MS-DOS, but they have more power than the MS-DOS batch file, thanks to PHP. &lt;br /&gt;&lt;br /&gt;Why Write Shell Scripts? &lt;br /&gt;Here are some reasons why you may want to consider writing PHP shell scripts:&lt;br /&gt;Shell script can take input from a user or file and output them on screen&lt;br /&gt;Useful to create your own commands/applications&lt;br /&gt;Don't have to reinvent the wheel&lt;br /&gt;Can be used to automate some day to day tasks, such as backups&lt;br /&gt;Getting Started &lt;br /&gt;Lets start with a small script to display the typical "Hello World" text. Create a text file called world.php. Enter the following code into world.php and save it in your PHP directory: &lt;br /&gt;&lt;br /&gt;&lt;? &lt;br /&gt;echo "Hello World"; &lt;br /&gt;?&gt; &lt;br /&gt;&lt;br /&gt;Open your command prompt change into the folder where PHP is installed and run the following command: &lt;br /&gt;&lt;br /&gt;php world.php &lt;br /&gt;&lt;br /&gt; &lt;img src="http://www.devarticles.com/images/phpss_1.gif" border=0&gt;&lt;br /&gt;&lt;br /&gt;If you're surprised to see the output at the command prompt instead of in a web browser, then welcome to the other dimension of PHP! You may have noticed that the following header is also included in the output (PHP does this be default, which also tells you the PHP version): &lt;br /&gt;&lt;br /&gt;X-Powered-By: PHP/4.2.3 &lt;br /&gt;Content-type: text/html &lt;br /&gt;&lt;br /&gt;To suppress this HTTP header, we could run PHP with the following command line parameter: &lt;br /&gt;&lt;br /&gt;php -q world.php &lt;br /&gt;&lt;br /&gt;Lets look at few of the command line options available with the PHP interpreter:&lt;br /&gt;-q (Quiet mode. Suppress HTTP Header output)&lt;br /&gt;-w (Display source with stripped comments and white space)&lt;br /&gt;-v (Version number)&lt;br /&gt;-c &lt;path&gt; (With this option one can either specify a directory where to look for php.ini or you can specify a custom INI file directly (which does not need to be named php.ini)&lt;br /&gt;-d (This option allows you to set a custom value for any of the configuration directives allowed in php.ini. The syntax is: -d configuration_directive[=value])&lt;br /&gt;-l (This option checks the syntax in the source file)&lt;br /&gt;-i (This command line option calls phpinfo() and prints out the results)&lt;br /&gt;Using Streams in Scripts &lt;br /&gt;You can redirect the output from any script to a file, just like this: &lt;br /&gt;&lt;br /&gt;php world.php &gt; outputfile &lt;br /&gt;&lt;br /&gt;For all you Linux fans, you can also redirect the script output to another command by using the | (pipe operator) e.g. : php world.php | sort.&lt;br /&gt;&lt;br /&gt;There are three streams available in the PHP CLI, which are:&lt;br /&gt;stdin ('php://stdin')&lt;br /&gt;stdout ('php://stdout')&lt;br /&gt;stderr ('php://stderr')&lt;br /&gt;This following example will display "Hello World" in the output window using the output stream: &lt;br /&gt;&lt;br /&gt;&lt;? &lt;br /&gt;$stdout = fopen('php://stdout', 'w'); &lt;br /&gt;fwrite($stdout,"Hello World"); &lt;br /&gt;fclose($stdout); &lt;br /&gt;?&gt; &lt;br /&gt;&lt;br /&gt;This example will demonstrate how to use an input stream. It will accept input from the user and wait until the user presses the enter key and then it will display the text entered: &lt;br /&gt;&lt;br /&gt;&lt;? &lt;br /&gt;$stdin = fopen('php://stdin', 'r'); &lt;br /&gt;echo "Please Enter your Name :"; &lt;br /&gt;$mystr = fgets($stdin,100); &lt;br /&gt;echo "Your Name Is :\n"; &lt;br /&gt;echo $mystr; &lt;br /&gt;fclose($stdin); &lt;br /&gt;?&gt; &lt;br /&gt;&lt;br /&gt;This following example shows you how to output text to an error stream: &lt;br /&gt;&lt;br /&gt;&lt;? &lt;br /&gt;$stderr = fopen('php://stderr', 'w'); &lt;br /&gt;fwrite($stderr,"There was an Error"); &lt;br /&gt;fclose($stderr); &lt;br /&gt;?&gt; &lt;br /&gt;&lt;br /&gt;OK, before we move ahead, there are a few things that you should know. The output to the error stream is always sent to the error device (normally screen) and is not sent to file or another command when redirecting the output. Always make sure you close this stream once you are done with it. Please refer to the PHP manual if you need more information on the fopen, fwrite, fgets and fclose functions.&lt;br /&gt;&lt;br /&gt;As you all know, we can use arguments with PHP (remember, world.php was an argument to the PHP interpreter). Similarly, we can use arguments in our scripts too. Curious? Let's take a look... &lt;br /&gt;&lt;br /&gt;All of the arguments passed to your script are stored in a zero based global array variable called $argv. There is also another global variable, $argc, which holds number of arguments passed to the script (For all of those coming from a C/C++ background, this should be familiar to you). &lt;br /&gt;&lt;br /&gt;One thing you need to remember is that $argc will always be one or more – never zero. This is because the name of the script being interpreted is always the first argument to the PHP interpreter. Here's the code, which will display the total number of arguments passed. It will also will display what those arguments are arguments: &lt;br /&gt;&lt;br /&gt;&lt;? &lt;br /&gt;echo "Total argument passed are : $argc \n"; &lt;br /&gt;for( $i = 0 ; $i &lt;= $argc -1 ;$i++) &lt;br /&gt;{ &lt;br /&gt;echo "Argument $i : $argv[$i] \n"; &lt;br /&gt;} &lt;br /&gt;?&gt; &lt;br /&gt;&lt;br /&gt;Assuming this code is entered into a file called argument.php, you could test this script by running something like this: &lt;br /&gt;&lt;br /&gt;php argument.php arg1 arg2 &lt;br /&gt;&lt;br /&gt;Here's the output: &lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.devarticles.com/images/phpss_2.gif" border=0&gt;&lt;br /&gt;&lt;br /&gt;Using PHP Script Instead of Perl Scripts &lt;br /&gt;As you must have guessed so far, the PHP executable can run independently from the web server. If you want to run your PHP scripts instead of Perl scripts -- which should be transparent to the system – you need to add a shebang to the top of the PHP script that you want to execute. A shebang looks like this: &lt;br /&gt;&lt;br /&gt;#!/usr/bin/php &lt;br /&gt;&lt;br /&gt;This will tell the UNIX system that it needs to run the PHP interpreter for the following script, and the good thing is that this line will be ignored when you run the script under a Windows environment, thus you can write PHP scripts that are not operating system specific: &lt;br /&gt;&lt;br /&gt;#!/usr/bin/php &lt;br /&gt;&lt;br /&gt;&lt;?php &lt;br /&gt;&lt;br /&gt;// your PHP code &lt;br /&gt;// goes here &lt;br /&gt;&lt;br /&gt;?&gt; &lt;br /&gt;&lt;br /&gt;Don't forget to add the PHP tags in the script file, otherwise PHP will not interpret it properly. If you want to suppress the PHP headers, use #!/usr/bin/php –q. Similarly you can also use any other PHP arguments that we discussed earlier by specifying them after the shebang.&lt;br /&gt;&lt;br /&gt;Configuring Windows to Executing PHP Scripts &lt;br /&gt;If you plan to run PHP scripts from a command line on a Windows machine, then you need to associate the PHP files with the PHP interpreter. To do this, open Windows explorer, click on the tools menu and select folder options. Next, click on the file types tab and select the new button. Type .php into the file extension box and click OK: &lt;br /&gt;&lt;img src="http://www.devarticles.com/images/phpss_3.gif" border=0&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;You now need to select the PHP entry in the registered file types list box and click on the advanced button. Click new and type "Run" in the action box. In the "Application Used to Perform Actions" box, type C:\PHP\PHP.exe "%1" %* (change the PHP path if its different on your machine, %* is used to send any command line arguments). Click OK, and then OK again and then the close button: &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;With this step completed, Windows is now configured to run PHP Scripts. To try it out, just double click on any PHP file using Windows Explorer to see it running. &lt;br /&gt;&lt;br /&gt;You can also register files with different PHP extensions, such as .php3 and .php4 using the same method mentioned above.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-4186573906200507773?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/4186573906200507773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=4186573906200507773' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/4186573906200507773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/4186573906200507773'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/shell-scripting-with-php.html' title='Shell Scripting With PHP'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-1124794844458625822</id><published>2008-03-22T00:23:00.002-05:00</published><updated>2008-03-22T00:26:58.575-05:00</updated><title type='text'>some questions on vbscript codings</title><content type='html'>How to load vbs functions in qtp&lt;br /&gt;&lt;br /&gt;U can directly use the function&lt;br /&gt;ExecuteFile "vbsfunctionname.vbs"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What are the differences between Visual Basic, VBA and VBScript? When would it be appropriate to use one as opposed to another?&lt;br /&gt;Visual Basic is a standalone tool for creating separate &lt;br /&gt;software components such as executable programs, COM &lt;br /&gt;components and ActiveX? Controls. It is useful when &lt;br /&gt;building a specialised solution from scratch. VBA offers &lt;br /&gt;the same powerful tools as Visual Basic in the context of &lt;br /&gt;an existing application and is the best option for &lt;br /&gt;customising software that already meets most needs. &lt;br /&gt;VBScript is a lightweight version of the Visual Basic &lt;br /&gt;language designed specifically for use on web pages. While &lt;br /&gt;VBScript can sometimes be used for simple automation, VBA &lt;br /&gt;is the premier technology designed specifically for &lt;br /&gt;application automation. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What is the equivalent of VBScript?s On Error In Jscript ?&lt;br /&gt;JScript uses the try/catch construct to trap, handle, and&lt;br /&gt;throw exceptions. This is one area where JScript is superior&lt;br /&gt;to VBScript.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When inserting strings into a SQL table in ASP what is the risk and how can you prevent it?&lt;br /&gt;The risk associated if not properly taken care of is &lt;br /&gt;something called as "SQL Injection" attack.&lt;br /&gt;&lt;br /&gt;This means you could &lt;br /&gt;&lt;br /&gt;say in Username textfield on the html frontend or any &lt;br /&gt;frontend, is possible to type something like the following &lt;br /&gt;to by pass the security mechanism and get access to the &lt;br /&gt;protected area of the site or application.&lt;br /&gt;&lt;br /&gt;Type the following in Username or Password or both and &lt;br /&gt;click on login/submit or equivalent button.&lt;br /&gt;&lt;br /&gt;' or 'x' = 'x'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What is parametrization ?&lt;br /&gt;It is used to test the application with different data sets.&lt;br /&gt;Different Data sets are stored in DataTable and we&lt;br /&gt;parametrize the test..........&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-1124794844458625822?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/1124794844458625822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=1124794844458625822' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1124794844458625822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1124794844458625822'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/some-questions-on-vbscript-codings.html' title='some questions on vbscript codings'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-5844706643949068854</id><published>2008-03-20T23:32:00.001-05:00</published><updated>2008-03-20T23:32:53.009-05:00</updated><title type='text'>Bug Report</title><content type='html'>reported by the following persons!&lt;br /&gt;&lt;br /&gt;Below you find the latest bug reports and a few resurrected ones.&lt;br /&gt;&lt;br /&gt;Multi-Column Ordered List Renumbering&lt;br /&gt;Permalink | Mozilla | 1 comments &lt;br /&gt;Reported on 7 September 2007 &lt;br /&gt;&lt;br /&gt;If you style an ordered list that contains links with the experimental -moz-column-count the list items of the last columns will be renumbered when a link in that column is clicked.&lt;br /&gt;&lt;br /&gt;Test page Workaround is included&lt;br /&gt;Reported by: Brian Sweeney.&lt;br /&gt;&lt;br /&gt;Backgrounds show through in invisible tables&lt;br /&gt;Permalink | (Orphaned), Safari | 2 comments &lt;br /&gt;Reported on 6 September 2007 &lt;br /&gt;&lt;br /&gt;Background colors given to &lt;col&gt;, &lt;tr&gt;, and &lt;tbody&gt; on a table that is supposed to be invisible (visibility: hidden) still show up. Backgrounds given to individual cells or to elements inside cells are not shown (like expected). &lt;br /&gt;&lt;br /&gt;Test page Workaround is not included&lt;br /&gt;Reported by: Jeffrey Bush.&lt;br /&gt;&lt;br /&gt;Buttons with an image don't align with text ones&lt;br /&gt;Permalink | Mozilla, Opera, Safari | 4 comments &lt;br /&gt;Reported on 5 September 2007 &lt;br /&gt;&lt;br /&gt;Sometimes you might want to mix text buttons with image buttons and insist on using the button tag. However, Firefox aligns the text buttons lower then the image buttons.&lt;br /&gt;&lt;br /&gt;Test page Workaround is not included&lt;br /&gt;Reported by: Laurens van der Klis.&lt;br /&gt;&lt;br /&gt;Absolute/Fixed elements align with Adjacent elements&lt;br /&gt;Permalink | Explorer 7 | 1 comments &lt;br /&gt;Reported on 4 September 2007 &lt;br /&gt;&lt;br /&gt;I have a fixed div that is supposed to reside on the left side of the page and remain static using fixed positioning. There is another div adjacent to it that has a margin property that ensures it remains shifted to the right of my fixed element.&lt;br /&gt;&lt;br /&gt;This looks fine in Firefox and Opera, but in IE7 the fixed element seems to 'inherit' somehow the margin of the adjacent element and positions itself relative to it, so that they share the same left margin. Any repositioning of the fixed element is relative to its adjacent node. This also happens if the node is adjacent.&lt;br /&gt;&lt;br /&gt;Test page Workaround is not included&lt;br /&gt;Reported by: Randeep.&lt;br /&gt;&lt;br /&gt;IE7 Uncle Double Class Selector Bug&lt;br /&gt;Permalink | Explorer 7 | 0 comments &lt;br /&gt;Reported on 3 September 2007 &lt;br /&gt;&lt;br /&gt;Creating a [.class|*|element] + element selector rule will cause IE7 to apply .class1.class2 element or .class1.class2 &gt; element as though it was also a .class1.class2 + element:first-of-type; assuming the final element getting selected in all the above rules are the same element type.&lt;br /&gt;&lt;br /&gt;Test page Workaround is included&lt;br /&gt;Reported by: Mit The Destroyer.&lt;br /&gt;&lt;br /&gt;Older entries&lt;br /&gt;See the September 2007 archive and beyond.&lt;br /&gt;&lt;br /&gt;Below you find a few resurrected bug reports.&lt;br /&gt;&lt;br /&gt;border on tbody incorrectly rendered&lt;br /&gt;Permalink | Safari | 0 comments &lt;br /&gt;Reported on 23 March 2007 &lt;br /&gt;&lt;br /&gt;Safari incorrectly places a border below the tfoot element. This is fixed in the current nightlies of web kit.&lt;br /&gt;&lt;br /&gt;Test page Workaround is not included&lt;br /&gt;Reported by: Marc Pacheco.&lt;br /&gt;&lt;br /&gt;Restoring default border for text input elements leaves left border color intact&lt;br /&gt;Permalink | Explorer 5-6 Windows, Explorer 7 | 0 comments &lt;br /&gt;Reported on 7 November 2006 &lt;br /&gt;&lt;br /&gt;Setting border: 2px inset on a text input element (INPUT.text, INPUT.password, TEXTAREA) to return to its default border after having changed its border style and color leaves the left border's previous color intact.&lt;br /&gt;&lt;br /&gt;Test page Workaround is included&lt;br /&gt;Reported by: Jason Brunette.&lt;br /&gt;&lt;br /&gt;Hangs up on form element with display:table-cell&lt;br /&gt;Permalink | Safari | 1 comments &lt;br /&gt;Reported on 19 July 2006 &lt;br /&gt;&lt;br /&gt;Put the code: &lt;form style="display:table-cell"&gt;&lt;/form&gt; in a page. Safari will hang and you must force it to quit.&lt;br /&gt;&lt;br /&gt;Applying styles dynamically makes no difference.&lt;br /&gt;&lt;br /&gt;Test page Workaround is not included&lt;br /&gt;Reported by: Toby Woodwark.&lt;br /&gt;&lt;br /&gt;Incorrect clientX/Y for text of disabled INPUT elements in tables&lt;br /&gt;Permalink | Explorer 5-6 Windows, Explorer 7 | 1 comments &lt;br /&gt;Reported on 15 March 2006 &lt;br /&gt;&lt;br /&gt;The event.clientX/Y values for the text portion of disabled INPUT elements is reported relative to the left/top of the INPUT element and not the viewport if the INPUT element is in a table.&lt;br /&gt;&lt;br /&gt;Test page Workaround is not included&lt;br /&gt;Reported by: Jason Brunette.&lt;br /&gt;&lt;br /&gt;nested form/table causes extra whitespace&lt;br /&gt;Permalink | Explorer 5-6 Windows, Explorer 7, Safari | 3 comments &lt;br /&gt;Reported on 21 November 2005 &lt;br /&gt;&lt;br /&gt;When nesting a form wholy inside a cell certain browsers includes extra white space at the end of the form. This would appear to be a bug.&lt;br /&gt;&lt;br /&gt;Test page Workaround is not included&lt;br /&gt;Reported by: Jay Soffian.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-5844706643949068854?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/5844706643949068854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=5844706643949068854' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/5844706643949068854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/5844706643949068854'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/bug-report.html' title='Bug Report'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-1376779046750013496</id><published>2008-03-19T03:23:00.001-05:00</published><updated>2008-03-19T03:23:52.285-05:00</updated><title type='text'>Types of SQL statements</title><content type='html'>There are four basic types of SQL statements:&lt;br /&gt;&lt;br /&gt;    * Data definition language (DDL) statements&lt;br /&gt;    * Data manipulation language (DML) statements&lt;br /&gt;    * Dynamic SQL statements&lt;br /&gt;    * Miscellaneous statements&lt;br /&gt;&lt;br /&gt;SQL statements can operate on objects that are created by SQL as well as externally described physical files and single-format logical files, whether they reside in an SQL schema. They do not refer to the IDDU dictionary definition for program-described files. Program-described files appear as a table with only a single column.&lt;br /&gt;Start of change&lt;br /&gt;SQL DDL Statements  SQL DML Statements&lt;br /&gt;ALTER SEQUENCE&lt;br /&gt;ALTER TABLE&lt;br /&gt;COMMENT ON&lt;br /&gt;CREATE ALIAS&lt;br /&gt;CREATE DISTINCT TYPE&lt;br /&gt;CREATE FUNCTION&lt;br /&gt;CREATE INDEX&lt;br /&gt;CREATE PROCEDURE&lt;br /&gt;CREATE SCHEMA&lt;br /&gt;CREATE SEQUENCE&lt;br /&gt;CREATE TABLE&lt;br /&gt;CREATE TRIGGER&lt;br /&gt;CREATE VIEW&lt;br /&gt;DECLARE GLOBAL TEMPORARY TABLE&lt;br /&gt;DROP ALIAS&lt;br /&gt;DROP DISTINCT TYPE&lt;br /&gt;DROP FUNCTION&lt;br /&gt;DROP INDEX&lt;br /&gt;DROP PACKAGE&lt;br /&gt;DROP PROCEDURE&lt;br /&gt;DROP SEQUENCE&lt;br /&gt;DROP SCHEMA&lt;br /&gt;DROP TABLE&lt;br /&gt;DROP TRIGGER&lt;br /&gt;DROP VIEW&lt;br /&gt;GRANT DISTINCT TYPE&lt;br /&gt;GRANT FUNCTION&lt;br /&gt;GRANT PACKAGE&lt;br /&gt;GRANT PROCEDURE&lt;br /&gt;GRANT SEQUENCE&lt;br /&gt;GRANT TABLE&lt;br /&gt;LABEL ON&lt;br /&gt;RENAME&lt;br /&gt;REVOKE DISTINCT TYPE&lt;br /&gt;REVOKE FUNCTION&lt;br /&gt;REVOKE PACKAGE&lt;br /&gt;REVOKE PROCEDURE&lt;br /&gt;REVOKE SEQUENCE&lt;br /&gt;REVOKE TABLE&lt;br /&gt; &lt;br /&gt;CLOSE&lt;br /&gt;COMMIT&lt;br /&gt;DECLARE CURSOR&lt;br /&gt;DELETE&lt;br /&gt;FETCH&lt;br /&gt;INSERT&lt;br /&gt;LOCK TABLE&lt;br /&gt;OPEN&lt;br /&gt;REFRESH TABLE&lt;br /&gt;RELEASE SAVEPOINT&lt;br /&gt;ROLLBACK&lt;br /&gt;SAVEPOINT&lt;br /&gt;SELECT INTO&lt;br /&gt;SET variable&lt;br /&gt;UPDATE&lt;br /&gt;VALUES INTO&lt;br /&gt;End of change&lt;br /&gt;Dynamic SQL Statements  Miscellaneous Statements&lt;br /&gt;DESCRIBE&lt;br /&gt;EXECUTE&lt;br /&gt;EXECUTE IMMEDIATE&lt;br /&gt;PREPARE&lt;br /&gt; &lt;br /&gt;BEGIN DECLARE SECTION&lt;br /&gt;CALL&lt;br /&gt;CONNECT&lt;br /&gt;DECLARE PROCEDURE&lt;br /&gt;DECLARE STATEMENT&lt;br /&gt;DECLARE VARIABLE&lt;br /&gt;DESCRIBE TABLE&lt;br /&gt;DISCONNECT&lt;br /&gt;END DECLARE SECTION&lt;br /&gt;FREE LOCATOR&lt;br /&gt;GET DIAGNOSTICS&lt;br /&gt;HOLD LOCATOR&lt;br /&gt;INCLUDE&lt;br /&gt;RELEASE&lt;br /&gt;SET CONNECTION&lt;br /&gt;SET ENCRYPTION PASSWORD&lt;br /&gt;SET OPTION&lt;br /&gt;SET PATH&lt;br /&gt;SET RESULT SETS&lt;br /&gt;SET SCHEMA&lt;br /&gt;SET TRANSACTION&lt;br /&gt;SIGNAL&lt;br /&gt;WHENEVER&lt;br /&gt;&lt;br /&gt;SQL DDL statements are described in Data Definition Language (DDL). SQL DML statements are described in Retrieving data using the SELECT statement and Data Manipulation Language. You can find complete descriptions of these statements in the SQL Reference book.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-1376779046750013496?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/1376779046750013496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=1376779046750013496' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1376779046750013496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1376779046750013496'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/types-of-sql-statements.html' title='Types of SQL statements'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-8325582576525592695</id><published>2008-03-17T00:30:00.000-05:00</published><updated>2008-03-17T00:33:26.498-05:00</updated><title type='text'>AJAX Fast and Easy</title><content type='html'> The purpose of this post is to try to explain AJAX the way I understand it. To me, AJAX is not some complicated technology that you need to go out and buy books to learn. Rather, it is simply two or more web pages, and a couple of simple Javascript functions.I have come to hate the term AJAX. It seems every time I mention AJAX, either developers get nervous, or account managers get excited. Neither situation benefits me. Actually, I’ve pretty much stopped using the term at all. Depending on my audience, I’ll make up different terms. Like when I’m talking to Java developers, I’ll say “we need to do a back end call” and that doesn’t freak them out, but telling them we need to do an AJAX call makes them sweat.&lt;br /&gt;&lt;br /&gt;Hopefully, if enough people read posts like this, the mystery and glamor will be removed from the term AJAX. So, lets get to the de-mystification.&lt;br /&gt;&lt;br /&gt;First, lets dissect the name itself. A.J.A.X.&lt;br /&gt;A = Asynchronous&lt;br /&gt;J = Javascript&lt;br /&gt;A = And&lt;br /&gt;X = XML&lt;br /&gt;&lt;br /&gt;Most developers reading this will feel pretty comfortable with the Javascript part. It’s the asynchronous and the XML parts that make most people nervous. They really shouldn’t. I’ll briefly describe each, then we’ll put it all together.&lt;br /&gt;&lt;br /&gt;Asynchronous simply means “lets open another URL without changing or reloading the page.” Picture it like this… You are reading a blog post, and you come across a link to another page. You don’t want to stop reading, so you right click the link and open it in a new window or another tab right? Now you continue reading the page you were on. Asynchronous simply means we are doing something else without disturbing the page we are viewing.&lt;br /&gt;&lt;br /&gt;Javascript, we all know what that is I hope. If you don’t, then you should probably be reading some other sites first (intro to Javascript). Now, the purpose of this post is to make AJAX easy to write, and easy to understand, so we are going to use Javascript tools that make our job a lot easier. Whenever I write AJAX code, I always use the Prototype Javascript framework. Go ahead and download it, we’ll talk more about it later, just know that it has most of the Javascript we will need built in.&lt;br /&gt;&lt;br /&gt;Before I get into XML, and what it is, I would like to note that AJAX doesn’t even need XML to work. For those who can’t or won’t use XML, don’t worry, you can still write useful AJAX code without it, but please continue reading and maybe you will decide that you can use XML after all. It does make AJAX a lot easier, but like I said, it’s not necessary.&lt;br /&gt;&lt;br /&gt;XML shouldn’t be scary, but many people just don’t know what it is. If you’ve got this far and you aren’t totally confused, then you probably know how to write HTML. HTML and XML should not necessarily be compared, but they are similar in how they are written. XML is written using ‘tags’ similar to HTML. And XML tags need to be “balanced” just like HTML should be. Following is some simple HTML:&lt;br /&gt;&lt;br /&gt;&lt; h tml &gt;&lt;br /&gt;  &lt; he ad &gt;&lt;br /&gt;    &lt; tit le &gt;sample&lt; / title &gt;&lt;br /&gt;  &lt; / head &gt;&lt;br /&gt;  &lt; body &gt;&lt;br /&gt;    &lt; div &gt;something&lt; /div &gt;&lt;br /&gt;  &lt; / body &gt;&lt;br /&gt;&lt; / ht ml &gt;&lt;br /&gt;&lt;br /&gt;Most people will recognize this as the most basic of HTML code, but what you may not know is that this could also be valid XML code as well. I mentioned the word “balanced” earlier. In the sample above, you will notice that each tag has a corresponding ending tag like &lt; h tml&gt;&lt;/ht m l&gt;. That is what balanced means. That is probably the most important concept in XML. Unlike HTML, we don’t necessarily use XML for presentation, XML is normally used more like a database. For example, if the code above were an XML file, and we wanted to think of it as data, we could say that the &lt;  htm l&gt; section could be the database itself, the &lt; h e ad &gt; section could represent a table in that database, the &lt;title&gt; section could represent a column in that table and the word “sample” would be the value of that column. If it were a database, we could query it something like this…&lt;br /&gt;&lt;br /&gt;select title&lt;br /&gt;from html.head&lt;br /&gt;&lt;br /&gt;We could spend a great deal of time explaining XML, but lets just says that its basic function is to store data and to define what that data means. So, in the example above, the word “sample” means, and we know this because of the XML tags we use to surround it, it is the ‘title’ of the ‘head’ of the ‘html’ file.&lt;br /&gt;&lt;br /&gt;I’ll write one more sample XML just for clarification because I think I’ve spent too much time on this subject already, but I think one more sample will be helpful in describing just how easy XML is. Lets say we want to get a list of books. We could represent that list of books with XML.&lt;br /&gt;&lt;br /&gt;&lt;books&gt;  &lt;br /&gt;  &lt;book&gt;     &lt;br /&gt;    &lt;title&gt;The Shining&lt;/title&gt;     &lt;br /&gt;    &lt;author&gt;Stephen King&lt;/author&gt;     &lt;br /&gt;    &lt;ISBN&gt;0743437497&lt;/ISBN&gt;     &lt;br /&gt;  &lt;/book&gt;     &lt;br /&gt;  &lt;book&gt;     &lt;br /&gt;    &lt;title&gt;Fahrenheit 451&lt;/title&gt;     &lt;br /&gt;    &lt;author&gt;Ray Bradbury&lt;/author&gt;     &lt;br /&gt;    &lt;ISBN&gt;9506440298&lt;/ISBN&gt;     &lt;br /&gt;  &lt;/book&gt;     &lt;br /&gt;&lt;/books&gt;&lt;br /&gt;&lt;br /&gt;From that example, XML should be pretty self explanatory. And that is the real point of XML.&lt;br /&gt;&lt;br /&gt;That concludes “AJAX Fast and Easy – part one”. In part two, we will build a basic HTML file and make an AJAX call to another basic HTML file, leaving the XML part out of the equation. &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-8325582576525592695?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/8325582576525592695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=8325582576525592695' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/8325582576525592695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/8325582576525592695'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/ajax-fast-and-easy.html' title='AJAX Fast and Easy'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-2745557100916708150</id><published>2008-03-13T23:55:00.000-05:00</published><updated>2008-03-13T23:56:37.878-05:00</updated><title type='text'>XML-binary Optimized Packaging</title><content type='html'>This specification defines the XML-binary Optimized Packaging (XOP) convention, a means of more efficiently serializing XML Infosets (see [XMLInfoSet]) that have certain types of content.&lt;br /&gt;&lt;br /&gt;A XOP package is created by placing a serialization of the XML Infoset inside of an extensible packaging format (such a MIME Multipart/Related, see [RFC 2387]). Then, selected portions of its content that are base64-encoded binary data are extracted and re-encoded (i.e., the data is decoded from base64) and placed into the package. The locations of those selected portions are marked in the XML with a special element that links to the packaged data using URIs.&lt;br /&gt;&lt;img src="http://www.w3.org/TR/xop10/XOP-architecture.png" border=0&gt;&lt;br /&gt;In a number of important XOP applications, binary data need never be encoded in base64 form. If the data to be included is already available as a binary octet stream, then either an application or other software acting on its behalf can directly copy that data into a XOP package, at the same time preparing suitable linking elements for use in the root part; when parsing a XOP package, the binary data can be made available directly to applications, or, if appropriate, the base64 binary character representation can be computed from the binary data.&lt;br /&gt;&lt;br /&gt;However, at the conceptual level, this binary data can be thought of as being base64-encoded in the XML Document. As this conceptual form might be needed during some processing of the XML Document (e.g., for signing the XML document), it is necessary to have a one to one correspondence between XML Infosets and XOP Packages. Therefore, the conceptual representation of such binary data is as if it were base64-encoded, using the canonical lexical form of XML Schema base64Binary datatype (see [XML Schema Part 2: Datatypes Second Edition] 3.2.16 base64Binary). In the reverse direction, XOP is capable of optimizing only base64-encoded Infoset data that is in the canonical lexical form.&lt;br /&gt;&lt;br /&gt;Only element content can be optimized; attributes, non-base64-compatible character data, and data not in the canonical representation of the base64Binary datatype cannot be successfully optimized by XOP.&lt;br /&gt;&lt;br /&gt;The remainder of this specification is organized in the following fashion:&lt;br /&gt;&lt;br /&gt;    *&lt;br /&gt;&lt;br /&gt;      Section 2 describes the XOP Infoset, which preserves the non-optimized content and structure of the original XML Infoset.&lt;br /&gt;    *&lt;br /&gt;&lt;br /&gt;      Section 3 specifies the XOP processing model.&lt;br /&gt;    *&lt;br /&gt;&lt;br /&gt;      Section 4 of this specification describes the form of the XOP Package.&lt;br /&gt;    *&lt;br /&gt;&lt;br /&gt;      Section 5 describes how XOP Documents are identified.&lt;br /&gt;    *&lt;br /&gt;&lt;br /&gt;      Section 6 explores the security considerations of using the XOP convention. &lt;br /&gt;&lt;br /&gt;1.1 Terminology&lt;br /&gt;&lt;br /&gt;This specification uses terminology from the XML Infoset (see [XMLInfoSet]) when discussing XML content and structure. This is only a convention for clear specification of XOP behavior.&lt;br /&gt;&lt;br /&gt;The following terms are used in this specification:&lt;br /&gt;&lt;br /&gt;    * Original XML Infoset - An XML Infoset to be optimized.&lt;br /&gt;    * Optimized Content - Content which has been removed from the XML Infoset.&lt;br /&gt;    * XOP Infoset - The Original Infoset with any Optimized Content removed and replaced by xop:Include element information items.&lt;br /&gt;    * XOP Document - A serialization of the XOP Infoset using any W3C recommendation-level version of XML.&lt;br /&gt;    * XOP Package - A package containing the XOP Document and any Optimized Content. As a whole, the XOP Package is an alternate serialization of the Original Infoset.&lt;br /&gt;    * Reconstituted XML Infoset - An XML Infoset that has been constructed from the parts of a XOP Package. &lt;br /&gt;&lt;br /&gt;Architecture of the XOP framework&lt;br /&gt;1.2 Example&lt;br /&gt;&lt;br /&gt;Example 1 shows an XML Infoset prior to XOP processing. Example 2 shows the same Infoset, serialized using the XOP format in a MIME Multipart/Related package. The base64-encoded content of the m:photo and m:sig elements have been replaced by a xop:Include element, while the binary octets have been serialized in separate MIME parts. Note that those examples use [Assigning Media Types to Binary Data in XML] to identify the media type of the content of the m:photo and m:sig elements. Note also that the sample base64 data is smaller than would be typical and the binary octets are not shown; in practice, the optimized form is likely to be much smaller than the original.&lt;br /&gt;Example: XML Infoset prior to XOP processing (Example 1, SOAP)&lt;br /&gt;&lt;br /&gt;&lt;soap:Envelope&lt;br /&gt;    xmlns:soap='http://www.w3.org/2003/05/soap-envelope' &lt;br /&gt;    xmlns:xmlmime='http://www.w3.org/2004/11/xmlmime'&gt;&lt;br /&gt;  &lt;soap:Body&gt;&lt;br /&gt;    &lt;m:data xmlns:m='http://example.org/stuff'&gt;&lt;br /&gt;      &lt;m:photo &lt;br /&gt;  xmlmime:contentType='image/png'&gt;/aWKKapGGyQ=&lt;/m:photo&gt;&lt;br /&gt;      &lt;m:sig &lt;br /&gt;  xmlmime:contentType='application/pkcs7-signature'&gt;Faa7vROi2VQ=&lt;/m:sig&gt;&lt;br /&gt;    &lt;/m:data&gt;&lt;br /&gt;  &lt;/soap:Body&gt;&lt;br /&gt;&lt;/soap:Envelope&gt;&lt;br /&gt;&lt;br /&gt;Example: XML Infoset serialized as a XOP package (Example 2, SOAP)&lt;br /&gt;&lt;br /&gt;MIME-Version: 1.0&lt;br /&gt;Content-Type: Multipart/Related;boundary=MIME_boundary;&lt;br /&gt;    type="application/xop+xml";&lt;br /&gt;    start="&lt;mymessage.xml@example.org&gt;";&lt;br /&gt;    startinfo="application/soap+xml; action=\"ProcessData\""&lt;br /&gt;Content-Description: A SOAP message with my pic and sig in it&lt;br /&gt;&lt;br /&gt;--MIME_boundary&lt;br /&gt;Content-Type: application/xop+xml; &lt;br /&gt;    charset=UTF-8; &lt;br /&gt;    type="application/soap+xml; action=\"ProcessData\""&lt;br /&gt;Content-Transfer-Encoding: 8bit&lt;br /&gt;Content-ID: &lt;mymessage.xml@example.org&gt;&lt;br /&gt;&lt;br /&gt;&lt;soap:Envelope&lt;br /&gt;    xmlns:soap='http://www.w3.org/2003/05/soap-envelope'&lt;br /&gt;    xmlns:xmlmime='http://www.w3.org/2004/11/xmlmime'&gt;&lt;br /&gt;  &lt;soap:Body&gt;&lt;br /&gt;    &lt;m:data xmlns:m='http://example.org/stuff'&gt;&lt;br /&gt;      &lt;m:photo &lt;br /&gt;  xmlmime:contentType='image/png'&gt;&lt;xop:Include &lt;br /&gt;    xmlns:xop='http://www.w3.org/2004/08/xop/include' &lt;br /&gt;    href='cid:http://example.org/me.png'/&gt;&lt;/m:photo&gt;&lt;br /&gt;      &lt;m:sig &lt;br /&gt;  xmlmime:contentType='application/pkcs7-signature'&gt;&lt;xop:Include &lt;br /&gt;    xmlns:xop='http://www.w3.org/2004/08/xop/include' &lt;br /&gt;    href='cid:http://example.org/my.hsh'/&gt;&lt;/m:sig&gt;&lt;br /&gt;    &lt;/m:data&gt;&lt;br /&gt;  &lt;/soap:Body&gt;&lt;br /&gt;&lt;/soap:Envelope&gt;&lt;br /&gt;&lt;br /&gt;--MIME_boundary&lt;br /&gt;Content-Type: image/png&lt;br /&gt;Content-Transfer-Encoding: binary&lt;br /&gt;Content-ID: &lt;http://example.org/me.png&gt;&lt;br /&gt;&lt;br /&gt;// binary octets for png&lt;br /&gt;&lt;br /&gt;--MIME_boundary&lt;br /&gt;Content-Type: application/pkcs7-signature&lt;br /&gt;Content-Transfer-Encoding: binary&lt;br /&gt;Content-ID: &lt;http://example.org/my.hsh&gt;&lt;br /&gt;&lt;br /&gt;// binary octets for signature&lt;br /&gt;&lt;br /&gt;--MIME_boundary--&lt;br /&gt;&lt;br /&gt;Example 3 shows an XML Infoset prior to XOP processing. Example 4 shows the same Infoset, serialized using the XOP format in a MIME Multipart/Related package. The base64-encoded content of the m:photo and m:sig elements have been replaced by a xop:Include element, while the binary octets have been serialized in separate MIME parts. Note also that the sample base64 data is smaller than would be typical and the binary octets are not shown; in practice, the optimized form is likely to be much smaller than the original.&lt;br /&gt;Example: XML Infoset prior to XOP processing (Example 3, non-SOAP)&lt;br /&gt;&lt;br /&gt;&lt;m:data xmlns:m='http://example.org/stuff'&gt;&lt;br /&gt;  &lt;m:photo&gt;/aWKKapGGyQ=&lt;/m:photo&gt;&lt;br /&gt;  &lt;m:sig&gt;Faa7vROi2VQ=&lt;/m:sig&gt;&lt;br /&gt;&lt;/m:data&gt;&lt;br /&gt;&lt;br /&gt;Example: XML Infoset serialized as a XOP package (Example 4, non-SOAP)&lt;br /&gt;&lt;br /&gt;MIME-Version: 1.0&lt;br /&gt;Content-Type: Multipart/Related;boundary=MIME_boundary;&lt;br /&gt;    type="application/xop+xml";&lt;br /&gt;    start="&lt;mymessage.xml@example.org&gt;";&lt;br /&gt;    start-info="text/xml"&lt;br /&gt;Content-Description: An XML document with my pic and sig in it&lt;br /&gt;&lt;br /&gt;--MIME_boundary&lt;br /&gt;Content-Type: application/xop+xml; &lt;br /&gt;    charset=UTF-8; &lt;br /&gt;    type="text/xml"&lt;br /&gt;Content-Transfer-Encoding: 8bit&lt;br /&gt;Content-ID: &lt;mymessage.xml@example.org&gt;&lt;br /&gt;&lt;br /&gt;&lt;m:data xmlns:m='http://example.org/stuff'&gt;&lt;br /&gt;  &lt;m:photo&gt;&lt;xop:Include &lt;br /&gt;  xmlns:xop='http://www.w3.org/2004/08/xop/include' &lt;br /&gt;  href='cid:http://example.org/me.png'/&gt;&lt;/m:photo&gt;&lt;br /&gt;  &lt;m:sig&gt;&lt;xop:Include &lt;br /&gt;  xmlns:xop='http://www.w3.org/2004/08/xop/include' &lt;br /&gt;  href='cid:http://example.org/my.hsh'/&gt;&lt;/m:sig&gt;&lt;br /&gt;&lt;/m:data&gt;&lt;br /&gt;&lt;br /&gt;--MIME_boundary&lt;br /&gt;Content-Type: image/png&lt;br /&gt;Content-Transfer-Encoding: binary&lt;br /&gt;Content-ID: &lt;http://example.org/me.png&gt;&lt;br /&gt;&lt;br /&gt;// binary octets for png&lt;br /&gt;&lt;br /&gt;--MIME_boundary&lt;br /&gt;Content-Type: application/pkcs7-signature&lt;br /&gt;Content-Transfer-Encoding: binary&lt;br /&gt;Content-ID: &lt;http://example.org/my.hsh&gt;&lt;br /&gt;&lt;br /&gt;// binary octets for signature&lt;br /&gt;&lt;br /&gt;--MIME_boundary--&lt;br /&gt;&lt;br /&gt;1.3 Notational Conventions&lt;br /&gt;&lt;br /&gt;The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC 2119].&lt;br /&gt;&lt;br /&gt;This specification uses a number of namespace prefixes throughout; they are listed below. Note that the choice of any namespace prefix is arbitrary and not semantically significant.&lt;br /&gt;Prefixes and Namespaces used in this specification.Prefix Namespace&lt;br /&gt;Notes&lt;br /&gt;xop "http://www.w3.org/2004/08/xop/include"&lt;br /&gt;A non-normative XML Schema [XML Schema Part 1: Structures Second Edition], [XML Schema Part 2: Datatypes Second Edition] document for the "http://www.w3.org/2004/08/xop/include" namespace can be found at http://www.w3.org/2004/08/xop/include. Note that XML Schema &gt; currently provides only for validation of XML 1.0 Infosets; accordingly, &gt; the schema may not be usable &gt; with XOP Infosets corresponding to later versions of XML.&lt;br /&gt;xmlmime "http://www.w3.org/2004/11/xmlmime"&lt;br /&gt;The namespace for the content type attribute.&lt;br /&gt;soap "http://www.w3.org/2003/05/soap-envelope"&lt;br /&gt;The SOAP 1.2 namespace[SOAP12].&lt;br /&gt;xs "http://www.w3.org/2001/XMLSchema"&lt;br /&gt;The namespace of XML Schema data types [XML Schema Part 2: Datatypes Second Edition].&lt;br /&gt;Editorial note: HR  &lt;br /&gt;Note that the "http://www.w3.org/2004/11/xmlmime" URI is not final and will be changed to track the evolution of the "Assigning Media Types to Binary Data in XML" document.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-2745557100916708150?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/2745557100916708150/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=2745557100916708150' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/2745557100916708150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/2745557100916708150'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/xml-binary-optimized-packaging.html' title='XML-binary Optimized Packaging'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-1804561800954706036</id><published>2008-03-12T23:47:00.001-05:00</published><updated>2008-03-12T23:47:45.873-05:00</updated><title type='text'>Gate Methodology</title><content type='html'>Everyone has heard the horror stories of cost overruns on SAP programmes. While there are a few factors which are outside the control of the programme managers (e.g. business change, funding withdrawn) the majority of the responsibility lies at their door.&lt;br /&gt;&lt;br /&gt;From the programme managers viewpoint it is essential to get early warning that things are starting to slip. One of the quickest way to lose your job is to surprise your board 4 weeks from go-live with the message that the programme is 6 months late.&lt;br /&gt;&lt;br /&gt;One of the best ways to get this early warning is through implementing a gate methodology which forces a structured review of the programme at pre-defined checkpoints along the way. In essence you build gates at the exit points of the major phases of the programme. Naturally these are also the entrance points to the next major phase. &lt;br /&gt;&lt;br /&gt;Let's assume that you have five major phases as follows: Scope &amp; Plan, Design, Build, Test, Go-Live. You would then have five major gates as well - each positioned at the exit point of the five phases: Gate 1 - Exit Scope &amp; Plan, Gate 2 - Exit Design, Gate 3 - Exit Build, Gate 4 - Exit Test and Gate 5 - Go-Live. Potential criteria for each of these gates could be as follows:&lt;br /&gt;&lt;br /&gt;Gate 1 - Exit Scope &amp; Plan&lt;br /&gt;&lt;br /&gt;Is there a scope document, and does it cover all aspects of scope including functionality requirements, modules to be implemented, geography, gaps, interfaces, organisational aspects, technical aspects, data conversion etc &lt;br /&gt;Is there a plan, and does it include detailed tasks (nothing longer than two weeks), with resource names mapped to tasks, and is it resource balanced (no simple task) &lt;br /&gt;Is the design team mobilised &lt;br /&gt;Is there a design authority in place, and is the change control process agreed &lt;br /&gt;Is the sandbox SAP system ready, and is there a client strategy document agreed &lt;br /&gt;Gate 2 - Exit Design&lt;br /&gt;&lt;br /&gt;Has the design been documented, including SAP transactions identified, and signed off by the business. A design walkthrough is strongly recommended. &lt;br /&gt;Have critical areas of the design (depending on your business) been prototyped in the sandbox &lt;br /&gt;Have all gaps and interfaces been identified, specified and estimated &lt;br /&gt;Has the data required been identified and mapped to legacy (ignore this at your peril), and have the data conversion programmes been identified and specified at a high level &lt;br /&gt;Have the roles required been identified &lt;br /&gt;Have control requirements been identified &lt;br /&gt;Has the plan been updated, and (if necessary) the scope document updated &lt;br /&gt;Gate 3 - Exit Build&lt;br /&gt;&lt;br /&gt;Has the system been fully built and unit tested in the development system (not the sandbox), and signed off by the business. A config walkthrough is strongly recommended. &lt;br /&gt;Have the gaps and interfaces been fully built and unit tested (this is a grey area) &lt;br /&gt;Have the data conversion programmes been built and unit tested (this is not a grey area) &lt;br /&gt;Has the system gone through any scenario-based validation (a step up from unit testing). It is probably best to include this in the Design phase since you cannot be fully satisfied your requirements have been met until you run business scenarios through the system. &lt;br /&gt;Has the configuration been fully documented, and the design documentation updated (if necessary) &lt;br /&gt;Have the roles been built &lt;br /&gt;Have the control requirements been built &lt;br /&gt;Has the plan been updated, and (if necessary) the scope document updated &lt;br /&gt;Gate 4 - Exit Test&lt;br /&gt;&lt;br /&gt;Has the system been fully tested in the test system (not the development system), and signed off by the business. A test walkthrough is strongly recommended. &lt;br /&gt;Have the gaps, interfaces and data conversion programmes been fully tested and signed off &lt;br /&gt;Have the user procedures been documented and tested &lt;br /&gt;Has the training material been completed and tested &lt;br /&gt;Has the system been tested by running converted data through it (warning: expect to do this four or five times before it works properly) &lt;br /&gt;Have all critical test problems been resolved. &lt;br /&gt;Gate 5 - Go-Live (done a few days prior to go-live)&lt;br /&gt;&lt;br /&gt;Have the users been trained &lt;br /&gt;Are the user procedures in place &lt;br /&gt;Is the user documentation in place &lt;br /&gt;Did the data conversion work &lt;br /&gt;Is the support team in place &lt;br /&gt;Is your 'cutover control room' ready, manned 24 hrs, and have detailed cutover plans in place (this might have started already for the data conversion) &lt;br /&gt;Have you done a trial cutover &lt;br /&gt;Do you have a contingency plan &lt;br /&gt;Everyone feeling well rested? Then push the button!  &lt;br /&gt;For the programme to actually exit the gate, you hold a gate meeting at which each team is required to demonstrate (not only verbally claim) why the feel that they have satisfied all the criteria. Pre-gate meetings will probably be required about 4 weeks out to help the teams finalise their positions. usually, but not always, post-gate meetings are required where teams resolve any issues which arose during the gate meeting itself.&lt;br /&gt;&lt;br /&gt;Properly implemented and executed, a gate methodology provides and excellent early warning system and should be looked at by every project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-1804561800954706036?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/1804561800954706036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=1804561800954706036' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1804561800954706036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1804561800954706036'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/gate-methodology.html' title='Gate Methodology'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-5526196656378121668</id><published>2008-03-11T11:32:00.000-05:00</published><updated>2008-03-11T11:34:13.644-05:00</updated><title type='text'>Basic Knowledge and System Navigation Question</title><content type='html'>What SPRO stands for? &lt;br /&gt;&lt;br /&gt;SPRO stands for SAP Project Reference Object &lt;br /&gt;. &lt;br /&gt;It is used to configure the setting as per your client requirement by using the standard setting present in the system.  This where you can do all the SAP configuration work.  It is also known as the Configuration Menu. &lt;br /&gt;&lt;br /&gt;What is full form IMG and SPRO? How are they different from each other? &lt;br /&gt;&lt;br /&gt;IMG    :-  Implementation Guide. &lt;br /&gt;SPRO :-  SAP Project Reference Object. &lt;br /&gt;&lt;br /&gt;SPRO------&gt;IMG. &lt;br /&gt;&lt;br /&gt;Type in the T-Code SPRO under That got to Main Menu which is IMG. &lt;br /&gt;&lt;br /&gt;SPRO is basically used to organize the consultant customizing during the SAP Project Phrase. &lt;br /&gt;&lt;br /&gt;How to close a window? &lt;br /&gt;&lt;br /&gt;If we want to stop a transaction in the middle, Right click on the end button (X) on the top right corner of the window. Then select "stop transaction". &lt;br /&gt;As we dont have STOP icon as we have in WINDOWS, this will help in the same way. &lt;br /&gt;&lt;br /&gt;Its a very small tip, but will help a lot. &lt;br /&gt;&lt;br /&gt;Tips by : Bhaskar &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Name two ways to start a transaction. &lt;br /&gt;- Dynamic Menu &lt;br /&gt;- Command Field &lt;br /&gt;&lt;br /&gt;Why do you create user-specific parameters? &lt;br /&gt;They supply defaults to R/3 fields. If a field is indicated, the system automatically fills in default value. Depending on the field definition, the entry can also be replaced with a value entered by the user. (Concept of PARAMETER ID) &lt;br /&gt;&lt;br /&gt;Name the three different kinds of messages in the R/3 system. What is the difference between them? &lt;br /&gt;A message can have five different types. These message types have the following effects during list processing: &lt;br /&gt;&lt;br /&gt;A (=Abend): &lt;br /&gt;The system displays a message of this message type in a dialog window. After the user confirms the message using ENTER, the system terminates the entire transaction (for example SE38). &lt;br /&gt;&lt;br /&gt;E (=Error) or W (=Warning): &lt;br /&gt;The system displays a message of this message type in the status line. After the user chooses ENTER, the system acts as follows: &lt;br /&gt;While creating the basic list, the system terminates the report. &lt;br /&gt;While creating a secondary list, the system terminates the corresponding processing block and keeps displaying the previous list level. &lt;br /&gt;&lt;br /&gt;I (=Information): &lt;br /&gt;The system displays a message of this message type in a dialog window. After the user chooses ENTER , the system resumes processing at the current program position. &lt;br /&gt;&lt;br /&gt;S (=Success): &lt;br /&gt;The system displays a message of this message type on the output screen in the status line of the currently created list. &lt;br /&gt;&lt;br /&gt;What is a data dictionary or repository? &lt;br /&gt;Central catalog that contains the descriptions of an organization's data and provides information about the relationships between the data and its use in programs and screens. &lt;br /&gt;The data descriptions in a Data Dictionary is also called metadata, i.e., data that describes other data. &lt;br /&gt;&lt;br /&gt;The ABAP/4 Dictionary stores system-wide data definitions. When you create a new data definition, the Dictionary tool does all the processing necessary to create the definition. You can use the Dictionary tool to look up the "definition" of objects in your R/3 System. &lt;br /&gt;&lt;br /&gt;What is a matchcode? &lt;br /&gt;Comparsion key. A matchcode allows you to locate the key of a particular database record (e.g. account number) by entering any field value contained in the record. The system then displays a list of records matching the specifications. &lt;br /&gt;&lt;br /&gt;If you want an end user to see a specific menu after logging on the R/3 system, how could you do that? &lt;br /&gt;User maintenance transactions allow the system administrator to create and maintain user master records. This includes the generation and assignment of authorizations and authorization profiles.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-5526196656378121668?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/5526196656378121668/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=5526196656378121668' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/5526196656378121668'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/5526196656378121668'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/basic-knowledge-and-system-navigation.html' title='Basic Knowledge and System Navigation Question'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-1480256444640429395</id><published>2008-03-08T00:16:00.000-05:00</published><updated>2008-03-08T00:17:12.392-05:00</updated><title type='text'>D Programming Language</title><content type='html'>The first D Programming Language Conference took place in Seattle at Amazon, Aug 23..24, 2007.&lt;br /&gt;&lt;br /&gt;D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. Special attention is given to the needs of quality assurance, documentation, management, portability and reliability. &lt;br /&gt;&lt;br /&gt;The D language is statically typed and compiles directly to machine code. It's multiparadigm, supporting many programming styles: imperative, object oriented, and metaprogramming. It's a member of the C syntax family, and its appearance is very similar to that of C++. For a quick comparison of the features, see this comparison of D with C, C++, C# and Java.&lt;br /&gt;&lt;br /&gt;It is not governed by a corporate agenda or any overarching theory of programming. The needs and contributions of the D programming community form the direction it goes. &lt;br /&gt;&lt;br /&gt;There are currently two implementations, the Digital Mars DMD package for Win32 and x86 Linux, and the GCC D Compiler package for several platforms, including Windows and Mac OS X. &lt;br /&gt;&lt;br /&gt;A large and growing collection of D source code and projects are at dsource. More links to innumerable D wikis, libraries, tools, media articles, etc. are at dlinks. &lt;br /&gt;&lt;br /&gt;This document is available as a pdf, as well as in Japanese and Portugese translations. A Japanese book D Language Perfect Guide is available. &lt;br /&gt;&lt;br /&gt;This is an example D program illustrating some of the capabilities:&lt;br /&gt;&lt;br /&gt;#!/usr/bin/dmd -run&lt;br /&gt;/* sh style script syntax is supported */&lt;br /&gt;&lt;br /&gt;/* Hello World in D&lt;br /&gt;   To compile:&lt;br /&gt;     dmd hello.d&lt;br /&gt;   or to optimize:&lt;br /&gt;     dmd -O -inline -release hello.d&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;import std.stdio;&lt;br /&gt;&lt;br /&gt;void main(string[] args)&lt;br /&gt;{&lt;br /&gt;    writefln("Hello World, Reloaded");&lt;br /&gt;&lt;br /&gt;    // auto type inference and built-in foreach&lt;br /&gt;    foreach (argc, argv; args)&lt;br /&gt;    {&lt;br /&gt;        // Object Oriented Programming&lt;br /&gt;        auto cl = new CmdLin(argc, argv);&lt;br /&gt;        // Improved typesafe printf&lt;br /&gt;        writefln(cl.argnum, cl.suffix, " arg: %s", cl.argv);&lt;br /&gt;        // Automatic or explicit memory management&lt;br /&gt;        delete cl;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // Nested structs and classes&lt;br /&gt;    struct specs&lt;br /&gt;    {&lt;br /&gt;        // all members automatically initialized&lt;br /&gt;        int count, allocated;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // Nested functions can refer to outer&lt;br /&gt;    // variables like args&lt;br /&gt;    specs argspecs()&lt;br /&gt;    {&lt;br /&gt;        specs* s = new specs;&lt;br /&gt;        // no need for '-&gt;'&lt;br /&gt;        s.count = args.length;     // get length of array with .length&lt;br /&gt;        s.allocated = typeof(args).sizeof; // built-in native type properties&lt;br /&gt;        foreach (argv; args)&lt;br /&gt;            s.allocated += argv.length * typeof(argv[0]).sizeof;&lt;br /&gt;        return *s;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // built-in string and common string operations&lt;br /&gt;    writefln("argc = %d, " ~ "allocated = %d",&lt;br /&gt; argspecs().count, argspecs().allocated);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class CmdLin&lt;br /&gt;{&lt;br /&gt;    private int _argc;&lt;br /&gt;    private string _argv;&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;    this(int argc, string argv) // constructor&lt;br /&gt;    {&lt;br /&gt;        _argc = argc;&lt;br /&gt;        _argv = argv;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    int argnum()&lt;br /&gt;    {&lt;br /&gt;        return _argc + 1;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    string argv()&lt;br /&gt;    {&lt;br /&gt;        return _argv;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    string suffix()&lt;br /&gt;    {&lt;br /&gt;        string suffix = "th";&lt;br /&gt;        switch (_argc)&lt;br /&gt;        {&lt;br /&gt;          case 0:&lt;br /&gt;            suffix = "st";&lt;br /&gt;            break;&lt;br /&gt;          case 1:&lt;br /&gt;            suffix = "nd";&lt;br /&gt;            break;&lt;br /&gt;          case 2:&lt;br /&gt;            suffix = "rd";&lt;br /&gt;            break;&lt;br /&gt;          default:&lt;br /&gt;     break;&lt;br /&gt;        }&lt;br /&gt;        return suffix;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;Note: all D users agree that by downloading and using D, or reading the D specs, they will explicitly identify any claims to intellectual property rights with a copyright or patent notice in any posted or emailed feedback sent to Digital Mars.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-1480256444640429395?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/1480256444640429395/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=1480256444640429395' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1480256444640429395'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1480256444640429395'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/d-programming-language.html' title='D Programming Language'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-1644263925401217992</id><published>2008-03-04T02:27:00.000-05:00</published><updated>2008-03-04T02:28:26.461-05:00</updated><title type='text'>Common .NET Naming Conventions</title><content type='html'>These are the industry-accepted standard naming conventions for J#, C# and VB.NET programs. For additional information, please see the MSDN help documentation and FX Cop. While individual naming conventions at organizations may vary (Microsoft only suggests conventions for public and protected items), the list below is quickly becoming the de-facto standard in the industry. Please note the absence of Hungarian Notation except in visual controls. These naming standards should find their way into all of your .NET development, including ASP.NET Web applications and .NET Windows Forms applications.&lt;br /&gt;&lt;br /&gt;Note that while this document predates the online and printed standards documentation from Microsoft, everything below which indicates it is based on .NET library standards is consistent with that documentation. In areas where Microsoft has not provided guidance (Microsoft generally doesn't care what you do in private/non-exposed code. In fact, they aren't even consistant in their internal code in the .NET framework), de facto standards have emerged, and I have captured them here.&lt;br /&gt;&lt;br /&gt;The "ux" naming convention for controls is something I have added and found to be helpful. It is not based on any official standards, but instead based upon a multitude of projects by my teams and others, as well as on-line discussions on the topic. While I strongly recommend that you follow Microsoft guidelines when present, I encourage you to try out the items marked as extensions below and see how they work for you before committing to them.&lt;br /&gt;&lt;br /&gt;Type Standard / Convention Example &lt;br /&gt;Namespaces Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Pascal Case, no underscores. Use CompanyName.TechnologyName as root. If you don't have a company, use your domain name or your own initials. Note that any acronyms of three or more letters should be pascal case (Xml instead of XML) instead of all caps.&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; AppliedIS.TimeCard.BusinessRules&lt;br /&gt;IrritatedVowel.Controllers&lt;br /&gt;PeteBrown.DotNetTraining.InheritanceDemo PeteBrown.DotNetTraining.Xml  &lt;br /&gt;Assemblies Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;If the assembly contains a single name space, or has an entire self-contained root namespace, name the assembly the same name as the namespace.&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read. More importantly, however, it keeps your assembly names and namespaces lined up, making it really easy to figure out what is any particular assembly, and what assembly you need to reference for any given class.&lt;br /&gt; AppliedIS.TimeCard.BusinessRules.dll&lt;br /&gt;IrritatedVowel.Controllers.dll&lt;br /&gt; &lt;br /&gt;Classes and Structs Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Pascal Case, no underscores or leading "C" or "cls". Classes may begin with an "I" only if the letter following the I is not capitalized, otherwise it looks like an Interface. Classes should not have the same name as the namespace in which they reside. Any acronyms of three or more letters should be pascal case, not all caps. Try to avoid abbreviations, and try to always use nouns.&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; Widget&lt;br /&gt;InstanceManager&lt;br /&gt;XmlDocument&lt;br /&gt;MainForm&lt;br /&gt;DocumentForm&lt;br /&gt;HeaderControl&lt;br /&gt;CustomerListDataSet (typed dataset) &lt;br /&gt; &lt;br /&gt;Collection Classes Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Follow class naming conventions, but add Collection to the end of the name&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; WidgetCollection &lt;br /&gt;Delegate Classes Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Follow class naming conventions, but add Delegate to the end of the name&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; WidgetCallbackDelegate &lt;br /&gt;Exception Classes Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Follow class naming conventions, but add Exception to the end of the name&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; InvalidTransactionException &lt;br /&gt;Attribute Classes Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Follow class naming conventions, but add Attribute to the end of the name&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; WebServiceAttribute &lt;br /&gt;Interfaces Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Follow class naming conventions, but start the name with "I" and capitalize the letter following the "I"&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read. It also distinguishes classes from interfaces, where (unlike in VB6) are truly different beings. This avoid name collisions as well, as it is quite common to have IFoo and a class named Foo that implements IFoo.&lt;br /&gt; IWidget &lt;br /&gt;Enumerations Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Follow class naming conventions. Do not add "Enum" to the end of the enumeration name. If the enumeration represents a set of bitwise flags, end the name with a plural.&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; SearchOptions (bitwise flags)&lt;br /&gt;&lt;br /&gt;AcceptRejectRule (normal enum)&lt;br /&gt; &lt;br /&gt;Functions and Subs Standard Based Upon Microsoft .NET Library Standards &lt;br /&gt;&lt;br /&gt;Pascal Case, no underscores except in the event handlers. Try to avoid abbreviations. Many programmers have a nasty habit of overly abbreviating everything. This should be discouraged. &lt;br /&gt;&lt;br /&gt;Functions and subs must differ by more than case to be usable from case-insensitive languages like Visual Basic .NET&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; VB: Public Sub DoSomething(...)&lt;br /&gt;&lt;br /&gt;C#: public void DoSomething(...) &lt;br /&gt; &lt;br /&gt;Properties and Public * Member Variables Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Pascal Case, no underscores. Try to avoid abbreviations. Members must differ by more than case to be usable from case-insensitive languages like Visual Basic .NET.&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; VB: Public Property RecordID As Integer&lt;br /&gt;&lt;br /&gt;C#: public int RecordID&lt;br /&gt; &lt;br /&gt;Parameters Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Camel Case. Try to avoid abbreviations. Parameters must differ by more than case to be usable from case-insensitive languages like Visual Basic .NET.&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read.&lt;br /&gt; VB: ByRef recordID As Integer&lt;br /&gt;&lt;br /&gt;C#: ref int recordID&lt;br /&gt; &lt;br /&gt;Procedure-Level Variables Standard Based Upon De facto Industry-Accepted Practices&lt;br /&gt;&lt;br /&gt;Camel Case&lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read. It also avoids naming collisions with class-level variables (see below)&lt;br /&gt; VB: Dim recordID As Integer&lt;br /&gt;&lt;br /&gt;C#: int recordID ;&lt;br /&gt; &lt;br /&gt;Class-Level Private and Protected Variables Standard Based Upon De facto Industry-Accepted Practices&lt;br /&gt;&lt;br /&gt;Camel Case with Leading Underscore. In VB.NET, always indicate "Protected" or "Private", do not use "Dim". Use of "m_" is discouraged, as is use of a variable name that differs from the property by only case, especially with protected variables as that violates compliance, and will make your life a pain if you program in VB.NET, as you would have to name your members something different from the accessor/mutator properties.&lt;br /&gt;&lt;br /&gt;Of all the items here, the leading underscore is really the only controversial one. I personally prefer it over straight underscore-less camel case for my private variables so that I don't have to qualify variable names with "this." to distinguish from parameters in constructors or elsewhere where I likely will have a naming collision. With VB.NET's case insensitivity, this is even more important as your accessor properties will usually have the same name as your private member variables except for the underscore.&lt;br /&gt;&lt;br /&gt;As far as m_ goes, it is really just about aesthetics. I (and many others) find m_ ugly, as it looks like there is a hole in the variable name. It's almost offensive. I used to use it in VB6 all the time, but that was only because variables could not have a leading underscore. I couldn't be happier to see it go away.&lt;br /&gt;&lt;br /&gt;Microsoft recommends against the m_ (and the straight _) even though they did both in their code. Also, prefixing with a straight "m" is right out. Of course, since they code mainly in C#, they can have private members that differ only in case from the properties. VB folks have to do something else. Rather than try and come up with language-by-language special cases, I recommend the leading underscore for all languages that will support it.&lt;br /&gt;&lt;br /&gt;If I want my class to be fully CLS-compliant, I could leave off the prefix on any C# protected member variables. In practice, however, I never worry about this as I keep all potentially protected member variables private, and supply protected accessors and mutators instead.&lt;br /&gt;&lt;br /&gt;Why: In a nutshell, this convention is simple (one character), easy to read (your eye is not distracted by other leading characters), and successfully avoids naming collisions with procedure-level variables and class-level properties.&lt;br /&gt; VB: Private _recordID As Integer&lt;br /&gt;&lt;br /&gt;C#: private int _recordID ;&lt;br /&gt; &lt;br /&gt;Controls on Forms An Extension to the Standards&lt;br /&gt;&lt;br /&gt;In recent projects (since 2002 or so), I have taken to a single prefix for all my UI controls. I typically use "ux" (I used to use "ui", but it wasn't set apart well in intellisense). "ux" comes from my usual design abbreviations where it means "User eXperience", which has also since become a popular acronym. I have found this to be extremely helpful in that I get the desired grouping in the intellisense even better than if I use "txt", "lbl" etc. It also allows you to change combo boxes to text boxes etc. without having to change the names - something that happens often during initial prototyping, or when programming using highly iterative agile/xp methodologies.&lt;br /&gt;&lt;br /&gt;Why: This convention avoids problems with changing control types (textboxes to drop-down lists, or simple text box to some uber textbox, or text box to date picker, for example), and groups the items together in intellisense. It is also much shorter than most Hungarian conventions, and definitely shorter and less type-dependent than appending the control type to the end of the variable name. I will use generic suffixes which allow me enough freedom to change them around.&lt;br /&gt; "ux" prefix&lt;br /&gt;&lt;br /&gt;uxUserID, uxHeader, uxPatientDateOfBirth, uxSubmit&lt;br /&gt; &lt;br /&gt;Constants Standard Based Upon Microsoft .NET Library Standards&lt;br /&gt;&lt;br /&gt;Same naming conventions as public/private member variables or procedure variables of the same scope. If exposed publicly from a class, use PascalCase. If private to a function/sub, use camelCase..&lt;br /&gt;&lt;br /&gt;Do not use SCREAMING_CAPS &lt;br /&gt;&lt;br /&gt;Why: This convention is consistent with the .NET Framework and is easy to read. A sizable section of the Framework Design Guidelines is dedicated to why they chose not to go the SCREAMING_CAPS route. Using SCREAMING_CAPS also exposes more of the implementation than is necessary. Why should a consumer need to know if you have an enum, or (perhaps because they are strings) a class exposing public constants? In the end, you often want to treat them the same way, and black-box the implementation. This convention satisfies that criteria.&lt;br /&gt; SomeClass.SomePublicConstant&lt;br /&gt;&lt;br /&gt;localConstant&lt;br /&gt;&lt;br /&gt;_privateClassScopedConstant&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-1644263925401217992?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/1644263925401217992/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=1644263925401217992' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1644263925401217992'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/1644263925401217992'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/common-net-naming-conventions.html' title='Common .NET Naming Conventions'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-3651705606244064435</id><published>2008-03-02T03:16:00.000-05:00</published><updated>2008-03-02T03:17:56.918-05:00</updated><title type='text'>case and loops in java Part 1</title><content type='html'>The switch statement in Java provides a convenient method for branching a program based on a number of conditionals. This recipe describes the use of the Java switch statement.&lt;br /&gt;The basic format of a switch statement in Java is: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;switch (expression) { &lt;br /&gt;    case cond1: code_block_1; &lt;br /&gt;    case cond2: code_block_2; &lt;br /&gt;          ... &lt;br /&gt;    case condn: code_block_n; &lt;br /&gt;    default: code_block_default; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;where expression is an integral expression (like int, char, short, or byte, but not long). In each case statement within the switch statement, a comparison is made which is equivalent to if (expression == cond1). If the comparison evaluates to true, the code within the block is executed. The final default: line is analogous to a final else statement. &lt;br /&gt;&lt;br /&gt;This arrangement is similar to a cascade of if/else if/else if statements but with one substantial difference. At the end of each code block, an optional break statement alters the flow through the switch statement. Without any break statements, all subsequent code blocks will be executed once a true evaulation is found. To make a switch statement behave just like an if/else if/else if statement, always put break statements at the end of code blocks. However, leaving out break statements can provide a capability very difficult to achieve with if statements. &lt;br /&gt;&lt;br /&gt;For example, consider the following code: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class TestSwitch { &lt;br /&gt;&lt;br /&gt;     public final static int TITANIUM = 0; &lt;br /&gt;     public final static int PLATINUM = 1; &lt;br /&gt;     public final static int GOLD     = 2; &lt;br /&gt;     public final static int SILVER   = 3; &lt;br /&gt;     public final static int TIN      = 4; &lt;br /&gt;&lt;br /&gt;     public static void main(String[] args) { &lt;br /&gt;         System.out.println("Tin  -----"); &lt;br /&gt;         printGift(TIN); &lt;br /&gt;         System.out.println("Titanium  -----"); &lt;br /&gt;         printGift(TITANIUM); &lt;br /&gt;     } &lt;br /&gt;&lt;br /&gt;     public static void printGift(int serviceLevel) { &lt;br /&gt;         switch(serviceLevel) { &lt;br /&gt;             case TITANIUM: case PLATINUM: &lt;br /&gt;                 System.out.println("  Free toaster"); &lt;br /&gt;             case GOLD: &lt;br /&gt;                 System.out.println("  Free stapler"); &lt;br /&gt;             case SILVER: case TIN: &lt;br /&gt;                 System.out.println("  Free staple remover"); &lt;br /&gt;                 break; &lt;br /&gt;             default: &lt;br /&gt;                 System.out.println("No gift"); &lt;br /&gt;         } &lt;br /&gt;     } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The example demonstrates break usage since any match will cause one or more println commands to output text but will not print the "No gift" line from the default code block. In addition, note that multiple case statements can be placed before each code block. Running this sample code results in the following output: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tin  ----- &lt;br /&gt;  Free staple remover &lt;br /&gt;Titanium  ----- &lt;br /&gt;  Free toaster &lt;br /&gt;  Free stapler &lt;br /&gt;  Free staple remover &lt;br /&gt;The for loop provides a simple mechanism for repeating a code block a fixed number of times or for iterating through a set of values. &lt;br /&gt;The generic syntax for a Java for loop is: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for ( {initialization}; {exit condition}; {incrementor} ) &lt;br /&gt;     code_block;&lt;br /&gt;&lt;br /&gt;For example, to execute a simple loop 5 times printing out the iteration number each time through the loop: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for ( i=1; i&lt;6; i++ ) { &lt;br /&gt;    System.out.println(i); &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In this example, the loop starts with an initialization of the (int) variable i to the value 1. Each time the loop iteration starts, a the exit condition is evaluated (is i less than 6?) and if true, continues. When the loop iteration is complete, the incrementor code is executed (i++ means increment the variable i by one). The loop continues until the exit condition is met (when i is equal to or greater than 6), so the code block will be executed for i values of 1, 2, 3, 4, and 5. &lt;br /&gt;&lt;br /&gt;The exit condition code can be more complex as needed because it is computed each time through the loop, so the condition can be based on variables which may change during the loop iteration. To run a code block on each value of an array, the loop condition could be i &lt; array.length. &lt;br /&gt;&lt;br /&gt;The incrementor code can also be more complex, essentially any valid Java code. Another simple example would be a decrementor using i-- which would subtract one from the variable i each time through the loop.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-3651705606244064435?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/3651705606244064435/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=3651705606244064435' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3651705606244064435'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3651705606244064435'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/03/case-and-loops-in-java-part-1.html' title='case and loops in java Part 1'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-3431221007850998784</id><published>2008-02-29T23:43:00.000-05:00</published><updated>2008-02-29T23:47:37.069-05:00</updated><title type='text'>Developing AJAX Applications</title><content type='html'>AJAX is the buzzword of the moment among web developers, so much so that you could be sick of introductions to AJAX by now (if that's the case, skip down to "The Chat Web Page"). AJAX is a technology that is hotly debated from many angles, but it has stuck because it encapsulates something that is new from a user's perspective. The functionally that is newly available to all web users is "in-page replacement": the ability for a web page to change using data from a web server without totally redrawing itself. This functionality has been around in Mozilla and Internet Explorer for a while, but it is only recently that Safari and Konqueror users have been able to join in.&lt;br /&gt;&lt;br /&gt;It is this ability to have web pages that update dynamically that is changing the way users interact with the web. For example:&lt;br /&gt;&lt;br /&gt;Activity Old Style AJAX Style&lt;br /&gt;Scrolling in a mapping website Click on a right arrow to refresh whole page. Drag map area to the right--and watch the map scroll, like Google Maps.&lt;br /&gt;Looking up a word in a dictionary Enter the word, and click Submit to see a definition for that word. Begin typing the word, see possible matches as you type and the definitions as soon as you finish typing, like ObjectGraph Dictionary.&lt;br /&gt;Interacting in online forum Type message, click Submit, regularly click "check new messages". Type messages, and wait as new replies appear automatically without needing your interaction. We will create a site like this in this article.&lt;br /&gt;Filling out form with a number of fields Visit a number of pages of a "wizard," getting error messages about invalid fields. Fill out a form that reports on errors as you type, and can dynamically add data (like filling in full address details from a zip code) without needing a slow page refresh.&lt;br /&gt;&lt;br /&gt;AJAX isn't the best acronym in the world: it stands for Asynchronous JavaScript and XML. This does nothing to describe the benefits to a user: the technology behind it does not have to be asynchronous, and the best implementations don't necessarily use XML, either. However, the buzzword has stuck so we are better off going with the flow now.&lt;br /&gt;&lt;br /&gt;The problem for the web developer is that while this is a very attractive way of creating websites, and one where you can get started without a huge amount of effort, there are a number of pitfalls that can make life harder. All browsers have different quirks, so you can easily discover that, for example, you have locked Mac users out of the party.&lt;br /&gt;&lt;br /&gt;DWR, hosted on java.net, is an Java open source library that helps developers to write websites that include AJAX technology. Its mantra is "Easy Ajax for Java." It allows code in a web browser to use Java functions running on a web server as if they were in the browser.&lt;br /&gt;&lt;br /&gt;This article demonstrates the use of DWR to create a multi-user web-based chat site. It demonstrates how simple it is to integrate JavaScript in the web browser with Java on the server. The aim is to have a fully functional system in about 100 lines of code for both the client and the server. The emphasis will not be on fancy graphics or lots of chat features, because that would distract us from the core business of how to write AJAX code without lots of effort.&lt;br /&gt;&lt;br /&gt;The Chat Web Page&lt;br /&gt;The web page has two parts: one area where you can see the messages that others type, and an input field where you can type messages yourself. Figure 1 shows what it looks like.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Figure 1. The chat web page&lt;br /&gt;&lt;img src="http://today.java.net/images/2005/08/example.gif" border="0" /&gt;&lt;br /&gt;The HTML is very simple:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Messages:&lt;/p&gt;&lt;br /&gt;&lt;div id="chatlog"&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Your Message:&lt;br /&gt;&lt;input id="text"&gt;&lt;br /&gt;&lt;input onclick="sendMessage()" type="button" value="Send"&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;We'll come to the JavaScript code in a bit, but let's start with the server side. Just how much code do you need for a multi-user web-based chat system?&lt;br /&gt;&lt;br /&gt;Server-Side Java&lt;br /&gt;We have two classes to do the server-side work. The first is the Message class that holds a single string entered by the user. The Message also maintains a unique ID as a property. For now, we are going to cheat by using the current time in milliseconds as the ID:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class Message&lt;br /&gt;{&lt;br /&gt;public Message(String newtext)&lt;br /&gt;{&lt;br /&gt;text = newtext;&lt;br /&gt;if (text.length() &gt; 256)&lt;br /&gt;{&lt;br /&gt;text = text.substring(0, 256);&lt;br /&gt;}&lt;br /&gt;text = text.replace('&lt;', '['); text = text.replace('&amp;amp;', '_'); } public long getId() { return id; } public String getText() { return text; } long id = System.currentTimeMillis(); String text; } The constructor does a few simple things: it shortens messages to 256 characters and replaces &lt;&gt; 0)&lt;br /&gt;{&lt;br /&gt;messages.addFirst(new Message(text));&lt;br /&gt;while (messages.size() &gt; 10)&lt;br /&gt;{&lt;br /&gt;messages.removeLast();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return messages;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public List getMessages()&lt;br /&gt;{&lt;br /&gt;return messages;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static LinkedList messages =new LinkedList();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;And that's it for the server-side code!&lt;br /&gt;&lt;br /&gt;Two of these methods are important from the web browser's point of view: addMessage(), which is called in response to a user typing in the input area, and getMessages(), which is polled from time to time to see if anyone else has said anything.&lt;br /&gt;&lt;br /&gt;Configuring DWR&lt;br /&gt;Now we need to remote these two methods to the web browser. The first step is to copy dwr.jar into your web app. You can download dwr.jar from its java.net project. Next, you need to configure your app server's web.xml to understand DWR. The standard bit of code looks like this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;servlet&gt;&lt;br /&gt;&lt;servlet-name&gt;dwr-invoker&lt;/SERVLET-NAME&gt;&lt;br /&gt;&lt;display-name&gt;DWR Servlet&lt;/DISPLAY-NAME&gt;&lt;br /&gt;&lt;servlet-class&gt;uk.ltd.getahead.dwr.DWRServlet&lt;/SERVLET-CLASS&gt;&lt;br /&gt;&lt;init-param&gt;&lt;br /&gt;&lt;param-name&gt;debug&lt;/PARAM-NAME&gt;&lt;br /&gt;&lt;param-value&gt;true&lt;/PARAM-VALUE&gt;&lt;br /&gt;&lt;/INIT-PARAM&gt;&lt;br /&gt;&lt;/servlet&gt;&lt;br /&gt;&lt;servlet-mapping&gt;&lt;br /&gt;&lt;servlet-name&gt;dwr-invoker&lt;/SERVLET-NAME&gt;&lt;br /&gt;&lt;url-pattern&gt;/dwr/*&lt;/URL-PATTERN&gt;&lt;br /&gt;&lt;/SERVLET-MAPPING&gt;&lt;br /&gt;&lt;br /&gt;Finally, you need to tell DWR about the chat server you just created. Specifically, you need to tell it two things:&lt;br /&gt;&lt;br /&gt;That Chat is safe to be remoted to the browser.&lt;br /&gt;That Message is allowed as a parameter.&lt;br /&gt;DWR could do the second bit for you, but we'll do it this way to make sure that you don't give away access to anything by mistake. The DWR configuration file, dwr.xml, is placed alongside web.xml in your WEB-INF folder. For your chat application, dwr.xml should look like this (obviously, replace the [your.package] bits with the package that you used from the code above):&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dwr&gt;&lt;br /&gt;&lt;allow&gt;&lt;br /&gt;&lt;create javascript="Chat" creator="new"&gt;&lt;br /&gt;&lt;param value="[your.package].Chat" name="class"&gt;&lt;br /&gt;&lt;/create&gt;&lt;br /&gt;&lt;convert match="[your.package].Message" converter="bean"&gt;&lt;br /&gt;&lt;/allow&gt;&lt;br /&gt;&lt;/dwr&gt;&lt;br /&gt;&lt;br /&gt;We are telling DWR it is OK to create Chat classes for remoting to the browser, and that in JavaScript they will be called 'Chat'. It also says that Message is safe to use as a parameter.&lt;br /&gt;&lt;br /&gt;The Client-Side Scripting&lt;br /&gt;The final bit is the JavaScript that is fired off by the HTML to call into the Java code. The good news is that DWR makes this bit easy. Typically, the JavaScript code for this type of thing would contain complex XMLHttpRequest code, DOM manipulation, and parameter collation. With DWR, you don't worry about any of that.&lt;br /&gt;&lt;br /&gt;First we include the JavaScript that tells the browser about the Chat code. There are there useful script lines:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="/[YOUR-WEB-APP]/dwr/engine.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="/[YOUR-WEB-APP]/dwr/interface/Chat.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="/[YOUR-WEB-APP]/dwr/util.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;The script engine.js contains the core of DWR. Generally, you just include it as is, and then ignore it. There are a few methods in it that are sometimes useful, but you can see the full documentation for them at the DWR website. The script util.js contains some utility functions that are totally optional, but will help you greatly in getting anything done with DWR. Chat.js is dynamically generated by DWR as the remote version of Chat.java. If you look at it, you'll see something like this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Chat.addMessage = function(callback, p0) { ... }&lt;br /&gt;Chat.getMessages = function(callback) { ... }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DWR does everything it can to make the JavaScript version of your Java code as simple as possible, but there are some things you need to be aware of. The most obvious is that the "A" in AJAX stands for asynchronous; so by definition, the remote method is not executed the instant your JavaScript code is executed. This would not be an issue, except for the complexity of knowing what to do with the values returned by Java to the browser. DWR solves the problem by asking for a callback method, to which it will pass the returned data. The first parameter to any DWR-generated method is always the callback function.&lt;br /&gt;&lt;br /&gt;Above, we created a web page with a JavaScript function that we've not implemented, until now: the sendMessage() event is fired off by the browser whenever the "send" button is pressed. As you might guess, this is going to call Chat.addMessage():&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;function sendMessage()&lt;br /&gt;{&lt;br /&gt;var text = DWRUtil.getValue("text");&lt;br /&gt;DWRUtil.setValue("text", "");&lt;br /&gt;Chat.addMessage(gotMessages, text);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The first line gets the value from the input field. DWRUtil.getValue() works with most HTML elements, so long as they have an id attribute (in this case, the input element has an id="text").&lt;br /&gt;&lt;br /&gt;Next, we use the setValue() method to blank out the input element; again, the setValue() is very smart at working out what to do with your data and how it should update your web page with the new data.&lt;br /&gt;&lt;br /&gt;Then we call Chat.addMessage() and ask DWR to return the list of messages typed by other web users to the gotMessages() function. It looks like this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;function gotMessages(messages)&lt;br /&gt;{&lt;br /&gt;var chatlog = "";&lt;br /&gt;for (var data in messages)&lt;br /&gt;{&lt;br /&gt;chatlog = " &lt;div&gt;" + messages[data].text +&lt;br /&gt;"&lt;/div&gt;" + chatlog;&lt;br /&gt;}&lt;br /&gt;DWRUtil.setValue("chatlog", chatlog);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This is where DWR excels. The Java method Chat.addMessage() returned a List of Message objects. DWR has automatically converted this into an array of JavaScript objects. All we need to do in gotMessages() is to iterate over the messages array, getting the text member from each object in the array, and build some HTML from it. Finally, we push the string we have created into the div using the ever-versatile setValue() method.&lt;br /&gt;&lt;br /&gt;And that's it! We have a basic multi-user, web-based chat system in about 100 lines of code, for both the client and server code.&lt;br /&gt;&lt;br /&gt;There are a number of things missing for this to be useful: a polling method that uses setTimeout() to call Chat.getMessages() would keep things flowing a bit more. The downloaded code contains an extra six lines of JavaScript to make this happen. We could also add code to only alter the display if new messages have arrived; this would make for a flicker-free display. Finally, having a back-off mechanism where the browsers poll the server less often if nothing much is happening would be a good idea to prevent swamping the server.&lt;br /&gt;&lt;br /&gt;You can see the final version here. It adds the features listed above, plus highlighting of new messages--all of which takes an extra 50 or so lines of JavaScript.&lt;br /&gt;&lt;br /&gt;It is also worth checking out http://localhost:8080/[YOUR-WEB-APP]/dwr, which is a test debug page that automatically shows you the classes you have remoted, and allows you to test their functionality.&lt;br /&gt;&lt;br /&gt;Conclusion&lt;br /&gt;Using DWR can make creating cross-browser AJAX websites very easy, and introduces a very neat way to interact between JavaScript in the web browser and Java on the server. It is simple to get started with and integrates well with your current website&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-3431221007850998784?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/3431221007850998784/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=3431221007850998784' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3431221007850998784'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3431221007850998784'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/02/developing-ajax-applications.html' title='Developing AJAX Applications'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4752443593401370011.post-3802974942339698249</id><published>2008-02-27T03:55:00.000-05:00</published><updated>2008-02-27T03:56:56.854-05:00</updated><title type='text'>Coding an XML Configuration File</title><content type='html'>This is a problem that we see a lot in .NET as well as programming in general these days. There are a lot of good ideas built into .NET and more ideas that are just carried forward for compatibility's sake. In particular, there are a lot of methods to choose from if you need to save a little configuration data for your program. &lt;br /&gt;&lt;br /&gt;This article will describe the various ways that this can be done, but we'll finish up with a very simple example - complete with the downloadable source - showing what I think is the easiest way to save a few data items between program executions: native XML. &lt;br /&gt;&lt;br /&gt;From a historical perspective, configuration information used to be saved in simple text files. You may still see a file named "settings.txt" or "config.txt" even today. In their latest book (Visual Basic 2005 for Programmers, 2nd Edition, Paul J. Deitel, Harvey M. Deitel, ISBN: 0-13-225140-X), the Deitel Developer Series has a major section showing how to create and read what is actually a "comma separated value" (CSV) file - an idea that is decades old. (Their goal is to demonstrate stream oriented sequential file processing, but the end result is the same.) &lt;br /&gt;&lt;br /&gt;The next step up the ladder was to require some structure for configuration files. The best example is proably the .INI files. Here's what a typical .INI file looks like (from Wikipedia): &lt;br /&gt;&lt;br /&gt;[section1]&lt;br /&gt;&lt;br /&gt;; some comment on section1&lt;br /&gt;var1 = foo&lt;br /&gt;var2 = doodle&lt;br /&gt;&lt;br /&gt;[section2]&lt;br /&gt;&lt;br /&gt;; another comment&lt;br /&gt;var1 = baz&lt;br /&gt;var2 = shoodle &lt;br /&gt;&lt;br /&gt;These types of files were very typical when Windows 3.1 was the hot OS, even though Windows itself used config.sys and autoexec.bat for most startup configuration. &lt;br /&gt;&lt;br /&gt;Then the thinking shifted to another idea: Put all your eggs in one basket and then watch that basket !! The "basket" is the Windows registry and it's still used for most of the Windows OS information. The next version of Windows, Vista, will continue to use the registry in just about the same way. In the era of Windows 2000 and Windows NT, creating lots of little .INI files was discouraged and programmers were encouraged to put their own program configuration information in the registry too, but we have discovered now that stuffing everything into one basket has it's own set of problems. So while COM, the technology used in VB 6, required that DLL's be "registered" .NET does not. VB.NET does provide excellent support for saving configuration information in the registry using the My.Computer.Registry object that is new in Framework 2.0 if that's the way you want to go. &lt;br /&gt;&lt;br /&gt;The idea of using individual configuration files - information that is only used by your program in a few small files in the program folder - gets a lot more respect these days, thanks in no small measure to .NET. After all, Visual Studio will create a couple of dozen different files for even the simplest Windows application filled with exactly this kind of information. &lt;br /&gt;&lt;br /&gt;But there are still more options to be considered. &lt;br /&gt;&lt;br /&gt;The new buzzword for writing a file these days is "persist" -- as in "Persisting an Object" or "Persist an ADO.NET DataSet" (titles taken directly from Microsoft's web site). I used to call it, "saving an object" or "writing a dataset" but I guess I'll have to catch up with the times and start saying "persist" now. The idea is that some result of the program lasts after the program stops running and is restored when the program starts up again. The dictionary definition of "persist" is "to exist in spite of adversity." Being removed from computer memory is an example of adversity, I suppose. &lt;br /&gt;&lt;br /&gt;You can persist information in several formats, however. We started the article by considering CSV and INI files, but there are more formats available now. VB.NET has excellent objects that help you serialize data to binary files, SOAP files, or XML files. Serialization is just the process of converting an object into a linear sequence of bytes. You can read more about serialization in lesson 3 from an About Visual Basic email tutorial. Microsoft's own Visual Studio will save configuration data in binary, XML, and proprietary formats. You can find examples in Microsoft's MSDN web site about how to persist data in all of these formats.&lt;br /&gt;&lt;br /&gt;The code . . .&lt;br /&gt;In my opinion, however, if you want your program to be as easy to understand as possible, and you want the data itself to be easy-to-read text too, then creating a configuration file using XML methods is probably the way to go. Most modern programming technologies now completely support XML and you can open an XML file in either Notepad or most browsers to see what's in it. Writing the file directly with XML methods in VB.NET makes what is happening as clear as possible in the program code. The alternative of "serializing" to an XML file does a lot of the work for you but also makes the creation of the XML a "black box". The example you will see here puts it all out there in the open. &lt;br /&gt;&lt;br /&gt;As an example of an alternative, here's a program designed to be used as a desktop utility for simple calculations of stock market prices and amounts. &lt;br /&gt;&lt;br /&gt;The starting values are set using an XML configuration file. The starting values that will be used the next time the program is loaded can be set using an update routine that overwrites the XML file with new values. The illustration below shows the XML file displayed in IE. (IE is one of the best XML utilities!) The first task for the program is to write the XML file. The code that writes the XML file is shown below. &lt;br /&gt;&lt;br /&gt;  Dim Doc As New XmlDocument&lt;br /&gt;  'Create a 'vanilla' XML Declaration (processing instruction)&lt;br /&gt;  Dim myXmlDeclaration As XmlDeclaration&lt;br /&gt;  myXmlDeclaration = _&lt;br /&gt;    Doc.CreateXmlDeclaration("1.0", "UTF-8", "yes")&lt;br /&gt;  Doc.AppendChild(myXmlDeclaration)&lt;br /&gt;  '       &lt;-Root Created&lt;br /&gt;  Dim Root As XmlElement&lt;br /&gt;  Root = Doc.CreateElement("StockCalcDefaults")&lt;br /&gt;  'Create a company name child node&lt;br /&gt;  Dim Child As XmlElement&lt;br /&gt;  Child = Doc.CreateElement("companyName")&lt;br /&gt;  Child.InnerText = companyName.Text&lt;br /&gt;  Root.AppendChild(Child)&lt;br /&gt;  'Create a Buy Price child node&lt;br /&gt;  Child = Doc.CreateElement("buyPrice")&lt;br /&gt;  Child.InnerText = _&lt;br /&gt;    CStr(Decimal.Round(buyPrice.Value, 2))&lt;br /&gt;  Root.AppendChild(Child)&lt;br /&gt;  'Create a Sell Price child node&lt;br /&gt;  Child = Doc.CreateElement("sellPrice")&lt;br /&gt;  Child.InnerText = _&lt;br /&gt;    CStr(Decimal.Round(sellPrice.Value, 2))&lt;br /&gt;  Root.AppendChild(Child)&lt;br /&gt;  'Create a Number of Shares child node&lt;br /&gt;  Child = Doc.CreateElement("numShares")&lt;br /&gt;  Child.InnerText = CStr(numShares.Value)&lt;br /&gt;  Root.AppendChild(Child)&lt;br /&gt;  'Add an attribute to the child node&lt;br /&gt;  Dim Attr As XmlAttribute&lt;br /&gt;  Attr = Doc.CreateAttribute("incByThousand")&lt;br /&gt;  Attr.Value = CStr(incByThousand.Checked)&lt;br /&gt;  Child.Attributes.Append(Attr)&lt;br /&gt;  'Create a Profit Amount child node&lt;br /&gt;  Child = Doc.CreateElement("profitAmount")&lt;br /&gt;  Child.InnerText = _&lt;br /&gt;    CStr(Decimal.Round(profitAmount.Value, 2))&lt;br /&gt;  Root.AppendChild(Child)&lt;br /&gt;  '       &lt;-Root Added to Doc&lt;br /&gt;  Doc.AppendChild(Root)&lt;br /&gt;  'Write XML to a file&lt;br /&gt;  Dim Output As New XmlTextWriter( _&lt;br /&gt;    "StockDefaults.xml", _&lt;br /&gt;    System.Text.Encoding.UTF8)&lt;br /&gt;  '       &lt;-Document Written&lt;br /&gt;  Doc.WriteTo(Output)&lt;br /&gt;  Output.Close() &lt;br /&gt;&lt;br /&gt;How the code works&lt;br /&gt;There are a lot of lines of code here, but they fit into some neat categories that will help you understand what they do. &lt;br /&gt;&lt;br /&gt;When programming XML, you have to learn to "think" XML first. The most fundamental organization of XML is a hierarchy. So, rather than writing the XML line-by-line as you might expect in a sequential file, the most direct way to write an XML file is to create it node-by-node and then write it. There are other techniques and you might want to experiment. You might find one that fits your way of thinking about it better. &lt;br /&gt;&lt;br /&gt;In this program, the first statements create the XML declaration. This identifies the file as an XML file and is strictly required. Then a root node is created and populated with all of the content: child nodes and any XML attributes. &lt;br /&gt;&lt;br /&gt;(This program includes just one XML attribute, incByThousand, to the numShares element.) Finally the root node is appended to the XML document and the whole thing is written to a file. No path information is provided so this file is written to the same folder that the executable is in. I used the same names for the XML elements and attributes as I used for VB program variables just to make things easier to code. This isn't required. &lt;br /&gt;In this program, reading the XML document back again requires you to change your thinking back to a sequential mode. Although Microsoft's System.Xml namespace gives you the tools to zero in on exactly what you need, in this case it's easiest to simply read through the XML in sequence and assign the data back into variables. I do this in the Load event for the form. A Do While loop moves through the XML document from front to back and a Select Case block simply extracts the values that the program needs. &lt;br /&gt;&lt;br /&gt;One interesting sidenote that contributes to confusion is that the Value property of an XML node can be used some of the time and some of the time it can't. The Tool-Tip unhelpfully tells us that Value "Gets the text value of the current node." &lt;br /&gt;&lt;br /&gt;Not exactly right. &lt;br /&gt;&lt;br /&gt;For example, this statement compiles, but creates an exception when the program runs: &lt;br /&gt;&lt;br /&gt;Child.Value = companyName.Text &lt;br /&gt;&lt;br /&gt;This statement works fine when the node type is an attribute but always assigns a null reference when the node type is an element. &lt;br /&gt;&lt;br /&gt;varName = Input.Value &lt;br /&gt;&lt;br /&gt;This MSDN page tells you when it works and when it doesn't. Although their documentation could be a lot more clear about why things work this way, you can't really blame Microsoft for the problem. The cause is the very exact way that XML works. For example, a node in XML might look like this: &lt;br /&gt;&lt;br /&gt;&lt;node&gt;FirstData&lt;emptysubnode/&gt;SecondData&lt;/node&gt; &lt;br /&gt;&lt;br /&gt;What's the "value" of the element node? Is it "FirstData"? Or "FirstDataSecondData"? Microsoft's very complete System.Xml namespace has methods to deal with every possibility, but some of them don't make sense until you have more experience with XML.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4752443593401370011-3802974942339698249?l=crackcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crackcode.blogspot.com/feeds/3802974942339698249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4752443593401370011&amp;postID=3802974942339698249' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3802974942339698249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4752443593401370011/posts/default/3802974942339698249'/><link rel='alternate' type='text/html' href='http://crackcode.blogspot.com/2008/02/coding-xml-configuration-file.html' title='Coding an XML Configuration File'/><author><name>SaMhAcKeR</name><uri>http://www.blogger.com/profile/13708883781541208252</uri><email>samwasim2002@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05993052443758465963'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>