Difference between a Framework and a Library : Javascript point of view

While attending interviews for programming jobs,one of the most common question you would face is to explain the difference between a libarary and a framework.Here in this article we look at the difference between a library and a framework from a Javascript point of view. Library Libraries provide methods/functions/modules  that can be useful while building your application.While using a library the control is with your code and you call the functions the libraries provide from within  your code.These functions are reusable and can be used at different parts of building your application.There are many Javascript libraries like JQuery,JqueryUI,moment.js etc.These libraries provides functions that serves different purposes.   So we can generally describe the working of a library as We call the library functions from from our code Flow Control is with our code                For example when using JQuery library, we include the library in our code and call the library functions from within our code in the following way

Framework A framework provides structure,resources for building your application.While using a framework you call your logic from within the framework .The control is with the framework code , your code is called when  logic is…

first-child and nth-child selectors : Styling multiple Elements with same class – CSS
css , Beginner , Uncategorized / July 7, 2018

first-child  – This selector selects first child of its parent. To color first one of elements with the same class,we use first-child selector.Consider below example with multiple divs(.box)  inside parent div(.container).To change the style of first div

  nth-child – This selector selects nth child of its parent. We can achieve the above result using nth-child selector .The number in the bracket indicates the order of the child


How to change ‘sql_mode’ in mysql
PHP , Uncategorized / July 2, 2018

To see Mysql mode settings,do the following query. Mysql mode is not linked to any particular database. Modes can be set locally to the session (connection), or for the server globally.

This gives results like below   Now to change sql_mode,you need to run query like this

Example Some times after  importing database and changing some table structure,you may get an error like this. This is because NO_ZERO_IN_DATE and NO_ZERO_DATE is enabled in and database has invalid date values. NO_ZERO_IN_DATE The NO_ZERO_IN_DATE mode affects whether the server permits dates in which the year part is nonzero but the month or day part is 0. Example – ‘2010-00-01’ or ‘2010-01-00’ NO_ZERO_DATE This mode is deprecated This determines whether the server permits ‘0000-00-00’ . NO_ZERO_IN_DATE also depends on whether strict SQL mode is enabled. Removing above modes from sql_mode  lets the server allow invalid dates in the aforementioned format     Or to set it PERMANANTLY, change etc/my.cnf

and restart WHAT is sql_mode Server SQL modes determine what SQL syntax MySQL should support and what kind of data validation checks it should use. This makes it easier to use MySQL in different environments. See more on  list of sql…

Event propagation in javascript – Capturing and Bubbling

Event propagation is the propagation of an event through the elements in the HTML DOM. When an event happens phase1 – Event Capturing is done until the target is reached phase2 –  Bubbling is done executing handlers on the way Event bubbling and capturing are the two ways of event propagation in processing an event by the HTML DOM API.Event bubbling means that when an event happens, it propagates all the way up the parent to the ancestor elements. Bubbling When an event happens on an element,say click, it first runs the handlers on it, then on its parent, then all the way up.See the below example -The button inside the wh4 div was clicked. Onclick handler is on the ancestor wh4 is run.   Not every event get bubbled.Here is a list of  the most common event handlers. onAbort onBlur onChange onClick onDblClick onDragDrop onError onFocus onKeyDown onKeyPress onKeyUp onLoad onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp onMove onReset onResize onSelect onSubmit onUnload Not every event bubbles.

If x is true then the event bubbles.You can check this creating the event By default all the Browsers support event bubbling. Event Capturing When an event happens capturing occurs in a way …

What are cookies and how to set and get them with Javascript

Cookies are data stored as text files in the computer.They are used store data that are needed to be remembered , like user information.Cookies can be set in client side and server side. For example,consider a user sign in to your website.The server sends back some response.The response have a token/id that can be stored as a cookie.This cookie value can keep the users details status in the client side. Cookie has a name and value pair,expiry time,path and secure . The security flags that are used to provide more security HttpOnly – HttpOnly flag sets the cookie unavailable to client side scripts.This prevent cross site scripting attacks(XSS) secure – Sets cookie to be send via a secure encrypted channel.Browser will send cookie only via an HTTPS request and prevent sending cookie via HTTP request. setcookievalue This function has three arguments name – cookie name. value – value of the cookie. hours- hours determine the expiry hours. document.cookie lets us store the cookie associated with the current document. getCookie This function has one argument ,cookie name document.cookie gets all the cookies associated with the current document.A cookie with a specific name can be obtained using the getCookie function.   getCookievalue This function has…

Understading working of javascript : Google’s JavaScript V8 Engine

What is javascript? Javascript is a single threaded,aynchrounous,non-blocking concurrent language.If you have an javascript code ,it is run by engines.Javascript v8 Engine powers Node.js ,Chrome browser,Electron(Desktop Application dev).There are many Javascript engines like Chakra(Microsoft), Spidermonkey(Firefox). We focus on V8 Javascript engine to understand more about JavaScript engines here.What V8 basically does is that it generate machine code from source code . All modern JavaScript engines use Just In Time(JIT) compilation also V8. V8 does’nt generate machine code Ahead of time but on run time when we need it.Compilation and execution goes at the same time. V8 features an interpreter called Ignition and an optimizing compiler  called TurboFan. Bookmark this page . Detailed study on V8 Engine will be available here soon…..  

An introduction to Eloquent ORM in Laravel
interview questions , PHP , Uncategorized / June 20, 2018

ORM refers to Object Relational Mapping.What ORM tools like  Eloquent does is that they are equipped with a metadata descriptor which helps in connecting object code to a relational database.To learn more on ORM refer this article. https://truetocode.com/orm-using-sequelize-orm-with-express-node-js/418/ Now,we know that sequelize is an ORM tool that is used to connect node applications to relational databases such as Mysql/postgres.For PHP Developers ,Laravel is equipped with a very simple,efficient ORM called Eloquent ORM. Using Eloquent To create model class we use the following command

Now in case you dont know,Artisan is a command line interface provided with Laravel just like the other command line interfaces you might have used,like angular-cli,Artisan helps you to generate files while working with Laravel. The above command creates a model file for our Table and it looks like this

As you can see all models extend “Illuminate\Database\Eloquent\Model” Also note that the table has ‘snake case plural’ name of the class.That is ‘televisions’ table and ‘television’ class.Uncomment the $table variable in the above code to use custom table name. Now,To generate a migration script on creating the model.This can be done using the following command.

The migration file looks like this

To run the…

Share this page in social media platforms