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

How to Stop a goroutine in Golang

Several Ways to Stop Goroutine in Go. A signal channel Typically, you pass the goroutine a (possibly separate) signal channel. That signal channel is used to push a value into when you want the goroutine to stop. The goroutine polls that channel reg...
pooriabt

How to Fetch Return Value from a goroutine in Golang

Catching return values from goroutines in Go. Channels A channel is a communication mechanism that lets one goroutine send values to another goroutine. Make a main.go file containing the following: package main import ( "fmt" "time" ) func ...
Tomoki

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 sort a vector in Rust

In Rust, there are 2 ways to sort a vector. Using sort Method The sort(&mut self) method sorts the slice. This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case. For example, fn main() { let mut v = [3, -5, ...
Tomoki

How to Make a List of Alphabet Characters in Python

In Python, there are 2 ways to make a list of alphabet characters. Using string Module The string.ascii_lowercase is a pre-initialized string used as string constant. In Python, string ascii_lowercase will give the lowercase letters ‘abcdefghijklmno...
Patcher56

How to Do Case Insensitive String Comparison in Python

In Python, there are 2 do case insensitive string comparison. Using casefold Method The str.casefold() method returns a casefolded copy of the string. Casefolded strings may be used for caseless matching. For example, #!/usr/bin/python3 a = "H...
pooriabt

How to Capitalize the First Letter of each Word in a String in Python

In Python, there are 2 ways to capitalize the first letter of each word in a string. Using title Method The str.title() method returns a titlecased version of the string where words start with an uppercase character and the remaining characters are...
Patcher56

How to Check if Directory on Path is Empty in Go

In Golang, using the Readdirnames function is the easiest way to check if directory on path is empty. Using Readdirnames Function The file.Readdirnames(n int) function reads the contents of the directory associated with file and returns a slice of ...
Sambhav Khandelwal

How to Convert Float to Integer in Rust

In Rust, there are 2 ways to convert float to integer. Using as Keyword Executing an as expression casts the value on the left-hand side to the type on the right-hand side. An example of an as expression: fn main() { let a = 3.6415_f64; l...
pooriabt

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 Check If two Strings are Equal in a Case-Insensitive Manner in Go

In Golang, using the strings.EqualFold function is the easiest way to check if two strings are equal in a case-insensitive manner Using strings.EqualFold Function The strings.EqualFold() function reports whether s and t, interpreted as UTF-8 strings...
Unused

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 Move a File in Python

In Python, there are 3 ways to move a file. Using os Module The os.rename() method renames the file or directory src to dst. If dst exists, the operation will fail with an OSError subclass in a number of cases: #!/usr/bin/python3 # Import modu...
aweis

How to Do a Case Insensitive Regular Expression in Go

In Golang, using the a case-insensitive flag is the easiest way to do a case insensitive regular expression. Using a case-insensitive flag You can set a case-insensitive flag as the first item in the regex. You can add a (?i) at the beginning of th...
ada

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