In Golang, there are 2 ways to change the current directory.
Using Dir Property
Usually if you need a command to run from a specific directory, you can specify that as the Dir property on the Command, for example:
package main
import (
"os/...
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
...
In Golang, there are 2 ways to pipe several commands.
Using piped commands
For example, this function retrieves the CPU model name using piped commands:
package main
import (
"fmt"
"os/exec"
)
func main() {
cmd := "cat /proc/cpuinfo | eg...
In Golang, using the exec.Command() function is the easiest way to execute a shell command
Using exec.Command Function
Command returns the Cmd struct to execute the named program with the given arguments.
You can execute a shell command using the e...
In Golang, there are 2 ways to access command-line arguments passed to a program.
Using os.Args Variable
You can access the command-line arguments using the os.Args variable.
Note that the first value in this slice is the path to the program, and o...
In Python, there are 2 ways to prettyprint a JSON file.
Using json module
The json module already implements some basic pretty printing in the dump and dumps functions, with the indent parameter that specifies how many spaces to indent by:
#!/us...
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...
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...
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::...
In Golang, there are 3 ways to get the directory of the currently running file.Using os.Executable Function
Executable returns the path name for the executable that started the current process.
The easiest way to get the directory of the currently ...
In Python, there are 3 ways to execute a program or call a system command.
Using subprocess Module
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. See the following e...
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...
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'] *...
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...
In Rust, "Hello World!" is the first basic program.
Build and Run
In our main.rs, add the following code:
// main.rs
fn main() {
println!("Hello,世界,こんにちは,안녕하세요")
}
Hello,世界,こんにちは,안녕하세요
we can run our application by typing:
B...