Angular JS

***Preparing content***




Note: Bootstrap uses Grunt for its build system, with convenient methods for working with the framework. It’s how we compile our code, run tests, and more.  (

Grunt commands:

  1. grunt dist
    • Regenerates the /dist/ directory with compiled and minified CSS and JavaScript files.
  2. grunt watch
    • Watches the Less source files and automatically recompiles them to CSS whenever you save a change.
  3. grunt test
  4. grunt docs
    • Builds and tests CSS, JavaScript, and other assets which are used when running the documentation locally via bundle exec jekyll serve.
  5. grunt
    • Compiles and minifies CSS and JavaScript, builds the documentation website, runs the HTML5 validator against the docs, regenerates the Customizer assets, and more. Requires Jekyll.

  • npm required for Grunt
  • Grunt is a javascript task runner
    • compress everything – all done by grunt
    • compiles Sass into css
    • compress JavaScript, CSS, HTML files
    • Combine JS files into a single file
    • Concatenates JS & CSS files
  • Build system with grunt
  • Software dependencies:
    • Node – javascript runtime
    • npm – package manager
    • grunt cli
    • grunt
    • plugins
  • Installing grunt
    • npm install grunt
    • pakcage json has to be created
      • npm init – creates the package json
      • package name has to be defined and shouldn’t be ‘grunt’
  • Installing grunt cli
    • npm install -g grunt-cli
  • Running grunt
    • grunt
  • Running grunt tasks
    • grunt taskname
  • Using existing project:
    • npm intall – will install all dependencies
  • Plugins:
    • grunt has so many plugins
      • loadNpmTasks – loads the default configs
      • To concat, you need to load the grunt-contrib-concat & to watch the changes grunt-contrib-watch
      • Installing grunt-contrib
        • npm install grunt-contrib-concat –save -dev
        • similar commands for all plugins
    • Handlebars:
    • Uglify:
      • beautifies js code
    • Sass:
      • Complies sass files to css
      • Installing grunt-contrib-sass

Installing NodeJS

1)Download node.js(.msi file)
2)Install node.js from node js website. NPM is installed as part of the installation.
3)Run node.js application / run git bash/ run command line
4)Check node command working on all of the above
5)If node command doesn’t work on git bash, set the path using the following
a.export PATH=$PATH:”C:\Program Files\nodejs”
b.unix style path
6)If node command doesn’t work on command line, set the path using the following
a.SET PATH=C:/Program Files/nodejs;%PATH%
7)Nodejs runs on the same java script engine as the chrome which is V8 Javascript engine.
8)With Node you have to write the webserver unlike PHP where you just install and use, here at node you have to write the webserver.

Testing Node Installation:

  1. Open command prompt and type in “node -v” to see the node version
  2. alternatively you can open node.js and type in “process.version”
  3. If you have opened command prompt and typed in ‘node’ and pressed Enter then you need to type in “process.version” to know the version of node

Test NPM installation:

  1. Make sure ‘%AppData%/npm’ is added to the path variable. Add it if it is not already added
  2. create a node-test folder
  3. Go to the folder on command prompt
  4. Type in command ‘npm init’ which creates package.json file for your project
  5. If the command doesn’t work, it means you haven’t set the path correct. Check point 1 and set your path variable right.
  6. Install a sample package by typing the command “npm install lodash”



htaccess/web.config url rewrite from asp to php


<IfModule mod_rewrite.c>
RewriteEngine On


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond {REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{QUERY_STRING} id=([_0-9a-z-]+)
RewriteRule Content\.asp$ %1 [r=301,L]




<?xml version=”1.0″ encoding=”UTF-8″?>
<rule name=”removing .php” stopProcessing=”true”>
<match url=”^(.*)$” />
<conditions logicalGrouping=”MatchAll”>
<add input=”{REQUEST_FILENAME}” matchType=”IsFile” ignoreCase=”false” negate=”true” />
<add input=”{REQUEST_FILENAME}.php” matchType=”IsFile” ignoreCase=”false” />
<action type=”Rewrite” url=”{R:1}.php” />
<rule name=”Asp classic legacy 301 redirect to php” stopProcessing=”true”>
<match url=”Content\.asp$” />
<add input=”{QUERY_STRING}” pattern=”id=([_0-9a-z-]+)” />
<action type=”Redirect” url=”{C:1}” redirectType=”Permanent” appendQueryString=”false”/>

Uploadify Uploadifive support check

Check if the browser supports “multiple” attribute for input file element, this way you don’t have to worry about browser or its version. You are only checking the browser feature.

var inputFile=document.createElement(“input”);

if(typeof inputFile.multiple!=”undefined”) return “Supports Uploadifive!”;
else return “Supports Uploadify!”;


Escape strings issue universal fix

Escape strings #onebigissue in programming, My solution works for all.

Say I have a textarea field “notes”

To encode all the special characters for passing the data, you’ll need to use “encodeURIComponent()”.
The encodeURIComponent doesn’t encode ~!*()’
To encode the remaining i have a function to replace single quotes in an encoded string.

function encodeURIComponentReplace(encodeString){
  //encodeURIComponent() will not encode: ~!*()' - use this function to do the job	
  var intIndexOfMatch = encodeString.indexOf( "'" );
  while (intIndexOfMatch != -1){
    encodeString = encodeString.replace( "'", "%27" )
    intIndexOfMatch = encodeString.indexOf( "'" );
  return encodeString;

If you send the parameters in GET method to PHP backend,
you’ll receive parameter values with added slashes.
You should strip slashes and convert the htmlentities before database insert/update.


If you send the parameters in POST method you do not have to do the above step.

Retrieving the data from the database using PHP.

If you are simply echoing values from the database to front-end use the following PHP code:

If you are sending values in a json array do the following before encoding:
then json_encode the output array.

What happens when you type in a URL in browser?

  1. As you type in the characters in the address bar, browser’s auto-complete mechanism kicks in, showing bunch of cached urls (only matching).
  2. On pressing enter, keyboard event fired (or) mouse click event if it’s a mouse click.
  3. Browser requests OS to check local DNS cache (where all the previously visited DNS records stored) for the IP Address of the server, if the records not stored locally then the request is handled by the recursive DNS servers located at your ISP, if it is not still not found then the request goes to root name servers (13). These name servers contains pointers for all the TLDs (Top Level Domains .com, .net, .org). Name servers looks at the top level domain and direct the query to the TLD DNS servers corresponding pointers.
    TLD DNS servers do not store all the records, instead they keep track of authoritative name servers for all the domains with their TLDs. TLD DNS servers looks at the next part of the query from right to left then direct the query to authoritative name server for the URL.
    Authoritative name servers contains all of the DNS records for the given domain such as host records, mx records etc. The recursive DNS server at the ISPs receives host record from the authoritative servers and stores the record in its cache for the future use. The host record is given to your computer it will be stored in your local DNS cache for future use and passes the information to the browser.
  4. the browser opens a TCP connection with the host and makes http/https request on port 80 (or) any specific port. the web server at the host sends a web page at that URL.