CopyRight

If you feel that any content has violated the copy-Right law please be free to mail me.
I will take suitable action.
Thanks

Monday, 15 August 2016

JavaScript Design Patterns

Function Argument Patterns
function myfunc(a,b,c) {
  return a+b+c;
}
  • Like all variables in JavaScript arguments are untyped
  • Unspecified arguments become undefined.
    • console.log(myfunc(1,2,3));
    • console.log(myfunc(1,2,3,4));
    • console.log(myfunc(1,2));



Thursday, 6 November 2014

Codechef , Topcoder - Never Miss a contest

 Codechef , Topcoder - Never Miss a contest 


Ever felt you have a bad memory and tend to forget things way to Fast. Specially if you are a geek and you have lots of stuff to do, you tend to miss out on coding contest on various online sites and that affects your ranking.

Here is simple yet very effective way to get yourself reminders , be it seconds before the contest start or weeks.

So the steps are as follows.

Step 1:
Add the calenders of various online judges.


HackerRank : Hackerrank
Top Coder : Topcoder
CodeForces : CodeForces
Code Chef : Codechef


Step 2:In the calendar list on the left, click the down-arrow button next to the appropriate calendar [in other calender ], then select Edit notifications.





Step 3:
In the Event Notifications section, select Add a Notification method. Then from the drop-down menu and enter the corresponding reminder time (between five minutes and four weeks).

You can select SMS, Pop up or Email. I generally prefer Sms.

If you'd like to add additional default reminders, simply click Add a Notification.



Step 4:Save

Wednesday, 13 August 2014

Privacy Policy for windows 8.1 Roux Artists App

Date of last revision: August 14, 2014
 Roux Artists application is just an app that gives you latest updates about Roux Academy 2012 Art confernce. This app uses the  Roux Academy page details. You can manually check out this page here . Further the content of this page posted by group of peoples and I (Hitesh Dua) am not part of this group. 

I Hitesh Duad do not take any responsibility of any kind of miss use, loss of any data or any kind of financial loss by iusing this app. The content of this is soley the right of Roux Academy.
Further this is important to notice this app only uses Rouz Acdemy page for any details. Download and use this app on your own risk.
I (Hitesh Dua) have full right to change these Privacy policy.
By downloading this app you are accepting above Privacy Policy.

Friday, 13 June 2014

.NET Connectivity to SQL server using C sharp

Using an IP Address to Connect to SQL Server
Problem
You want to connect to a SQL Server using its IP address instead of its server name.
Solution
Use the Network Address and Network Library attributes of the connection string.
ConnectSqlServerIpAddressForm.cs
// Namespaces, variables, and constants
using System;
using System.Data.SqlClient;

//  . . .

