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

How to Use Variadic Functions in Golang

Variadic Functions Tutorial with Examples in Go. Variadic Function A variadic function is one that can be called with varying numbers of arguments. The most familiar examples are fmt.Printf and its variants. package main import "fmt" func add(v...
Patcher56

How to Extract All the Numbers Contained in a String in Python

In Python, there are 2 ways to extract all the numbers contained in a string. Using List Comprehension List comprehensions provide a concise way to create lists. If you only want to extract only positive integers, try the following: #!/usr/bin/...
Sambhav Khandelwal

How to Copy a File in Go

In Golang, there are 2 ways to copy a file. Using io.Copy Function You can copy a file using the io.Copy() function. For example, package main import ( "io" "os" ) // Copy the src file to dst. func Copy(src, dst string) error { in, err...
Unused

How to Create a GUID/UUID in Python

In Python, using the uuid module is the easiest way to create a GUID/UUID. Using uuid Module uuid module provides immutable UUID objects (the UUID class) and the functions uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5 UUID...
aweis

How to Create Multiline Comments in Python

In Python, using the triple-quoted strings is the easiest way to create multiline comments. Using triple-quoted Strings String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''. You can use triple-quoted strin...
aweis

How to Append Text to a File in Go

In Golang, using the os.O_APPEND flag is the easiest way to append text to a file Using os.OpenFile Function OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc...
ada

How to Index a String in Rust

In Rust, there are 2 ways to index a string. Using as_bytes Function 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: fn main() { let s = "abc"; let b: u8 = s.as...
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 Create Nested Directories in Go

In Golang, using the os.MkdirAll function is the easiest way to create nested directories Using os.MkdirAll Function The os.MkdirAll() function creates a directory named path, along with any necessary parents, and returns nil, or else returns an er...
Sambhav Khandelwal

How to Download a Large File in Go

In Golang, using the io.copy function is the easiest way to download a large file Using io.Copy Function The io.Copy() function copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and ...
ada

How to Convert Vec to a String in Rust

In Rust, there are 2 ways to convert Vec to a string. Using collect Function The collect() function transforms an iterator into a collection. collect() can take anything iterable, and turn it into a relevant collection. This is one of the more powe...
Patcher56

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 Remove an Element From a List by Index in Python

In Python, there are 3 ways to remove an element from a list by index. Using del Keyword There is a way to remove an item from a list given its index instead of its value. For example, #!/usr/bin/python3 # -*- coding: utf8 -*- l = [1, 2, 3, 4]...
Unused

How to Merge two Dictionaries into a new Dictionary in Python

In Python, there are 3 ways to merge two dictionaries into a new dictionary. Using Additional Unpacking Generalizations Starting with Python 3.5, we can merge in with literal notation as well. See the following example: #!/usr/bin/python3 # -*-...
Unused