Home Blog Page 85

How to Build a File Upload Component with Angular Material?

File Upload Component

Whether it’s uploading documents, images, or videos, a file upload component can significantly enhance the user experience by allowing users to share files with others easily. 

One popular UI library for Angular projects is Angular Material, which provides several useful components and tools, including the Angular Material file upload component. This upload component allows intuitive file uploads in Angular projects with a sleek user interface.

Angular Material is a collection of UI components that follows the material design guidelines. It provides a set of pre-designed and customizable UI components that you can easily integrate into an Angular application.

In this article, we will explore the steps for building a file upload component using Angular Material, starting from setting up the environment and ending with creating the component itself. 

We’ll also examine how to customize your components’ interface and user experience.

Setting Up the Project

Before building our file upload component, we must set up a new Angular project and install Angular Material. If you already have the Angular CLI installed, you can create a new project using this command:

ng new my-project

Next, we need to install the Angular Material package. We can do this by running the following command:

ng add @angular/material

This command will install the necessary packages and add the required configuration to your project. You have successfully set up the project and are ready to create the file upload document.

Developing the File Upload Document

Now that we have our project set up, we can start building our file upload component. You can develop the file upload document by following these steps:

1. Install the Angular Material Package

In the terminal, run the following command to install the Angular Material package:

npm install -save @angular/material @angular/cdk 

@angular/animations 

2. Import the Angular Material Modules

In the Angular app module file, import the Angular Material modules you will use in your app. Here is an example of code you could use:

import { MatButtonModule } from ‘@angular/material/button’;

import { MatlnputModule } from ‘@angular/material/input’; 

