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

How to Split a String into a List in Python

In Python, using the str.split method is the easiest way to split a string into a list Using split Method The str.split(sep=None, maxsplit=- 1) method returns a list of the words in the string, using sep as the delimiter string. If maxsplit is given...
ada

How to List Files of a Directory in Rust

In Rust, using the read_dir function is the easiest way to list files of a directory. Using read_dir Function The fs::read_dir() function returns an iterator over the entries within a directory. See the following example: use std::fs; fn main...
ada

How to Set Timeout for http.Get Requests in Go

In Golang, there are 2 ways to set timeout for http.Get requests Using http.Client.Timeout Field Timeout specifies a time limit for requests made by this Client. The timeout includes connection time, any redirects, and reading the response body. S...
Tomoki

How to Subtracting time.Duration from Time in Go

In Golang, using the time.Duration function is the easiest way to subtract time from a time.Time Using time.Duration Function A Duration represents the elapsed time between two instants as an int64 nanosecond count. The representation limits the la...
Tomoki

How to Get the Maximum Value for an Int Type in Go

In Golang, there are 2 ways to get the maximum value for an int type. Using constant values Since integer types use two's complement arithmetic, you can infer the min/max constant values for int and uint. For example, package main import ( "...
Patcher56

How to Know If an Object has an Attribute in Python

In Python, there are 4 ways to know if an object has an attribute. Using hasattr Method The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. For example, #!/usr/...
ada

How to Limit Floats to Two Decimal Points in Python

In Python, there are 4 ways to limit floats to two decimal points. Using format Method You can use str.format() function to limit floats, it really simple. For example, #!/usr/bin/python3 # -*- coding: utf8 -*- f = 13.949999999999999 print("{:...
Unused

How to Execute a Program or Call a System Command in Python

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...
Patcher56

How to Split a String in Rust

In Rust, there are 3 ways to split a string. Using split Function An iterator over substrings of this string slice, separated by characters matched by a pattern. See the following example: fn main() { let s = "abc1bcd2e"; let _split = s.sp...
ada

How to Read a File Line-by-Line in Go

In Golang, there are 2 ways to read a file line-by-line. Using bufio.Scanner Function Scanner provides a convenient interface for reading data such as a file of newline-delimited lines of text. The ones that are currently implemented are: packa...
Sambhav Khandelwal

How to create a multiline string in Rust

In Rust, there are 4 ways to create multiple lines string.Using triple-quotes A string literal is a sequence of any Unicode characters enclosed within two U+0022 (double-quote) characters, with the exception of U+0022 itself, which must be escaped b...
Unused

How to split a string into a slice in Go

Splitting a String into a Slice in Golang.Using strings.Split Function Use the strings.Split function to split a string into its comma separated values. package main import ( "fmt" "strings" ) func main() { s := "Japan,Germany" // func S...
Unused

How to use the df command in Linux

Show information about the file system on which each FILE resides, or all file systems by default. df (abbreviation for disk free) is a standard Unix command used to display the amount of available disk space for file systems on which the invoking us...

How to use the curl command in Linux

command line tool and library for transferring data with URLs. cURL (pronounced 'curl') is a computer software project providing a library (libcurl) and command-line tool (curl) for transferring data using various network protocols. The name ...

How to use the ls command in Linux

List Files and Directories.The ls command lists files and directories within the file system, and shows detailed information about them. It is a part of the GNU core utilities package which is installed on all Linux distributions. List all files, in...