The default color of the bars created by using ggplot2 package is grey but we can change that color to any depending on our interest. This change is highly required in professions such as academic writing and analytics because everyone wants to look at attractive images. They are not meant to be useful if you just want to learn the concept but when it comes to practical, you need to do it as attractive images gets more attention, thus, they become memorable. To change the color of the bars in ggplot2, we can use fill argument of geom_bar function.ExampleConsider the ... Read More
Bats are mammals which use sound ways to locate their prey. They do so by a scientific technique called 'Echolocation'. This is because they are nocturnal mammals that have weak eyesight. They use their ears more than any other mammal.EcholocationIt is defined as the use of sound waves and echoes to determine the location of objects in space. Bats use this mechanism for finding their food. Just as SONAR (Sound Navigation and Ranging) is used in case of big ships, and tanks, similarly, the emission of sound waves helps bat catch its prey.Bats use ultrasonic waves (20 to 200 kilohertz) ... Read More
In this article we will see how to make a server and client chat room system using Socket Programming with Python.The sockets are the endpoints of any communication channel. These are used to connect the server and client. Sockets are Bi-Directional. In this area, we will setup sockets for each end and setup the chatroom system among different clients through the server. The server side has some ports to connect with client sockets. When a client tries to connect with the same port, then the connection will be established for the chat room.There are basically two parts. The server side ... Read More
To search for the word in PowerShell and replace it in the file we will use the string operation. In fact, the Get-Content command in PowerShell is used to read almost any type of file content. In this article, we are considering one text file as shown below.Get-Content C:\Temp\TestFile.txtOutputPS C:\> Get-Content C:\Temp\TestFile.txt # In case of linux, networkInterface names are of the form eth* # In Windows, please use the network full name from Device Manager networkInterfaces: ["Microsoft Hyper-V Network Adapter" ] overrideMetricsUsingScriptFile: false scriptTimeoutInSec: 60 scriptFiles: - osType: windows filePath: monitors/NetworkMonitor/scripts/windows-metrics.bat - osType: unixBase filePath: monitors/NetworkMonitor/scripts/unix-base-metrics.shThe ... Read More
As we know $ErrorActionPreference and $ErrorAction both have the same functionality and both are used to handle terminating errors by converting Non-Terminating errors to Terminating errors. But when both the variables are used, we need to know which takes precedence.$ErrorActionPreference variable is used at the start of the script while the $erroraction variable is a common parameter and used with the cmdlet. In some cases, we might need the script to be terminated as soon as an error occurs but inside the script, we have some cmdlets which need to be ignored or continued if the error occurs. In that ... Read More
Scriptblock is a set of commands which can be executed together when they are invoked. In PowerShell, generally, we write individual commands. Scriptblock can be written with two curly brackets.Example$sb = {Get-Process powershell; Get-Service W32Time}Here we have written two commands under scriptblock. If you directly run this command, scriptblock treats them as a string.PS C:\> $sb Get-Process powershell; Get-Service W32TimeTo run the commands inside the scritblock, use Invoke-Command with the -Scriptblock parameter.Invoke-Command -ScriptBlock $sbOutputHandles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName ------- ------ ----- ----- ------ -- -- ... Read More
To copy files/folders on the remote path without overwriting the existing files/folders, you can use multiple cmdlets like Copy-Item, Robocoy, and Xcopy, etc. As Copy-Item is a standard cmdlet, we will check if it's supported parameters can prevent overwriting.If Copy-Item doesn’t work then we will check its alternate command. Copy-Item simply overwrites the files and folders on the destination path and the copies newer files.For example, To copy files from the source folder C:\Test1 to the destination folder C:\Test2 below command is used and it simply overwrites the file without asking.ExampleCopy-Item C:\Test1\* C:\Test2 -Recurse -VerboseOutputPS C:\Temp> Copy-Item C:\Test1\* C:\Test2 -Recurse ... Read More
To run commands in the background in the PowerShell, you need to use Background job cmdlets. Background job means running commands/job in the background without occupying the console.Start-Job is one of the job scheduler cmdlets for PowerShell which runs PowerShell commands in the background without interacting with the current user session as a Job so that users can work in the PowerShell console without losing the control of the console while the command is running in the background.When PowerShell's job starts using Start-Job, a job returns the object immediately even if the job takes an extended time.Start-Job is designed to ... Read More
The includes() check whether array has a specific element, whereas splice() is used to add/remove items. Following is the code −ExampledeleteElementsFromArray = function(elements, ...values) { let elementRemoved = Array.from(values); for (var index = 0; index < elements.length; index++){ if (elementRemoved.includes(elements[index])){ elements.splice(index, 1); index--; } } return elements; } console.log(deleteElementsFromArray([80,90,56,34,79], 90, 34,79));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo69.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo69.js [ 80, 56 ]
You can use a for loop and check whether the percentage is greater than 70 or not with if condition.Following are the records of each student −const studentDetails= [ { studentName:"John", percentage:78 }, { studentName:"Sam", percentage:68 }, { studentName:"Mike", percentage:88 }, { studentName:"Bob", percentage:70 } ]Now, use the for loop and et conditions for students with percentage more than 70 −for(var index=0;index 70) { ... Read More