private void connectButton_Click(object sender, System.EventArgs e)
{
    String connString =
        "Network Library=dbmssocn;Network Address=127.0.0.1
;" +
        "Integrated security=SSPI;Initial Catalog=Northwind";
   
    SqlConnection conn = new SqlConnection(connString);
    conn.Open( );


File: ConnectionPoolingOptionsForm.cs
// Namespaces, variables, and constants
using System;
using System.Configuration;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

private SqlConnection conn;

//  . . .

private void ConnectionPoolingOptionsForm_Load(object sender,
    System.EventArgs e)
{   
    conn = new SqlConnection( );
    conn.StateChange += new StateChangeEventHandler(conn_StateChange);

    connectionStringTextBox.Text =
        ConfigurationSettings.AppSettings["Sql_ConnectString"];
    connectTimeoutTextBox.Text = "15";
    connectLifetimeTextBox.Text = "0";
    minPoolSizeTextBox.Text = "0";
    maxPoolSizeTextBox.Text = "100";
    poolCheckBox.Checked = true;

    UpdateConnectionString( );
}

private void UpdateConnectionString( )
{
    connectionStringTextBox.Text =
        ConfigurationSettings.AppSettings["Sql_ConnectString"] +
        "Connection Timeout = " + connectTimeoutTextBox.Text + ";" +
        "Connection Lifetime = " + connectLifetimeTextBox.Text + ";" +
        "Min Pool Size = " + minPoolSizeTextBox.Text + ";" +
        "Max Pool Size = " + maxPoolSizeTextBox.Text + ";" +
        "Pooling = " + poolCheckBox.Checked.ToString( );
}

private void openButton_Click(object sender, System.EventArgs e)
{
    try
    {
        conn.ConnectionString = connectionStringTextBox.Text;
        conn.Open( );
    }
    catch(SqlException ex)
    {
        MessageBox.Show("ERROR: " + ex.ToString( ), "Open Connection",
            MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    catch(InvalidOperationException ex)
    {
        MessageBox.Show("ERROR: " + ex.ToString( ), "Open Connection",
            MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

private void closeButton_Click(object sender, System.EventArgs e)
{
    conn.Close( );
}

private void conn_StateChange(object sender, StateChangeEventArgs e)
{
    connectionStateTextBox.Text =
        "Connection.StateChange event occurred" +
        Environment.NewLine +
        "OriginalState = " + e.OriginalState.ToString( ) +
        Environment.NewLine +
        "CurrentState = " + e.CurrentState.ToString( );

}

.NET Connectivity to Access Database using C sharp

Problem
You want to connect to a Microsoft Access database that has a database password.
Solution
Use the Jet OLEDB:Database Password attribute in the connection string to specify the password.

File: AccessPasswordForm.cs
// Namespaces, variables, and constants
using System;
using System.Configuration;
using System.Text;
using System.Data;
using System.Data.OleDb;

//  . . .

private void connectButton_Click(object sender, System.EventArgs e)
{
    StringBuilder result = new StringBuilder( );

    // Build the connections string incorporating the password.
    String connectionString =
        ConfigurationSettings.AppSettings["MsAccess_Secure_ConnectString"]+
        "Jet OLEDB:Database Password=" + passwordTextBox.Text + ";";

    result.Append("ConnectionString: " + Environment.NewLine +
        connectionString + Environment.NewLine + Environment.NewLine);

    OleDbConnection conn = new OleDbConnection(connectionString);
    try
    {
        conn.Open( );

}

.NET Connectivity to Excel Workbook using C sharp

Connecting to a Microsoft Excel Workbook
Problem
You want to access data stored in a Microsoft Excel workbook.
Solution
Use the OLE DB Jet provider to create, access, and modify data stored in an Excel workbook.
1)Create workbook and sheet
using System;
using System.Configuration;
using System.Data;

private OleDbDataAdapter da;
private DataTable dt;

//  . . .

private void ExcelForm_Load(object sender, System.EventArgs e)
{
    // Create the DataAdapter da
    da = new OleDbDataAdapter("SELECT * FROM [Sheet1$]",
        ConfigurationSettings.AppSettings["Excel_0115_ConnectString"]);

    // Create the insert command.
    String insertSql = "INSERT INTO [Sheet1$] " +
        "(CategoryID, CategoryName, Description) " +
        "VALUES (?, ?, ?)";
    da.InsertCommand =
        new OleDbCommand(insertSql, da.SelectCommand.Connection);
    da.InsertCommand.Parameters.Add("@CategoryID", OleDbType.Integer, 0,
        "CategoryID");
    da.InsertCommand.Parameters.Add("@CategoryName", OleDbType.Char, 15,
        "CategoryName");
    da.InsertCommand.Parameters.Add("@Description", OleDbType.VarChar, 100,
        "Description");

    // Create the update command.
    String updateSql = "UPDATE [Sheet1$] " +
        "SET CategoryName=?, Description=? " +
        "WHERE CategoryID=?";
    da.UpdateCommand =
        new OleDbCommand(updateSql, da.SelectCommand.Connection);
    da.UpdateCommand.Parameters.Add("@CategoryName", OleDbType.Char, 15,
        "CategoryName");
    da.UpdateCommand.Parameters.Add("@Description", OleDbType.VarChar, 100,
        "Description");
    da.UpdateCommand.Parameters.Add("@CategoryID", OleDbType.Integer, 0,
        "CategoryID");

    // Fill the table from the Excel spreadsheet.
    dt = new DataTable( );
    da.Fill(dt);
    // Define the primary key.
    dt.PrimaryKey = new DataColumn[] {dt.Columns[0]};

    // Records can only be inserted using this technique.
    dt.DefaultView.AllowDelete = false;
    dt.DefaultView.AllowEdit = true;
    dt.DefaultView.AllowNew = true;
    // Bind the default view of the table to the grid.
    dataGrid.DataSource = dt.DefaultView;
}
private void updateButton_Click(object sender, System.EventArgs e)
{
    da.Update(dt);

}

Monday, 12 May 2014

Introduction to Matlab

Introduction to Matlab

THEORY:

MATLAB® is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include
·         Math and computation
·         Algorithm development
·         Data acquisition
·         Modeling, simulation, and prototyping
·         Data analysis, exploration, and visualization
·         Scientific and engineering graphics
·         Application development, including graphical user interface building
MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar non interactive language such as C or Fortran.
The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software for matrix computation.

FUNCTIONS USED IN MATLAB:
1)    Logarithm:

Syntax:   Y = log(X)

Description:
The log function operates element-wise on arrays. Its domain includes complex and negative numbers, which may lead to unexpected results if used unintentionally.
Y = log(X) returns the natural logarithm of the elements of X. For complex or negative, where, the complex logarithm is returned. log(z) = log(abs(z)) + i*atan2(y,x).

Example: (log(-1))
ans =

    3.1416

2)    Plot:
Syntax:   plot(Y)
               plot(X1,Y1,...)

Description:
plot(Y) plots the columns of Y versus their index if Y is a real number. If Y is complex, plot(Y) is equivalent to plot(real(Y),imag(Y)). In all other uses of plot, the imaginary component is ignored.
plot(X1,Y1,...) plots all lines defined by Xn versus Yn pairs. If only Xn or Yn is a matrix, the vector is plotted versus the rows or columns of the matrix, depending on whether the vector's row or column dimension matches the matrix.

Example:     x = -pi:pi/10:pi;
                    y = tan(sin(x)) - sin(tan(x));
                    plot(x,y)

3)    Exponential:

Syntax:      Y = exp(X)

Description:
The exp function is an elementary function that operates element-wise on arrays. Its domain includes complex numbers.
Y = exp(X) returns the exponential for each element of X. For complex , it returns the complex exponential .

Example: y = exp(2)
y =

    7.3891

4)    Grid:

Syntax:     grid on
     grid off
     grid minor

            Description:    
The grid function turns the current axes' grid lines on and off.
grid on adds major grid lines to the current axes.
grid off removes major and minor grid lines from the current axes.
grid toggles the major grid visibility state.

Example:
x=-pi:0.01:pi;
            plot(x,sin(x)),grid on
           
5)    Stem:

Syntax:    stem(Y)
    stem(X,Y)

           
Description:
A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. A circle (the default) or other marker whose y-position represents the data value terminates each stem.
stem(Y) plots the data sequence Y as stems that extend from equally spaced and automatically generated values along the x-axis. When Y is a matrix, stem plots all elements in a row against the same x value.
stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the same size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows.

            Example:
            x=45;
h=stem(x,sin(x))
h =

  152.0028

6)    Xlabel, Ylabel & Title

