Skip to main content

Posts

Showing posts from 2013

Grunt - A command line JavaScript task runner.

Grunt is a JavaScript task runner that will help you to mini-fy the various JS files. It will make your work really less while performing repetitive tasks like minification, compilation, unit testing, linting, etc with just few lines of code you need to write in command prompt. Grunt is a task-based command line build tool for JavaScript projects. If you have a Javascript and html based project that used MVVM model and you have millions of lines of code to minimize then grunt is the key for you. Some of the p lugins Grunt can enjoy. Some of the big IT companies that uses grunt.. and Below is the starter guide provided by grunt official website to keep you jump started. have fun in grunting.  Getting started: Grunt and Grunt plugins are installed and managed via  npm , the  Node.js  package manager. Grunt 0.4.x requires Node.js version  >= 0.8.0 . Installing the CLI In order to get started, you'll want to in...

Tips to increase your Transact-SQL efficiency Part 2

First Part :  http://www.developerscloud.org/2013/09/tips-to-increase-your-transact-sql.html 11. Use 'BETWEEN' operator instead of >= and <= operators to select data in range. 12. Wisely use the EXISTS, IN clauses in sub query select statement. - IN has the slowest performance as data is filtered between the range. - IN is efficient when most of the filter criteria is in the sub-query. - EXISTS is efficient when most of the filter criteria is in the main query. 13. Avoid 'NOT IN' in select clause. Because when we use “NOT IN” in SQL queries, the query optimizer uses 'Nested table scan' technique  to perform the activity 14. Use Stored Procedure, functions(UDF) and views instead of heavy-duty queries. - The application must first convert the binary value into a character string (which doubles its size, thus increasing network traffic and taking more time) before it can be sent to the server. And when the  server receives the charac...

Tips to increase your Transact-SQL efficiency Part 1.

Given below are little known tips that you can use to ensure your Transact-SQL queries are performing in the  most efficient manner possible. 1. Avoid '*' in select query.      Restrict the queries result set by returning only the particular columns from the table and not all the  table's columns. The sql query becomes faster if you use the actual column names in SELECT  statement instead of than '*'. 2. Avoid COUNT(*) in select statement to check the existence of records in table.       Instead use IF EXISTS() to check records. - Write the query as: IF EXISTS (SELECT * FROM table_name WHERE column_name = ‘xxx’) - Instead of : SELECT COUNT(*) FROM table_name WHERE column_name = ‘xxx’ 3. Use alternate of SELECT COUNT(*).      Use an alternative way instead of the SELECT COUNT(*) statement to count the number     of records in  table.         - SELECT CO...

Importing the Excel into the Database (SQL).

We can import the excel into the Database by using the following query. Suppose we have a table named as Address_Temp and it has three column. 1. Name 2. State 3. Zip Here we need to update the zip code with the new value and to update that zip code we need to check the excel. So we can use that excel in our sql server by importing it using the following command. Its very easy query but make sure that it won't work in following two scenarios. 1. The file need to be in local machine. 2. The file should not be password protected. Declare @ ZipTemp NVarchar ( 255 ) set @ ZipTemp = ( SELECT * FROM OPENROWSET ( 'Microsoft.Jet.OLEDB.4.0' , 'Excel 8.0;Database=C:\Addresses.xls;IMEX=1' , 'SELECT top 1 ZIP FROM [Sheet1$] where ZIP = "328301"' ))

