Wednesday, October 19, 2022

Understanding JavaScript Execution Context like never before

Here is the article. 

JavaScript's Execution Context is the base of understanding many other fundamental concepts correctly. Often we find lots of misunderstanding in each of the following concepts just because we misunderstood the fact behind Execution Context. 

  • Hoisting
  • Scope
  • Scope Chain
  • Closure
  • Event loop
Benefits to understand execution context:

  • Introduce lesser bugs into the Source Code. 
  • Become a boss in doing great code reviews
  • Great eyes for Debugging
  • Easier ways to tackle production issues






The JavaScript `this` Keyword + 5 Key Binding Rules Explained for JS Beginners

 JavaScript's this keyword is one of the hardest aspects of the language to grasp. But it is critically important for writing more advanced JavaScript code.

In JavaScript, the this keyword allows us to:

  • Reuse functions in different execution contexts. It means, a function once defined can be invoked for different objects using the this keyword.
  • Identifying the object in the current execution context when we invoke a method.

The this keyword is very closely associated with JavaScript functions. When it comes to this, the fundamental thing is to understand where a function is invoked. Because we don't know what is in the this keyword until the function is invoked.

The usage of this can be categorized into five different binding aspects. In this article, we will learn about all five aspects with examples.

  1. There are three very special methods, call(), apply() and bind() that help us achieve explicit binding.

In Summary

To summarize,

  • In the case of implicit binding, this binds to the object adjacent to the dot(.) operator while invoking the method.
  • In the case of explicit binding, we can call a function with an object when the function is outside of the execution context of the object. The methods call(), apply(), and bind() play a big role here.
  • When a function is invoked with the new keyword, the this keyword inside the function binds to the new object being constructed.
  • When the this keyword is not resolved with any of the bindings, implicit, explicit or new, then this is bound to the window(global) object. In JavaScript's strict mode, this will be undefined.
  • In HTML event handlers, this binds to the HTML elements that receive the event.

There is one more case where this behaves differently, such as with ES6 arrow functions. We will take a look at that in a future article.


Tuesday, October 18, 2022

Meta | SeekingAlpha article

 

Meta Down -62.56% YTD, Teaming Up With Microsoft Could Be A Major Future Catalyst

Here is the link.

Monday, October 17, 2022

Mona Mahajan

 As the Senior Investment Strategist and a member of the Investment Strategy team, I'm responsible for providing market advice and guidance across asset classes, in addition to supporting our financial advisors and clients with differentiated investment thought leadership. I also serve as a key spokesperson, communicating – both internally and externally – the firm’s investment ideas and asset allocation views. I appear regularly on broadcast media, such as CNBC and Bloomberg TV, as well as print media, to express the firm's market and economic views.


Follow me at Twitter @MonaMahajanView

Edward Jones, a Fortune 500 company headquartered in St. Louis, provides financial services in the U.S. and, through its affiliate, in Canada. Every aspect of the firm's business, from the investments offered to the location of branch offices, caters to individual investors. The firm's nearly 19,000 financial advisors serve more than 7 million clients with a total of $1.6 trillion in client assets under care. Visit edwardjones.com or the recruiting website at careers.edwardjones.com. Member SIPC.

A Strong U.S. Dollar Buoys Small-Cap Companies’ Stocks

 

The S&P 600 small-cap index is on pace to outperform the S&P 500 this year for the first time since 2016



Small-cap stocks are bouncing back. A strong U.S. dollar is boosting their run.

After suffering bruising losses earlier this year, shares of many small, domestic-focused companies are outshining the large-capitalization stocks that dominate the U.S. equity markets. In October, the S&P 600 small-cap index has risen 5.3%, beating the large-cap S&P 500’s 2.6% increase. For the year, the S&P 600 is on pace to outperform the S&P 500 for the first time since 2016.

Here is the article. 

Best small-cap funds

 

Best small-cap funds

If you don't want to choose individual small-cap stocks for your portfolio, you can instead gain exposure to small-cap companies by investing in a small cap-focused exchange-traded fund (ETF) or mutual fund. Here are a couple of options:

  • iShares Russell 2000 ETF (NYSEMKT:IWM): This ETF tracks the performance of the Russell 2000, which is considered the leading index of small-cap stocks. The fund's managers charge an annual management fee of 0.19%, which works out to $1.90 for every $1,000 invested.
  • Fidelity Small Cap Growth Fund (NASDAQMUTFUND:FCPGX): This mutual fund invests in small-cap stocks that have high growth potential. It's actively managed, with the objective of outperforming the Russell 2000, so the fund's fees -- 0.94% annually -- are somewhat high compared to most ETFs.

