Sorting an Array by Date Value in JavaScript

Learn how to sort an array of items by date value in JavaScript. If you have an array of objects like the one below, which contains a set of date objects: const activities = [ { title: 'Hiking', date: new Date('2019-06-28') }, { title: 'Shopping', date: new Date('2019-06-10') }, { title: 'Trekking', date: new Date('2019-06-22') } ] and you want to sort those activities by the date property, you can use the sort() method of Array....

Sorting Text Using the Linux `sort` Command

In the world of Linux, the sort command is a powerful tool that allows you to sort records or lines of text. Whether you have a text file with a jumbled list of names, or you want to sort the output of another command, sort has got you covered. Let’s start with a simple example. Suppose you have a text file that contains the names of dogs: Spot Rusty Fido Max To sort these names in alphabetical order, you can use the sort command:...

SQL Injection: Protecting Your Application from Attacks

SQL injection poses a significant threat to database-driven applications that rely on SQL queries. The vulnerability lies in the lack of input sanitization, which allows attackers to manipulate the queries’ behavior. Let’s take a look at a simple Node.js example to understand how SQL injection can occur: const color = // coming from user input const query = `SELECT * FROM cars WHERE color = '${color}'` In this case, if the value of color is a legitimate color like “red” or “blue”, the query works as intended....

SQL Joins: How to Perform a Simple Join Between Two Database Tables

Joins are an essential tool in SQL for correlating data from different tables. By applying relational algebra, joins allow us to combine information based on specific column values. In this blog post, we will explore a simple example of performing a join between two tables. Let’s consider two tables, people and cars, with the following structures: CREATE TABLE people ( age INT NOT NULL, name CHAR(20) NOT NULL PRIMARY KEY ); CREATE TABLE cars ( brand CHAR(20) NOT NULL, model CHAR(20) NOT NULL, owner CHAR(20) NOT NULL PRIMARY KEY ); To add some sample data, we can execute the following queries:...

SQL Views: Creating and Utilizing Views in a SQL Database

When working with SQL, one powerful feature you can utilize is the creation of views. Unlike regular tables, views are dynamically generated based on the result of a SELECT query. This allows for flexible data retrieval and analysis within your database. Let’s use the example we used in the previous lesson on joins: CREATE TABLE people ( age INT NOT NULL, name CHAR(20) NOT NULL PRIMARY KEY ); CREATE TABLE cars ( brand CHAR(20) NOT NULL, model CHAR(20) NOT NULL, owner CHAR(20) NOT NULL PRIMARY KEY ); To populate the tables, we can insert some data:...

SQL, Unique and Primary Keys: How to Create and Use Them in a Database

In a SQL database, it’s important to have a way to ensure uniqueness and identify individual rows in a table. This can be achieved by using unique and primary keys. Let’s start with a table created using the following command: CREATE TABLE people ( age INT NOT NULL, name CHAR(20) NOT NULL ); By default, this table allows duplicate rows and columns that repeat the same values. However, we can prevent this by adding the UNIQUE key constraint to a column....

sqlite-how-to-install

title: “How to Install SQLite on macOS” In this tutorial, I will explain the simple steps needed to install SQLite on macOS. On macOS, you don’t need to worry about installing SQLite because it is already preinstalled in all modern versions of macOS. To start using SQLite, follow these steps: Open a terminal on your macOS machine. Enter the following command in the terminal: sqlite3 Press “ctrl-C” twice to exit the SQLite executable....

Squashing Git Commits: Simplifying Your Git Workflow

As a regular user of Git, I have found myself utilizing its basic functionalities on a daily basis. However, there are advanced features of Git that still leave me in awe. One such feature is the ability to squash commits. In this blog post, I will provide you with an overview of squashing commits and how it can simplify your Git workflow. For most of my personal projects, where I am the sole developer, I prefer working directly on the master branch....

Start Your Journey: Embracing Consistency and Passion

In a world where a hundred people consume for every person who creates, it’s easy to feel overwhelmed or discouraged. However, it’s important to remember that these statistics are not set in stone and can vary depending on the niche or field you’re interested in. For example, becoming a successful YouTuber might require a more significant investment of time and effort, with only a small percentage succeeding consistently. But how does one become a YouTuber or excel in any endeavor?...

Stay Focused: The Pitfalls of Language Hopping in Coding

In today’s blog, we will address a common issue that aspiring coders often face: the temptation to switch languages too frequently while learning to code. I have received numerous emails from individuals who have encountered this problem, so let’s take a closer look. Imagine starting your coding journey with Python, only to become discouraged after some time and lose momentum. Consequently, you decide to switch to JavaScript. However, you soon confront a roadblock in your JavaScript learning journey....