Syntax:     xlabel('string'), ylabel('string'), title('string')


Description:
Each axes graphics object can have one label for the x-, y-, and z-axis. The label appears beneath its respective axis in a two-dimensional plot and to the side or beneath the axis in a three-dimensional plot.
xlabel('string'), ylabel('string') labels the x-axis, y-axis of the current axes.Each axes graphics object can have one title. The title is located at the top and in the center of the axes.
title('string') outputs the string at the top and in the center of the current axes.

Example:    x = [1,2,3];
       y=sin(x);
       z=stem(y);
       xlabel('x')
       ylabel('y')
       title('Stem Plot')

7)    Maximum:

Syntax:      C = max(A)
      C = max(A,B)

Description:
C = max(A) returns the largest elements along different dimensions of an array.
If A is a vector, max(A) returns the largest element in A.
If A is a matrix, max(A) treats the columns of A as vectors, returning a row vector containing the maximum element from each column.
If A is a multidimensional array, max(A) treats the values along the first non-singleton dimension as vectors, returning the maximum value of each vector.
C = max(A,B) returns an array the same size as A and B with the largest elements taken from A or B.

Example:
x = [1,2,3;4,5,6;7,8,9];
 max(x)
ans =

     7     8     9

8)    Minimum:

Syntax:    C = min(A)
    C = min(A,B)