Friday, October 14, 2022

AJAX with PHP: Load dynamic content to websites

 Add dynamic, asynchronously loading content to websites to make them more modern, professional, and user friendly with Ajax and PHP. Learn how to use Ajax to send and receive data in the background and how to use PHP to assemble and return text, HTML, or JSON responses. Kevin Skoglund walks viewers through sample projects for the most common Ajax use cases: buttons to allow users to mark or favorite items, forms that validate and submit data in the background, infinite scrolling of paginated content, and autosuggestions beneath a text field.

Learning objectives

  • What is Ajax?
  • Creating Ajax requests and responses
  • Monitoring Ajax request state and events
  • Responding to Ajax requests with HTML and JSON
  • Building Ajax buttons
  • Submitting forms with Ajax
  • Implementing infinite scrolling
  • Adding autosuggestions to text fields

Thursday, October 13, 2022

Time to push hard on learning

Oct. 13, 2022

I like to go back to work on web programming daily and master PHP programming with mySQL, WordPress. If I commit 100% to my coding skills, I definitely can see big difference every month or three months. 

7 things to learn 

I finally figure out that best learning is to work on a project, and then work hard on the goal to complete the project. I like to choose to be a software programmer to devote my heart on the project I am working on. 

  1. Always work on a project with some coding requirements; 
  2. Take small breaks to look up internet, Linkedin courses and other resources like youtube.com videos;
  3. Keep hands on coding project 70% of time at work. It is better to code and learn, learn and then code;
  4. It is important to learn to work with others. 
一个程序员上班投入100%时间, 争取做最好最有效工作;需要不停挑战自己。 光看书, 看课程,没有压力, 时间浪费了。做好一个程序,需要付出辛苦劳动。 

利用上班时间,锻炼自己。多做几个项目,提高自己能力。提高工作效率。

做好编程工作,需要花很多时间。 自己管理好自己,需要付出辛苦劳动。 




PHP - AJAX and MySQL

Here is the article.

AJAX can be used for interactive communication with a database.

AJAX Database Example

The following example will demonstrate how a web page can fetch information from a database with AJAX:

Example Explained - The MySQL Database

The database table we use in the example above looks like this:

Example Explained

In the example above, when a user selects a person in the dropdown list above, a function called "showUser()" is executed.

The function is triggered by the onchange event.

Here is the HTML code:

