Skip to main content

Posts

Simple JavaScript Object and Class Examples

In JavaScript, most things are objects. An object is a collection of related data and/or functionality Namespace: Everything you create in JavaScript is by default global. In JavaScript namespace is Global object . How to create a namespace in JavaScript? Create one global object, and all variables, methods, and functions become properties of that object. Example:  // global namespace var MYAPP = MYAPP || {}; Explaination: Here we first checked whether MYAPP is already defined.If yes, then use the existing MYAPP global object, otherwise create an empty object called MYAPP How to create sub namespaces? // sub namespace MYAPP.event = {}; Class JavaScript is a prototype-based language and contains no class statement.JavaScript classes create simple objects and deal with inheritance. Example: var Person = function () {}; Explaination: Here we define a new class called Person with an empty constructor. Use the class keyword class Calculation {}; A class expr...

PHP Fresher Technical Interview Questions

PHP Fresher Technical Interview Questions Question : How to find out leap year? Answer:  A leap year is a calendar year containing one additional day. It has 366 days instead of the usual 365 days. function isLeapYear($year){   return ((0 == ($year % 4)) && (0 != ($year % 100)) || (0 == ($year % 400))); } var_dump(isLeapYear(2020)); Code Explanation: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. Question : How to find out Prime number? Answer:   Prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Function to check whether prime number or not function isPrimeNumber($num){ $flag = 0; for($i=2; $i<=$num/2; ++$i)     {         // condition for nonprime number         if($num%$i==0)   ...

PHP 7 Feautures

Performance Battle, PHP 7 vs. PHP 5 With virtually all updates, minor performance upgrades are to be expected. However, this time PHP brings a significant improvement over earlier versions making sheer performance one of PHP 7’s most attractive features. This comes as part of the “PHPNG” project, which tackles the internals of the Zend Engine itself. By refactoring internal data structures and adding an intermediate step to code compilation in the form of an Abstract Syntax Tree (AST), the result is superior performance and more efficient memory allocation. The numbers themselves look very promising; benchmarks done on real world apps show that PHP 7 is twice as fast as PHP 5.6 on average, and results in 50 percent less memory consumption during requests, making PHP 7 a strong rival for Facebook’s HHVM JIT compiler. Have a look at this infographic from Zend depicting performance for some common CMS and Frameworks. PHP 7 Syntactic Sugar PHP 7 comes with new syntax features. W...

MySql Indexing

MySql Indexing A database index is a data structure that improves the speed of operations in a table.INSERT and UPDATE statements take more time on tables having indexes where as SELECT statements become fast on those tables. The reason is that while doing insert or update, database need to insert or update index values as well. Indexes are a way to avoid scanning the full table to obtain the result CREATE TABLE person ( last_name VARCHAR(50) NOT NULL, first_name VARCHAR(50) NOT NULL, INDEX (last_name, first_name) ); So if your index has two columns, say last_name and first_name, the order that you query these fields matters a lot. This query would take advantage of the index: SELECT last_name, first_name FROM person WHERE last_name = "John" AND first_name LIKE "J%" Using Create statement CREATE INDEX techsudhir_age ON employees(emp_name, emp_age); Alter command to update index ALTER TABLE person  ADD INDEX (name); Removing Indexes DROP...

MySQL Examples for Beginners

MySQL Examples for Beginners This basic MySQL query which will help beginners to learn. -- Delete if it exists mysql> DROP DATABASE IF EXISTS databaseName -- Create only if it does not exists mysql> CREATE DATABASE IF NOT EXISTS databaseName -- Set the default (current) database mysql> USE databaseName -- Show the default database mysql> SELECT DATABASE() -- Show the CREATE DATABASE statement mysql> SHOW CREATE DATABASE databaseName  -- Show all the tables in the current database. mysql> SHOW TABLES; -- Create the table "products". mysql> CREATE TABLE IF NOT EXISTS products ( productID bigint(11) UNSIGNED NOT NULL AUTO_INCREMENT, productCode CHAR(3) NOT NULL DEFAULT '', name VARCHAR(30) NOT NULL DEFAULT '', quantity INT UNSIGNED NOT NULL DEFAULT 0, price DECIMAL(7,2) NOT NULL DEFAULT 0000.00, PRIMARY KEY (productID) ); -- Describe the fields (columns) of the "products" table mysql> DESCRIBE pro...

How to learn NodeJs in 5 steps

NodeJs Entry level Tutorial Node.js is an open-source, cross-platform JavaScript runtime environment for developing a diverse variety of tools and applications. It is a server-side platform built on Google Chrome's JavaScript Engine Follow Basic steps to run your first example Step1: Download Nodejs and install it. Step2: After installation Check NodeJs working or not a) Open Windows Command Prompt b) Execute the Command node -v. It print a version number Example: C:\Users\Sudhir>node -v Output: v6.9.2 c) Execute the Command npm -v . It print NPM’s version number Example: C:\Users\Sudhir>npm -v Output: 3.10.9 Step3: Type npm init and press enter Step4: It will ask for file name, version and description etc Step5: It will create a package.json file { "name": "nodetest", "version": "1.0.0", "description": "Hello test", "main": "index.js", "scripts": { ...

Setup a Virtual Host on WAMP

Setup a Virtual Host on WAMP Running several name-based web sites on a single IP address. Step 1: Add Code in file C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf uncomment the LoadModule vhost_alias_module modules/mod_vhost_alias.so uncomment the Include conf/extra/httpd-vhosts.conf Step 2: Add VirtualHost code in file C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf # Ensure that Apache listens on port 80 Listen 80 <VirtualHost *:80>     ServerAdmin sudhir@techsudhir.com     DocumentRoot "C:/wamp/www/wordpress"     ServerName techsudhir.local ServerAlias www.techsudhir.local     ErrorLog "logs/techsudhir.local-error.log"     CustomLog "logs/techsudhir.local-access.log" common <Directory "/"> Deny from all Allow from 127.0.0.1 </Directory> </VirtualHost> Save All Step 3: Add Code in file C:\Windows\System32\drivers\etc\hosts 127.0.0.1  techsudhir.local...