Description:

C = min(A) returns the smallest elements along different dimensions of an array.
If A is a vector, min(A) returns the smallest element in A.
If A is a matrix, min(A) treats the columns of A as vectors, returning a row vector containing the minimum element from each column.
If A is a multidimensional array, min operates along the first nonsingleton dimension.
C = min(A,B) returns an array the same size as A and B with the smallest elements taken from A or B.

Example:
x = [1,2,3;4,5,6;7,8,9];
min(x)
ans =

     1     2     3

9)    Modulus:

Syntax:   M = mod(X,Y)

Description:
M = mod(X,Y) if Y ~= 0, returns X - n.*Y where n = floor(X./Y) . If Y is not an integer and the quotient X./Y is within roundoff error of an integer, then n is that integer. By convention, mod(X,0) is X. The inputs X and Y must be real arrays of the same size, or real scalars.

Example:
mod(13,5)
ans =

     3

10) Transfer Function:

Syntax:    sys = tf(num,den)
    sys = tf(num,den,Ts)
    sys = tf(M)
                sys = tf(num,den,ltisys)

Description:
tf is used to create real- or complex-valued transfer function models (TF objects) or to convert state-space or zero-pole-gain models to transfer function form.

Example:   h=tf([1,0],[1 2 10])

      Transfer function:
                s
        --------------
      s^2 + 2 s + 10

11) Absolute

Syntax:     Y = abs(X)

Description:
abs(X) returns an array Y such that each element of Y is the absolute value of the corresponding element of X.
If X is complex, abs(X) returns the complex modulus (magnitude), which is the same as sqrt(real(X).^2 + imag(X).^2).

Example:    abs(-5)
       ans =

                        5

12) Matrix addition

Syntax:    A+B

Description:
MATLAB has two different types of arithmetic operations. Matrix arithmetic operations are defined by the rules of linear algebra. Array arithmetic operations are carried out element by element, and can be used with multidimensional arrays. The period character (.) distinguishes the array operations from the matrix operations. However, since the matrix and array operations are the same for addition and subtraction, the character pairs .+ and .- are not used.
+ Addition or unary plus. A+B adds A and B. A and B must have the same size, unless one is a scalar. A scalar can be added to a matrix of any size.

Example:
a=[1,2,3;4,5,6];
b=[4,5,6;1,2,3];
a+b
ans =

     5     7     9
     5     7     9

13) Matrix Subtraction

Syntax:   A-B

Description:
MATLAB has two different types of arithmetic operations. Matrix arithmetic operations are defined by the rules of linear algebra. Array arithmetic operations are carried out element by element, and can be used with multidimensional arrays. The period character (.) distinguishes the array operations from the matrix operations. However, since the matrix and array operations are the same for addition and subtraction, the character pairs .+ and .- are not used.
- Subtraction or unary minus. A-B subtracts B from A. A and B must have the same size, unless one is a scalar. A scalar can be subtracted from a matrix of any size.

Example:
a=[1,2,3;4,5,6];
b=[4,5,6;1,2,3];
a-b
ans =

    -3    -3    -3
     3     3     3

14) Matrix Multiplication

Syntax:     A*B     A.*B

Description:
MATLAB has two different types of arithmetic operations. Matrix arithmetic operations are defined by the rules of linear algebra. Array arithmetic operations are carried out element by element, and can be used with multidimensional arrays. The period character (.) distinguishes the array operations from the matrix operations. However, since the matrix and array operations are the same for addition and subtraction, the character pairs .+ and .- are not used.
* Matrix multiplication. C = A*B is the linear algebraic product of the matrices A and B.
.* Array multiplication. A.*B is the element-by-element product of the arrays A and B. A and B must have the same size, unless one of them is a scalar.

Example:
a=[1,2,3;4,5,6];
b=[4,5,6;1,2,3];
a.*b
ans =

     4    10    18
     4    10    18

15) Matrix Power
Syntax:    A^B    

Description:
MATLAB has two different types of arithmetic operations. Matrix arithmetic operations are defined by the rules of linear algebra. Array arithmetic operations are carried out element by element, and can be used with multidimensional arrays. The period character (.) distinguishes the array operations from the matrix operations. However, since the matrix and array operations are the same for addition and subtraction, the character pairs .+ and .- are not used.
^ Matrix power. X^p is X to the power p, if p is a scalar. If p is an integer, the power is computed by repeated squaring. If the integer is negative, X is inverted first.
.^ Array power. A.^B is the matrix with elements A(i,j) to the B(i,j) power. A and B must have the same size, unless one of them is a scalar.

Example:
a=[1,2,3;4,5,6;7,8,9];
a.^2
ans =

     1     4     9
    16    25    36
    49    64    81
16) Fourier Transform
Syntax:  F = fourier(f)

Description:
The Fourier transform is a representation of an image as a sum of complex exponentials of varying magnitudes, frequencies, and phases. The Fourier transform plays a critical role in a broad range of image processing applications, including enhancement, analysis, restoration, and compression.
The Fourier transform of the expression f = f(x) with respect to the variable x at the point w is defined as follows:
http://www.mathworks.in/help/releases/R2013b/symbolic/eqn1327359241.png
Here c and s are parameters of the Fourier transform. The fourier function uses c = 1, s = –1.
Example:
syms x y
f = exp(-x^2);
fourier(f, x, y)
ans =

pi^(1/2)*exp(-y^2/4)

17)  Z-Transform
Syntax:  F = ztrans(f)

Description:
           The Z-transform of the expression f = f(n) is defined as follows:
   http://www.mathworks.in/help/releases/R2013b/symbolic/eqn1327618459.png

Example:
syms k x
f = sin(k);
ztrans(f, k, x)
 ans =

(x*sin(1))/(x^2 - 2*cos(1)*x + 1)

18) Laplace Transform
Syntax: L = laplace(F)

Description:
              The Laplace transform is defined as follows:
      http://www.mathworks.in/help/releases/R2013b/symbolic/eqn1327616965.png
Example:
syms a t y
f = exp(-a*t);
laplace(f, y)
 ans =

1/(a + y)

19)  Length
Syntax: length(X)

Description:
It finds the number of elements along the largest dimension of an array. array is an array of any MATLAB® data type and any valid dimensions. numberOfElements is a whole number of the MATLAB double class.
For nonempty arrays, numberOfElements is equivalent to max(size(array)). For empty arrays, numberOfElements is zero.

Example:
X = [5, 3.4, 72, 28/4, 3.61, 17 94 89];
length(X)
ans =

     8


20)  Size
Syntax: D = size(X)

Description:
If X is a scalar, then size(X) returns the vector [1 1]. Scalars are regarded as a 1-by-1          arrays in MATLAB®.
If X is a table, size(X) returns a two-element row vector consisting of the number of rows  and the number of variables in the table. Variables in the table can have multiple columns, but size only counts the variables and rows.

Example:
v=[1 2 3; 4 5 6]
size(v)
ans =

     2     3

21)  Display
Syntax: display(X)

Description:
prints the value of X. MATLAB® implicitly calls display after any variable or expression that is not terminated by a semicolon.
To customize the display of objects, overload the disp function instead of the display function. display calls disp.