<!DOCTYPE html>
<html>
<head>
<script>
function showUser(str) {
  if (str=="") {
    document.getElementById("txtHint").innerHTML="";
    return;
  }
  var xmlhttp=new XMLHttpRequest();
  xmlhttp.onreadystatechange=function() {
    if (this.readyState==4 && this.status==200) {
      document.getElementById("txtHint").innerHTML=this.responseText;
    }
  }
  xmlhttp.open("GET","getuser.php?q="+str,true);
  xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Joseph Swanson</option>
<option value="4">Glenn Quagmire</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>

Tuesday, October 11, 2022

Web programming courses on Linkedin learning

  1.  JavaScript: Enhancing the DOM
  2. The DOM in JavaScript, jQuery, AngularJS, and React
  3. Succeeding in Web Development: Full stack and Front end
  4. UX foundations: Accessibility
  5. Responsive layout

Web programming foundations | 2 hours course

Here is the link. 

To be an effective web programmer, you have to understand what happens when you enter a URL or click on a link. Under every webpage lies the markup—JavaScript, HTML, and CSS—and the hierarchy that controls display—the Document Object Model (DOM). Then there is the server that hosts the files, the browser that renders them, the metadata, and the mobile experience to consider. Explore what happens below the surface, and learn how to write better code. This course provides a deep dive into the world wide web, and the underlying structures you need to understand to build robust applications and websites that are efficient and easy to maintain. Learn how HTML documents provide the foundation for CSS and JavaScript, and see how to layer presentation and interactions on top. Learn how different code editors and browsers interact with web content, enabling editing, programming, and display. Discover why accessibility is so important to keeping the web open and available to all users, and what workflow works best for web programming. Instructor Morten Rand-Hendriksen keeps the lessons fun and fast-paced, so it's easy for almost anyone—web programmers, web designers, and even web publishers—to follow along.


PHP Select Option

 Here is the article. 

Summary: in this tutorial, you will learn how to use the <select> element to create a drop-down list and a list box and how to get the selected values from the <select> element in PHP.

A quick introduction to the <select> element

The <select> is an HTML element that provides a list of options. The following shows how to define a <select> element in HTML:

Friday, October 7, 2022

Node js vs. PHP: An In-depth Comparison Guide for Web Development

Here is the article. 

Both PHP and Node.js are effective options for back-end development. And just like with other technologies, there’s a debate in the dev community when it comes to defining which of these is the best. 

Node.js is an open-source, cross-platform runtime environment that executes JavaScript for backend and frontend development. While PHP is an open-source server-side script language. Currently, one of the most popular and used technologies of all time. 

So which of them is better? And how do you choose whether to use PHP or Node.js for your next project’s server-side development? Let’s find out!

In this comparison article, we will look at the two of them in-depth understanding their advantages and disadvantages and comparing their:

  • Performance
  • Development
  • Database
  • Hosting
  • Execution speed
  • Practical application


Wednesday, October 5, 2022

PHP: Object-Oriented Programming with Databases

 Learn how to interact with databases using object-oriented PHP code. In this intermediate course, Kevin Skoglund teaches powerful PHP techniques that streamline interactions with MySQL databases. PHP developers will benefit from the efficient, well-organized, reusable, and easy-to-understand code that object-oriented programming (OOP) offers. Kevin shows how OOP techniques can optimize database queries, help manage sessions, and simplify user logins. He provides practical examples and tips to create objects that interact seamlessly with database rows, to build a content management system with HTML forms, to authenticate users, and to break up long lists of database data into smaller pages.


Note: This is an intermediate-level training course that assumes you have existing knowledge of PHP. To refresh your skills, check out PHP Essential Training and PHP: Object-Oriented Programming.

Learning objectives

  • Creating a project database and tables
  • Connecting to the database
  • Database queries with OOP
  • The active record design pattern
  • Defining a database-driven class
  • Performing common database tasks with OOP
  • Creating inheritable and reusable code
  • Object-oriented user authentication
  • Object-oriented pagination

Tuesday, October 4, 2022

PHP Array | Time to go over all functions

Here is the link. 

  1. array()
  2. array_change_key_case
  3. array_chunk()
  4. array_column()

Strictly typed | PHP

 

Creating Strictly Typed Arrays and Collections in PHP

Here is the article. 

Problems with this kind of typed arrays

One of the downsides of using this feature as typed arrays is that we can only define one such array per method. Let’s say we wanted to have a Movie class that expects a list of air dates together with a list of ratings in the constructor, instead of setting them later via optional methods. This would be impossible with the method used above.

Another problem is that when using PHP 7, the return types of our get() methods would still have to be “array”, which is often too generic.

Thursday, September 29, 2022

Import CSV File Into MySQL Table

Here is the article. 

This tutorial shows you how to use the LOAD DATA INFILE statement to import CSV file into MySQL table.

The  LOAD DATA INFILE statement allows you to read data from a text file and import the file’s data into a database table very fast.

Before importing the file, you need to prepare the following:

  • A database table to which the data from the file will be imported.
  • A CSV file with data that matches with the number of columns of the table and the type of data in each column.
  • The account, which connects to the MySQL database server, has FILE and INSERT privileges.

Suppose we have a table named discounts with the following structure:

We use CREATE TABLE statement to create the discounts table as follows:

CREATE TABLE discounts ( id INT NOT NULL AUTO_INCREMENT, title VARCHAR(255) NOT NULL, expired_date DATE NOT NULL, amount DECIMAL(10 , 2 ) NULL, PRIMARY KEY (id) );

The field of the file is terminated by a comma indicated by  FIELD TERMINATED BY ',' and enclosed by double quotation marks specified by ENCLOSED BY '" ‘.

Each line of the CSV file is terminated by a newline character indicated by LINES TERMINATED BY '\n' .

Because the file has the first line that contains the column headings, which should not be imported into the table, therefore we ignore it by specifying  IGNORE 1 ROWS option.

Now, we can check the discounts table to see whether the data is imported.

Transforming data while importing

Sometimes the format of the data does not match the target columns in the table. In simple cases, you can transform it by using the SET clause in the  LOAD DATA INFILE statement.

Suppose the expired date column in the  discount_2.csv file is in  mm/dd/yyyy format.

When importing data into the discounts table, we have to transform it into MySQL date format by using str_to_date() function as follows: