Dynamically Select a Method of an Object in JavaScript

Learn how to dynamically access a method of an object in JavaScript and improve code flexibility. Sometimes, you may encounter a situation where you have an object and need to call different methods based on certain conditions. For instance, you might have a car object and want to either drive() or park() it based on the driver.sleepy value. Traditionally, you can achieve this using an if/else condition: if (driver.sleepy > 6) { car....

Easy Ways to Set Up Automations in macOS

When working on a website or any project involving data storage, it’s important to have automated backup systems in place. In this blog, we will explore an easy way to set up automations in macOS using built-in tools. One of the simplest ways to achieve automated backups is by utilizing the power of Automator, an often underappreciated app on the Mac. Automator allows you to create custom actions and workflows to automate repetitive tasks....

Efficient Searching with Quicksort in JavaScript

Quicksort is a highly efficient algorithm for searching and sorting arrays in JavaScript. It makes use of recursion, which involves calling a function from within the same function. This technique helps streamline the search process and improve performance. Generally, Quicksort outperforms other algorithms like selection sort, especially in scenarios where the data set is large. The algorithm’s time complexity is generally O(n log n), which falls between O(n) and O(n^2). However, it’s worth noting that in the worst-case scenario, Quicksort can take the same time as selection sort, resulting in a time complexity of O(n^2)....

Efficiently load JavaScript with defer and async

When loading a script on an HTML page, it’s important to consider its impact on the loading performance. The position and method of adding scripts to an HTML page can greatly influence the loading time. Traditionally, scripts are included in the page using the following syntax: <script src="script.js"></script> When the HTML parser encounters this line, it fetches the script and executes it. This process introduces delay, which can negatively affect the loading time of the page....

Electronic Components: Buttons - An Essential Component for Circuitry

Buttons are a crucial electronic component that facilitates the connection between two parts of a circuit when pressed. Once the button is released, the circuit is opened, preventing the flow of current. This article will explore the functionality and implementation of buttons in electronic circuits. Buttons generally have two sets of connections that can be closed simultaneously. These connections are located on the curved pins of the button. When incorporating a button into a breadboard, it is typically placed in the middle section....

Electronic Components: Buzzers

Buzzers are electronic components that are used to generate sound. In this blog, we will explore the different types of buzzers and their functionalities. Active Buzzers Active buzzers are a type of buzzer that have additional logic compared to passive buzzers. They require a direct current (DC) connection and are more expensive than passive buzzers. To generate sound with an active buzzer, you need to connect a 0V wire and a signal wire, alternately switching between high and low voltage levels at different frequencies based on the desired sound....

Electronic Components: LEDs

Light Emitting Diodes (LEDs) are essential electronic components for various applications and prototypes. They are easy to use and perfect for exploring different concepts. In this blog post, we will focus on 5mm LEDs commonly used for prototyping. An LED has two leads: the anode and the cathode. The anode is usually longer than the cathode. It is crucial to connect the anode to the positive lead (+) and the cathode to the negative lead (-) correctly to ensure the LED functions properly....

Electronic Components: Resistors

A resistor is an essential electronic component that is designed to impede the flow of electrical current within a circuit. There exists a wide variety of resistors available, constructed using different materials and offering varying levels of resistance. In my collection, I currently possess the following resistors: 10Ω 220Ω 330Ω 1kΩ 2kΩ 5kΩ 10kΩ 100kΩ 1MΩ Each resistor value is distinctly represented by a unique color combination, aiding in easy identification....

Electronic Components: Servo Motors

Servo motors are programmable motors that have the ability to rotate to positions spanning over 180 degrees. These motors are commonly used in various applications that require movement and come in different sizes. For Arduino and battery-powered applications, the micro servo or RC servo is often used. Examples include the SG90 and the MG90S. Both of these servos function in the same manner. A mechanical arm can utilize multiple MG90S servos, as shown in the image below:...

Electronic Components: Understanding the 1602 LCD Display

The 1602 LCD display is a widely used alphanumeric display that consists of two lines, each capable of displaying 16 characters. Its versatility makes it suitable for various applications, including vending machines and train stations. While it is commonly included in Arduino kits, the instructions provided here can be applied to any LCD display that has a 16-pin interface compatible with the Hitachi HD44780 LCD controller. To control the display, the LiquidCrystal Arduino library emulates the Hitachi HD44780 LCD controller....