@NgModule({ imports: [ 

MatButtonModule, 

MatlnputModule, 

// other imported modules]

 // other module properties

})

 export class AppModule { } 

3. Create a File Input Form Element

Create a file input form element in your HTML template that will allow users to select a file to upload.

You can use the mat-form-field and mat-input components from Angular Material to style the file input element.

<form> 

<mat-form-field> 

<mat-label>File</mat-label>

 <input -tInput type=”file” (change)=”onFileSelected($event)” I> 

</mat-form-field> 

</form> 

4. Handle the File Selection Event

When uploading files with Angular Material, it is important to know about the file selection event to handle the selected files and correctly perform any necessary actions. Here is one way of doing it:

onFileSelected(event) {

this.selectedFile = event.target.files[0];

5. Create a File Upload Button

In your HTML template, create a button that will trigger the file upload process when clicked. You can use the mat-button component from Angular Material to style the button.

<button mat-button (click) = “uploadFile() “>Upload</button>

6. Implement the File Upload Logic

Create a method for handling the file upload process in your component class. This method should use the Angular HttpClient service to send a POST request to the server with the selected file attached.

uploadFile() 

{const fd = new FormData();

fd.append(‘file’, this.selectedFile, this.selectedFile.name); 

this.http.post(‘/server/upload’, fd).subscribe(res => { 

console.log(res);

}); 

7. Display a Progress Bar

If you want to show the progress of the file upload, you can use the mat-progress-bar component from Angular Material to display a progress bar. In your component class, you can bind the value of the progress bar to a component property representing the upload progress.

<mat-progress-bar [value] = “uploadProgress”></mat-progress-bar>

Error Handling with Angular Material

Error handling is an important part of any software development process, and it’s especially crucial when creating a file upload component. Allowing users to upload files into an application can be a complex task, and mistakes in the code can lead to errors that could prevent successful uploads. 

Fortunately, Angular Material provides developers powerful error-handling tools to create reliable file upload components. It offers several features that make error handling easier. 

For instance, the Angular Material library has robust form state management, allowing developers to easily track each field’s validity status and display appropriate messages when errors occur. 

Additionally, developers can use the extensive input validation options available within Angular Material to ensure their application accepts only valid data. Together, these tools allow developers to easily create file upload components that are both robust and highly customizable.  

Best Practices When Using Angular Material for Error-handling

Error-handling

Here are five steps to follow when using Angular Material for error handling:

1. Validation Rules

Set up validation rules to ensure data integrity and accuracy when users submit information. 

Plus, use the Angular Material Dialog component to provide helpful feedback to users when input errors occur. It creates a better user experience by providing visual cues and clear instructions on solving the problem.

2. Reactive Forms

Use the Reactive Forms module in Angular Material to enable form-level validation and apply custom validators as required. It ensures that all form elements adhere to specific criteria before being submitted by users.

3. Use Mat-Error Directive

Use the Mat-error Directive from Angular Material to display validation messages for both individual fields and entire forms if needed. It prevents users from submitting a form in error, creating a better user experience.

4. Remove Errors From the Screen

Ensure that errors are removed from the screen once the user has corrected them. When submitting a form, you should use the Angular ngModel Directive and its Error Object to display validation messages for individual fields onscreen.

5. Use the Angular ngModelGroup Directive

Use the Angular ngModelGroup Directive to group form fields, making displaying validation messages for entire form sections easier. Then, utilize the Angular ngMessages Directive to display messages for the entire form if necessary.

The Takeaway

Building a file upload component with Angular Material is an excellent way for users to upload files in your web application easily. With just a few steps, you can create an intuitive and accessible user interface for uploading files. 

You can quickly set up this feature with minimal coding using Angular Material components like the File Input, Button, and Progress Bar. These features will make your web application more attractive and user-friendly. 

Furthermore, you can use other features from the Angular Material library, like custom themes and animations, to improve the look of the file upload component even further. With all of these options available, creating an intuitive, user-friendly file upload feature for any web application using Angular Material is easy.

Qualcomm’s Snapdragon 7+ Gen 2 Outperforms Flagship Chips in Benchmark Tests

Snapdragon 7 Plus Gen 2 Benchmark Test

Qualcomm’s latest Snapdragon 7+ Gen 2 has debuted with a significant performance boost over its predecessor, but it seems to have outperformed even the flagship chips. 

According to benchmark tests conducted by members of the Android Authority, the Snapdragon 7+ Gen 2 managed to outperform other high-end chips, such as Tensor G2, Snapdragon 8 Gen 1, and Exynos 2200 in multi-core tests.

The Snapdragon 7+ Gen 2 was tested against various smartphones such as the Galaxy S22 Ultra (both Snapdragon and Exynos variants), Galaxy S23 Ultra, OnePlus 11, Pixel 7 Pro, Asus ROG Phone 6, and Nothing Phone (1). The tests revealed that the Snapdragon 7+ Gen 2 beat its competitors in both single-core and multi-core tests, except for the Snapdragon 8 Gen 2, which performed comparably to the Snapdragon 8 Gen 1.

Regarding GPU performance, the Snapdragon 7+ Gen 2 was not as impressive as its CPU performance but still beat the Exynos 2200, Tensor G2, and Snapdragon 778G Plus.

One of the most intriguing findings came from the 3DMark Wild Life stress test, where the Snapdragon 7+ Gen 2 showed something unique, maintaining a consistent performance throughout the test. In comparison, the Galaxy S23 Ultra’s Snapdragon 8 Gen 2 started to decline from 14,000, dropped to 9,000, and then stabilized. The Asus ROG Phone 6 also started dropping from 10,000, dropped to 5,000, and kept declining. The Galaxy S22 Ultra also dropped from 10,000 and maintained its performance at 5,000. However, the Snapdragon 7+ Gen 2 remained above 7,000 at the test’s beginning and end.

While the ability to maintain stable performance is impressive, the Snapdragon 7+ Gen 2 is expected to perform well in power consumption, making it an excellent option for many mid-range smartphones. However, for most users, it may be over-specified.

In conclusion, Qualcomm’s Snapdragon 7+ Gen 2 has impressive performance in benchmark tests, outperforming even the flagship chips. This chip’s excellent performance and power efficiency make it a desirable choice for many mid-range smartphones. With the Snapdragon 7+ Gen 2, Qualcomm has set a new standard for mobile processors.

Elon Musk Announces Twitter’s Recommendation Algorithm Will Be Open-Sourced On March 31st

Elon Musk Joins Twitter Board Of Directors

In a surprise move, Elon Musk, owner and CEO of Twitter, announced that the social media platform would open-source its recommendation algorithm on March 31st. Twitter algorithms have always been kept as closely guarded trade secrets, so this move is unprecedented.

Musk stated that their algorithms are complex and not fully understood internally. The decision to release the recommendation display algorithm can be seen as a move to compensate for the decline in development capabilities due to the reduction in the workforce. Still, it aligns with Musk’s promise to release it publicly. He believes that providing code transparency will lead to rapid quality recommendations and, most importantly, earn the trust of Twitter users.

Twitter’s algorithms link users to other users, groups, artists, events, or posts they may know, as well as other relevant content customized to them. However, critics argue that these algorithms can favour certain ideologies and perspectives at the expense of others.

The decision to open-source Twitter’s recommendation algorithm is a bold move that could set a precedent for other social media companies. It will be interesting to see how this move affects how users interact with Twitter and whether it leads to a more transparent and trustworthy social media platform.

Microsoft Plans to Build Cryptocurrency Wallet into Edge Browser

Cryptocurrency Wallet into Edge Browser

Microsoft has been testing a new feature that might revolutionise the world of bitcoin and NFTs. According to screenshots published on Twitter by @thebookisclosed, Microsoft is working on a bitcoin wallet that will be incorporated into the Edge browser. 

According to the images, the wallet function would allow users to manage their cryptocurrencies and NFTs easily and securely without relying on a third party to hold their private keys and passwords.

https://twitter.com/thebookisclosed/status/1636759487829917698

The cryptocurrency wallet in the Edge browser will allow users to engage with Web3 without needing third-party add-ons. This implies that consumers may safely keep their digital assets without fear of compromised security.

The wallet feature will display users’ current balances and assets, transaction history, linked applications, watchlists, and dedicated tabs for exploring the world of Web3, crypto, and NFTs. The wallet looks to include interfaces with Coinbase and MoonPay, allowing users to purchase cryptocurrencies and transfer payments to others.

It is important to note that Microsoft has yet to disclose its plans to enter the cryptocurrency market. The corporation is still experimenting with various concepts, many of which may never see the light of day. The project is clearly labelled as confidential. 

Microsoft did not supply any crypto or NFTs to test participants as part of the feature experiment, and there was no refund for lost funds. As a result, anyone accessing the crypto wallet in the Edge browser should proceed at their own risk.

Microsoft’s decision to build a cryptocurrency wallet integrated into the Edge browser might be a game changer in digital assets. If it is good, it might make handling cryptocurrencies and NFTs easier for more people, making the technology more accessible and safer. But until Microsoft makes an official announcement, we should regard this initiative as an experiment and act cautiously.

Gboard hidden features: 10 tricks and tips to help you master Gboard for Android

Gboard hidden features

Without a doubt, we all can agree that Google keyboard or Gboard is the most powerful and best keyboard app available today for Android. In this article, we gonna list some of the best lesser-known Gboard hidden features and tricks for Android you should start to use right now to master on this awesome keyboard.

Nevertheless, which keyboard we are using we can’t deny Gboard for Android is one of its kind – with its glide typing and integrated Google search, Gboard rules over other so-called modern keyboards.

If you are still not a Gboard user, head on to Google Play and install the app. Although Gboard for iOS is still lacking behind many features compared to its Android version, so most of these listed Gboard hidden features are only available for Android users.

Gboard hidden features:

1. Built-in Google search

Let’s start with the integration of Google Search itself with the Gboard keyboard, one of the unique feature none other keyboard apps had. Just tap on the “ G ” button on the top right corner and type in your search keyword. And with just tapping the result, you could share it with others easily. So now onwards use this Gboard Google Search feature to look up things quickly without leaving your chat window.

Built-in Google search

2. Integrated with Google Translate

How about sending a message to your Chinese friend without knowing a single letter in Chinese. With integrated Google Translator on Gboard now it’s possible to send somebody a message in their native language. You just have to tap the “G” button and choose the Google Translate tool. From there, choose the input and output languages, then whatever you type will automatically be interpreted.

 Integrated with Google Translate

3. Say it – Gboard types it

Integrated with Google’s smart voice recognition technology in Gboard, now it’s easy to type long messages without using a keyboard. Just tap the microphone icon in the top-right corner to activate the mic and then dictate what you want to type.

Say it - Gboard types it

4. Add more languages

Now you need no new keyboard app to type messages in your native language. Gboard offers almost all popular regional languages and national languages. You simply have to go to Gboard Settings > Languages > Add Keyboard to include your favorite language to the list. After adding, next time when you open Gboard, simply hold on the spacebar button to choose between the language you need to type.

 Add more languages

5. Hidden punctuation quick access

We normally tap on ”?123” to access punctuations and special characters in the keyboard, but what if I say you can access major punctuations a little bit faster. Just long-press the period button to pop up the hidden punctuation quick access menu, where you just slide your finger to choose the one you needed.

Hidden punctuation quick access

6. Hidden fractions

Most of the keyboard out there doesn’t have some important character set, one such example – fractions – even though if they provided it there is no easy way for a general Android user to find it or know how to use. But with Google Gboard, users only have to long press any number in the keyboard to get the list of common fractions that use the long-pressed number as a numerator.

Hidden fractions

7. Now selecting text is handier

Sometimes it makes us mad to select a particular sentence or word from the middle of a long message. Gboard has an inbuilt tool for you to make your text selecting and copy process easier. Tap on “G” icon and choose additional options to get “Text Editing”. With this option, you easily maneuver cursor around a long written article just with the directional keys and copy/paste words in it.

Now selecting text is handier

8. Use Spacebar as a trackpad

Sometimes it really difficult to pinpoint typing cursor exactly on the place where we forgot a letter or misspelled a word — some people even clear the whole words after the error just to correct the misspelled. But with Gboard it’s easy to move your cursor around the words. Just swipe your finger across the spacebar to move the cursor, just like a laptop mouse — swipe left or right to move cursor location to that respective direction.

Use Spacebar as a trackpad

9. One hand mode makes typing easy

If you using a 5.5 inch+ phone, then it is a really clumsy process or maybe almost difficult to type in with just one hand. But this Gboard hidden feature has provided a solution for this, go to additional options and choose “One-handed” to activate the one-hand mode. In one-hand mode, you can readjust the position of the keyboard according to your comfort. So next time, typing with one hand on a big screened phone is a piece of cake.

One hand mode makes typing easy

10. Tweak the Gboard appearance

Unlike other keyboards, Gboard offers pretty good and simple themes for users. Also, it offers a custom theme option where users can use their images from the gallery as a keyboard background.

Tweak the Gboard appearance

All these features are there on Gboard but somehow people fail to utilize the full potential of this keyboard app, thus makes them Gboard hidden features. Next time use them and experience the real power on Gboard.

A Critical Vulnerability Discovered in Microsoft Outlook

Microsoft Outlook Vulnerability

A recent cybersecurity threat has put millions of organizations at risk due to a critical Microsoft Outlook for Windows vulnerability. This vulnerability, CVE-2023-23397, allows hackers to steal hashed passwords by emailing remotely. This puts businesses in danger of having their sensitive data and systems compromised, leading to financial loss, reputational damage, and legal liabilities.

In response to this threat, Microsoft has released a PowerShell script that administrators can use to check if any users in their Exchange environment have been affected by this Outlook vulnerability. This script can help identify malicious items and allow administrators to purge or permanently delete them. The script can also modify or remove potentially harmful messages on a trusted Exchange server.

However, this vulnerability is not easy to detect, and even with the PowerShell script, organizations are still at risk. Dominic Chell, a red team member at MDSec, discovered that it’s easy for hackers to exploit this bug and steal NTLM hashes using a calendar in Microsoft Outlook. Chell found that by using the “PidLidReminderFileParameter” property within received mail items, a hacker can add a UNC path to trigger NTLM authentication and steal the NTLM hashes.

The stolen NTLM hashes can then be used to perform NTLM Relay attacks, giving hackers access to corporate networks. Attackers can also collect hashes and authenticate against an IP address outside the trusted intranet zone or sites using Microsoft Outlook tasks, notes, or emails.

To protect your organization from this threat, it’s crucial to immediately apply the released fix for the vulnerability, add users to the Protected Users group in Active Directory, and block outbound SMB (TCP port 445) as a temporary measure to minimize the impact of the attacks.

Organizations should also educate employees on identifying phishing emails and other suspicious messages. This includes looking out for strange links, attachments, or requests for sensitive information. Ensuring that all software and systems are updated regularly with the latest security patches is essential.

Organizations need to take proactive steps to protect themselves from this threat, including implementing the recommended solutions from Microsoft and educating their employees. Companies may avoid becoming victims of this vulnerability and secure their sensitive data and systems by remaining watchful and adopting the required steps.

Move All Negative Elements to One Side of an Array-C

Array-C

Transitioning and playing with numbers is one of the most fascinating aspects of compiling array data structures. On that note, did you know that arrays can be used for storing infinite natural numbers and digits that have been discovered till date?

One such number component that we are going to be discussing in this blog are integers. Integers are numbers that can be positive, negative and even zero. 

In this array problem, we are going to be discussing how to move all negative elements to the end or the beginning of an array by using simple approaches and algorithms.

Keep in mind that the order of the elements is not relevant for this problem. We are only considering the negative elements and placing them at either the beginning or the end of the list.

What are the methods to move all negative elements to one side of an Array?

The arrays in programming are one of the most versatile data structures. This is due to the fact that, from numbers to integers, the arrays facilitate storing infinite positive, negative, and even zero value integers as well. Also, these elements within the array might be stored in random positions irrespective of their general sequence.

There are plenty of algorithms and methods that exist to help in sorting and moving these elements within the arrays. Hence, we can say that this is a form of sorting that is performed on the array as per the requirements of the program.

This problem is often asked in programming interviews. In the following section of the blog, we will discuss these approaches to move all negative elements to end of an array.

How to move all elements to one side in an Array using C? 

In order to learn how to move all negative elements to the end of an array, we will consider this problem with the help of an example. Here we have an input array that consists of negative as well as positive integers. 

Let us discuss the approaches and methods to move the negative elements towards one side of the array further in this section.

Input Array

1 -2 3 -1 8 9

Output Array

1 9 3 8 -2 -1

As we can see in the output of the array, the negative elements have been arranged at the end of the sequence.

Keep in mind that the arrangement of these elements do not have to be in a perfect order. They can be aligned in a random order as long as we move all negative elements to end within the program.

Now, let us discuss the different approaches that can be applied for shifting all the negative elements by the end of the array.

Method 1: Using the Naive Approach

We will start by attempting to solve this problem using the naive approach. This method is also commonly referred to as the recursive algorithm that is used for solving various other programming problems as well such as performing a zigzag traversal of Binary Tree.

  • In the context of moving all the negative elements to the end of an array, we can start by sorting the given array in a descending order 
  • This way, all the negative elements will get piled up at the end of the array
  • For achieving this we can implement the selection sort function i.e selection sort(int arr[], int n)
  • In this function, for each of the ith element within the array, we will try to figure out the minimum element within the subarray from i+1 and try to swap their values to sort the array at the end

Time Complexity for this approach:

O(n*log(n))

Method 2: Using Partition Approach

Now we are moving towards more efficient and convenient approaches. For this method, we will be using the nested loops for performing only a single traversal through the entire array.

A simple method to use the partition approach is to implement the nested loop for the entire length of the array and this loop will help us in detecting the negative integers that need to be moved to the end.

Here’s how this approach can be implemented:

  • You can start by declaring a variable such as j=0 at the starting of the array for arr[j]
  • Next up, we will iterate through the entire data using the i pointer of the loop
  • Now, at each step of the iteration, we will keep a tab of the fact whether arr[i] is negative or not
  • If it is found to be true, we will simply swap the element with arr[j] and place it at the beginning of our input array
  • Finally, you can increment the element j and its value and carry this process forward for the remaining elements of the array

Time Complexity for this approach:

O(n) 

Here we have considered “n” to be length of our input array

Method 3: Using the Variables or Pointers technique

As you might have already guessed, in order to move all negative elements to the end, as our third approach, we will initialise two variables or pointers “m” and “n” at the start and end positions of the input array.

By using this technique, we will keep a track of all the elements within the array and consecutively increment the m pointer and decrement the n pointer.

Here’s how the algorithm for this approach would work:

  • If both the m and n pointers point are pointing to negative elements, then increment the element’s value to m
  • If the value of pointer m has a positive number and pointer n has a negative number then swap both of their values
  • In case, both of the pointers are indicating to a positive integer, then decrement the pointer n
  • And finally, if m points towards a negative element while n points to positive, then increment m and decrement n

Final Thoughts 

There are a wide range of array based problems that can be solved using Pointers and the Naive Approach such as performing zigzag traversal of Binary Tree.

These approaches offer their own set of classes and functions that can be effectively used for reducing the time complexity of the problem.

Brave Adds Firewall + VPN Function To The Desktop Version

Brave Adds Firewall and VPN

The Brave browser, known for its privacy-focused features, has recently added a Firewall + VPN function to its desktop version. The browser’s latest version, 1.49, now provides a VPN service across all platforms, including Android, iOS, and desktop, making it cross-platform. Customers who purchase a desktop VPN subscription can use it on up to five devices, regardless of platform.

When a VPN is active, it provides numerous features that improve users’ privacy and security. It hides their IP address, alters their online location, safeguards their internet activity with apps other than Brave Browser, and stops ISPs from eavesdropping on their activities. When you use a firewall and VPN on your phone, trackers are blocked in all apps, not just the Brave browser.

The Firewall + VPN service costs $9.99 monthly, with a $99.99 annual option coming to the desktop soon. If you have five devices connected to the VPN, the cost per device is around $2 per month. This makes it a cost-effective choice for people who wish to secure internet traffic across several devices. Those with a mobile subscription may connect their browser by enabling the option and connecting their device to the account.brave.com website, which will display automatically.

Brave also unveiled a new feature called Summarizer earlier this month, which uses artificial intelligence to provide short summaries of what users are searching for from numerous sources. AI-generated solutions are displayed directly above online search results and indicate the text’s source. This feature allows visitors to rapidly find the information they want without browsing many articles.

Including the Firewall + VPN capability in the desktop version of the Brave browser is a significant step in the browser’s evolution into a comprehensive privacy-focused platform. Brave is making it easy for individuals to be safe and secure online with its low prices and ability to safeguard users’ internet traffic on all devices, regardless of platform. These advances position Brave as a formidable competitor in the privacy-focused browser market.