Simple Pyramid in Csharp .Net

    *   ***  ***** ******* Updated  As you can see below the code for simple pyramid has two for loop nested in each other. So for each row it enter, it increment the counter and draw the star against forming a pyramid like figure. You can use  different special counter, play with the loop and enjoy the coding. Simple Pyramid in Csharp    class Program     {          static void Main( string [] args)         {             int row, col = 0, n = 5;                                 for (row = 0; row <= n; row++)             {           ...

Rise, Fall and Struggle of Microsoft .Net [Article]

Some years ago there was a guy named Vinod Khosla from IIT- Delhi and Stanford. This awesome guy co-founded Sun Microsystem. Sun Microsystem as we all know is fully undertaken by Oracle. But Sun Microsystem came up with a fantastic language called Java. This language was becoming too famous and popular since its birth and by 90's its JAVA, JAVA and only JAVA everywhere. Microsoft who was struggling with the PC market at that time want's to capture the opportunity and Microsoft was building everything like the OS  and Office and Java was taking the credit of so called windows application so then MICROSOFT plans to launch its own language. Yes, so think back a decade or so ago. As you may recall, .Net was supposed to be much more than just the next version of Windows DNA or COM+ or COM. It was supposed to destroy Java, extend the Windows platform, and secure the Microsoft monopoly for another decade or two. But then what happened after the DOT COM BUBBLE. Rise Like m...

Send a Fax in windows using faxcomexlib and TAPI in VB code .Net

An application that provides sending fax from faxmodem, connected to the computer, will be explained in the following post.  We can use Telephony Application Programming Interface (TAPI) and the Fax Service Extended Component Object Model (COM) API to send fax. The fax service is a Telephony Application Programming Interface (TAPI)-compliant system service that allows users on a network to send and receive faxes from their desktop applications. The service is available on computers that are running Windows 2000 and later. The fax service provides the following features: Transmitting faxes Receiving faxes Flexible routing of inbound faxes Outbound routing Outgoing fax priorities Archiving sent and received faxes Server and device configuration management Client use of server devices for sending and receiving faxes Event logging Activity logging Delivery receipts Security permissions The following Microsoft Visual Basic code example sends a fax. Note that...

What is OOP ? Basic Concepts.

What is OOP? Object oriented programming is a type of programming paradigm based around programming classes and instances of classes called objects. These can be objects that appear on the screen (e.g., pictures, textboxes, etc.) or are part of the programming (e.g. actors, connections, particles, etc.) What is an Object? An object is merely a collection of related information and functionality. An object can be something that has a corresponding real-world manifestation (such as an employee object), something that has some virtual meaning (such as a window on the screen), or just some convenient abstraction within a program (a list of work to be done, for example). An object is composed of the data that describes the object and the operations that can be performed on the object. Information stored in an employee object, for example, might be various identification information (name, address), work information (job title, salary), and so on. The operations performed might include...

Three Tier Architecture : A simple Example/Illustration

Three Tier Architecture: Very Easy to understand, the three tier are: 1. Presentation layer 2. Business Layer 3. Database Layer Simple Example: Lets take example of a Songs and Artist. 1. DataAccess Layer Below is a class of Data Access Layer, that has some dummy/fudge data, we only write DataBase calling method in DataAccessLayer. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DataBaseLayer {     public class DataAccessLayer     {         string [] ArtistName = { "Akon" , "Shakira" , "Michael_Jackson" };         string [] Shakira = { "Waka Waka" , "Addicted to you" , "Beautiful Liar" };         string [] Akon = { "Chammak Challo" , "Lonely" , "Dont Matter" };         string [] Michael_Jackson = { "Beat It" , "Danger...

CREATE and ALTER Statement

Create Statement The CREATE statement is used to create a new table with no record. Let's create the table office . The records in the office table will contain a technical id, the name of the office, a description, the number of available places, the availability and the date for the next office security control: Query : CREATE TABLE office ( id_office INTEGER PRIMARY KEY NOT NULL , name VARCHAR ( 20 ) NOT NULL , description VARCHAR ( 255 ) , place_number INTEGER NOT NULL , available SMALLINT NOT NULL DEFAULT 1 , next_inspection DATE NOT NULL ) ; The table after the statement : office id_office INTEGER name VARCHAR(20) description VARCHAR(255) place_number INTEGER available SMALLINT next_inspection DATE  ALTER statement  The ALTER statement is used to modify a table. It can be used on a table with records in it.

Using Parameterized Queries to avoid SQL Injection In C# .Net

An SQL injection attack consists of insertion or "injection" of an SQL query via the input data from the client to the application. Attackers potentially use SQL Injection to: -Logging into your applicatiob by Bypassing the authentication. -Gaining access to your sensitive information in the database. -Tampering or destroying data. There are two complementary and successful methods of mitigating SQL Injection attacks: -Parameterized queries using bound, typed parameters. -Careful use of parameterized stored procedures. So one common use of such queries is explained in the below example written in Dot Net, which uses Parameterized queries for the variables declared with initial @. And also you can avoid the error caused by Apostophe (') in the variable if you are updating a table. Like if you have a variable like O'Connor then you app will throw an error, which can be avoided by the use of Parameterized query. It is one of the best way to avoid h...

Creating a HTML tag in C# Code (TEXT AREA) Asp.Net and display it in HTML Page

Follow @harshit_parshii HtmlTextWriter:-  The HtmlTextWriter class is used to render HTML 4.0 to desktop browsers. The HtmlTextWriter is also the base class for all markup writers in theSystem.Web.UI namespace. It Writes markup characters and text to an ASP.NET server control output stream. This class provides formatting capabilities that ASP.NET server controls use when rendering markup to clients. It allows you to generate a list of HTML elements, such as <div> elements. You could use StringBuilder to create the HTML, but HtmlTextWriter is sometimes better—fewer errors are likely. Below is sample code: protected void Page_Load(object sender, EventArgs e) {     TextBox txtBox = new TextBox();     // Initialize StringWriter instance.     StringWriter stringWriter = new StringWriter();     // Put HtmlTextWriter in using block because it needs to call Dispose.     using(HtmlTextWriter writer ...

Taking Backup of database in one server and restoring in other via sql commands

Database YourDB has full backup YourBaackUpFile.bak. It can be restored using following two steps. Step 1:  Retrive the Logical file name of the database from backup. RESTORE  FILELISTONLY  FROM DISK =  'D:BackUpYourBaackUpFile.bak' GO Step 2:  Use the values in the LogicalName Column in following Step. Step 2.1: ----Checking if the drive exist(for ldf n mdf files) in this particular server EXEC master.dbo.xp_fileexist 'YourLDFLogicalName'  EXEC master.dbo.xp_fileexist ' YourMDFLogicalName It will give 3 columns, for file, directory and root directory. Check if it exist or not for both LDF and MDF files. Step 2.2 ---If not then change the file path using these lines --For data file SELECT TOP 1 ms . physical_name FROM master . sys . master_files ms WHERE ms . file_id = 2 ORDER BY ms . database_id DESC --For log file SELECT TOP 1 ms . physical_name FROM master . sys . master_files ms WHERE m...

SQL Joins

Follow @harshit_parshii SQL JOIN The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables. Tables in a database are often related to each other with keys. A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table FULL OUTER JOIN A JOIN is made matching a column on a table to a column on the other table. After a FULL OUTER JOIN, for a given value (red), for a given row with this value on one table ([ red | 9999 ]), one row is created for each row that matches on the other table ([ red | OOOOOO ] and [ red | LLLLLL ]). If a value exists in only one table, then a row is created and is completed with NULL columns. FROM table_1 FULL OUTER JOIN table_2 ON table_1...