Server Side Programming Articles

Page 1913 of 2109

Empty Slice vs. Nil Slice in Golang

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 01-Nov-2021 1K+ Views

In this article, we will see the differences and similarities that are there between a slice that is declared as an empty and a nil slice.Slices in Golang are used to store a sequence of elements. Slices can be expanded at any time and they are declared in the same way as an array, but without their capacity defined.Nil SliceA nil slice is a slice in which while declaring, we simply define the name and the data type and not make use of the built-in make function.A nil slice is a slice that has nil as its zero value and ...

Read More

Functions vs Methods in Golang

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 01-Nov-2021 6K+ Views

In this article, we will learn what similarities and differences are there between functions and methods in Golang. We will start with each of them separately, and then we will see an example where both of them will be used.Let's start with functions and see what they are and how to use them in Golang.Functions in GolangFunctions in Golang are a block of code that take a few parameters as input and produce some output. If we pass in the same input to a function, it will produce the same output as always.Example 1In this example, we are creating a ...

Read More

Find the column index of least value for each row of an R matrix

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 01-Nov-2021 619 Views

To find the column index of least value for each row in an R matrix, we can use apply function.For Example, if we have a matrix called M then we can find column that has the least value for each row by using the command as follows −apply(M,1,which.min)Example 1Consider the matrix given below −M1

Read More

Channel synchronization in Golang

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 01-Nov-2021 1K+ Views

We can make use of channels if we want to synchronize goroutines. By synchronizing, we want to make the goroutines work in a defined manner, for example, not starting the next goroutine until the previous one has finished its execution.The channels help in achieving that, as they can be used to block the process and then can also be used to notify the second goroutine that the previous goroutine has finished its job.Example 1Let's consider a very basic example of channel synchronization where we will see how we can achieve it with the help of a buffered channel.Consider the code ...

Read More

How to get the Response status code in Golang?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 01-Nov-2021 14K+ Views

Response status codes are the numbers that we get in response that signify what type of response we received from the server when we asked for something from it.There are different status codes that one gets from the response, and these are mainly divided into five categories.Generally, the status codes are divided into these five classes.1xx (Informational)2xx (Successful)3xx (Redirection)4xx (Client Error)5xx (Server Error)In this article, we will try to get two or more of these status codes.Example 1Let's start with a basic HTTP request to the google.com URL. Once we do that, we will get the response from the server ...

Read More

How to convert days in a week to number in R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 01-Nov-2021 1K+ Views

To convert days in a week to number in R data frame column, we would need to convert the column into a factor by defining the weekdays as the levels and then read that column as integer.If we provide the correct sequence of weekdays during conversion then Monday will be converted to 1. Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −Week_Days

Read More

How to detect the content type of a file in Golang?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 01-Nov-2021 7K+ Views

Consider a case where we want to get the content type of a file in Golang for whatever reasons. In order to do that, we must first know how to open the file and read some of its bytes into a buffer slice which we will then pass to a function that will help us in detecting the type of the file.The first step is to open the file whose type we want to check.Open the FileConsider that we have a file named sample.pdf whose contentType is what we want to know. In order to open the file, we need ...

Read More

How to create transparent boxplot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 01-Nov-2021 1K+ Views

Be default, the boxplot created in base R or by using ggplot2 are not transparent in nature. If we want to create a transparent boxplot then we can use bwplot function from lattice package.For Example, if we have a vector called X then we can create transparent boxplot of X by using the below command −bwplot(x)Example 1To create transparent boxplot use the snippet given below −library(lattice) bwplot(rnorm(1000))OutputIf you execute the above given snippet, it generates the following Output −Example 2To create transparent boxplot add the following code to the above snippet −library(lattice) bwplot(rpois(1000, 5))OutputIf you execute all the above given ...

Read More

How to decode JSON into objects in Golang?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 01-Nov-2021 1K+ Views

Suppose we have a JSON that looks like this.{ "name":"Mukul Latiyan", "age":10, "sports":[ "football", "tennis", "cricket" ] }Now, we want to convert this JSON into struct fields which we can access later and maybe iterate over too.In order to do that, we need to first make a struct that will satisfy the fields of the above JSON.The struct shown below will work just fine for the above JSON.type Person struct ...

Read More

Find the column name with the largest value for each row in an R data frame.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 01-Nov-2021 4K+ Views

To find the column name that has the largest value for each row in an R data frame, we can use colnames function along with apply function.For Example, if we have a data frame called df then we can find column name that has the largest value for each row by using the command as follows −df$Largest_Column

Read More
Showing 19121–19130 of 21,090 articles
Advertisements