All Go Rust Python PHP JavaScript
Chrome Dev Summit to secure your spot in workshops, office hours and learning lounges!

How to Use Deferred Function Calls in Golang

Understanding defer in Go. Deferred Function Calls A defer statement is an ordinary function or method call prefixed by the keyword defer. The function and argument expressions are evaluated when the statement is executed, but the actual call is def...
ada

How to Get the Full URL in PHP

In PHP, using the $_SERVER variable is the easiest way to get the full URL. Using $_SERVER Variable $_SERVER is an array containing information such as headers, paths, and script locations. The following example should cover whatever you are trying...
url
Sambhav Khandelwal

How to Get the System Hostname in Python

In Python, there are 3 ways to get the system hostname. Using gethostname Method The socket.gethostname() method returns a string containing the hostname of the machine where the Python interpreter is currently executing. For example, #!/usr/bin...
Tomoki

How to Reverse a String in Rust

In Rust, there are 2 ways to reverse a string. Using rev Function The str::rev() function reverses an iterator’s direction. See the following example: fn main() { let mut s = "Hello"; println!("{}", s.chars().rev().collect::<String>());...
pooriabt

How to Get the String Length in Characters in Rust

In Rust, there are 2 ways to get the string length in characters. Using chars Function The str::chars() function returns an iterator over the chars of a string slice. See the following example: fn main() { let mut s = "Hello"; println!("{}...
Tomoki

How to Make First Letter of Words Uppercase in a String in Go

In Golang, using the cases package is the easiest way to make first letter of words uppercase in a string. Using cases Package install Use the following command to download the repository to the local file system. install go mod tidy ...
pooriabt

How to Iterate through the Values of an Enum in Rust

In Rust, there are 2 ways to iterate through the values of an enum. Using a static array If the enum is C-like, then you can create a static array of each of the variants and return an iterator of references to them: use self::Direction::*; use...
pooriabt

How to Iterate Over a String by Character in Rust

In Rust, there are 3 ways to iterate over a string by character. Using chars Method The chars() method returns an iterator over the chars of a string slice. See the following example: fn main() { let s = "abc"; for c in s.chars() { pr...
pooriabt

How to Generate a UUID in Go

In Golang, there are 4 ways to generate a uuid. Using uuid Package install Use the following command to download the repository to the local file system. install go mod tidy go get github.com/google/uuid go install github.com...
Sambhav Khandelwal

How to List all Standard Packages in Go

In Golang, there are 2 ways to list all standard packages. Using packages go install Use the following command to download the repository to the local file system. install go get golang.org/x/tools/go/packages go install golang.or...
aweis

How to Access Command Line Parameters in Rust

In Rust, there are 2 ways to access command line parameters. Using std::env::args Function This function actually returns the arguments that this program was started with. See the following example: use std::env; fn main() { for arg in env::...
Patcher56

How to Remove Packages Installed with go get in Go

In Golang, there are 3 ways to remove packages installed with go get. Using go mod tidy go mod tidy ensures that the go.mod file matches the source code in the module. It adds any missing module requirements necessary to build the current module’s p...
ada

How To Split a list into equally sized chunks in Python

In Python, there are 3 ways to split a list into equally sized chunks. Using List Comprehension List comprehensions provide a concise way to create lists. The following example: #!/usr/bin/python3 # -*- coding: utf8 -*- # initialize lst = ['a'] *...
Patcher56

How To Install Go in Linux

In Golang, there are 2 ways to install Go in Linux.Download Packages Download packages for Windows 64-bit, macOS, Linux, and more. Go install Linux Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extr...
Unused

How To Install Rust in Linux

In Rust, there are two ways to install rust in Linux.Running the following in your terminal If you’re running macOS, Linux, or another Unix-like OS. To download Rustup and install Rust, run the following in your terminal, then follow the on-screen i...
pooriabt