Example:
X = magic(3);
display(X)
X =

     8     1     6
     3     5     7
     4     9     2

22)  Figure
Syntax: figure(H)

Description:
figure Create figure window.
figure, by itself, creates a new figure window, and returns
its handle.
 
figure(H) makes H the current figure, forces it to become visible,
and raises it above all other figures on the screen.  If Figure H
does not exist, and H is an integer, a new figure is created with
handle H.

Example:
Figure
Opens a figure window

23)  whos
Syntax: whos

Description:
whos List current variables, long form.
whos is a long form of WHO.  It lists all the variables in the current
workspace, together with information about their size, bytes, class,
etc.

In a nested function, variables are grouped into those in the nested
function and those in each of the containing functions, each group
separated by a line of dashes.  In nested functions and in functions
containing nested functions, even uninitialized variables are listed.
   
whos GLOBAL lists the variables in the global workspace.
whos -FILE FILENAME lists the variables in the specified .MAT file.
whos ... VAR1 VAR2 restricts the display to the variables specified.

The wildcard character '*' can be used to display variables that match
a pattern.  For instance, whos A* finds all variables in the current
workspace that start with A.

Example:
whos
  Name      Size            Bytes  Class     Attributes

  X         3x3                72  double  

24)  who
Syntax: who

Description:
who lists the variables in the current workspace.
In a nested function, variables are grouped into those in the nested
function and those in each of the containing functions.  who displays
only the variables names, not the function to which each variable
belongs.  For this information, use WHOS.  In nested functions and
in functions containing nested functions, even unassigned variables
are listed.

Example:
who

Your variables are:

Area   ans    k      n      s1     s3     theta  x      z     
a      f      m      r      s2     t      v      y     

25)  imread
Syntax: A = imread(FILENAME,FMT)

Description:
It reads a grayscale or color image from the file specified by the string filename. If the file is not in the current folder, or in a folder on the MATLAB® path, specify the full pathname.

The text string fmt specifies the format of the file by its standard file extension. For example, specify 'gif' for Graphics Interchange Format files. To see a list of supported formats, with their file extensions, use the imformats function. If imread cannot find a file named filename, it looks for a file named filename.fmt.

The return value A is an array containing the image data. If the file contains a grayscale image, A is an M-by-N array. If the file contains a truecolor image, A is an M-by-N-by-3 array. For TIFF files containing color images that use the CMYK color space, A is an M-by-N-by-4 array. See TIFF in the Format-Specific Information section for more information.

The class of A depends on the bits-per-sample of the image data, rounded to the next byte boundary. For example, imread returns 24-bit color data as an array of uint8 data because the sample size for each color component is 8 bits. See Tips for a discussion of bitdepths, and see Format-Specific Information for more detail about supported bit depths and sample sizes for a particular format.

Example:

A = imread('ngc6543a.jpg');
imread returns a 650-by-600-by-3 array, A.

26) Imresize
Snytax: B = imresize(A, SCALE)

Description:
imresize Resize image.
B = imresize(A, SCALE) returns an image that is SCALE times the
size of A, which is a grayscale, RGB, or binary image.
  
B = imresize(A, [NUMROWS NUMCOLS]) resizes the image so that it has
the specified number of rows and columns.  Either NUMROWS or NUMCOLS
may be NaN, in which case imresize computes the number of rows or
columns automatically in order to preserve the image aspect ratio.

Example:
I = imread('rice.png');        J = imresize(I, 0.005)
J =

  121  114
   67   59

27) fliplr
Snytax: fliplr(X)

Description:
fliplr Flip matrix in left/right direction.
fliplr(X) returns X with row preserved and columns flipped
in the left/right direction.

Example:
X=[1 2 3; 4 5 6];
fliplr(X)
ans =

     3     2     1
     6     5     4

28) display
Syntax: display(X)

Description:
Display text and numeric expressions

Example:
display(X)
X =

     1     2     3

     4     5     6