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 Use bytes.Buffer in Golang

Golang bytes.Buffer Examples Examples of Golang bytes.Buffer The bytes package provides the Buffer type for efficient manipulation of byte slices. A Buffer starts out empty but grows as data of types like string, byte, and []byte are written to it. ...
ada

How to Add Two Numbers in Go

An example program using numbers. Integers And Floating Point Numbers Go has several different types to represent numbers. Generally we split numbers into two different kinds: integers and floating-point numbers. Make a main.go file containing the ...
pooriabt

How to Encrypt and Decrypt a String Using AES CBC in Go

In Golang, using the crypto/aes package is the easiest way to encrypt a string using AES CBC. Ehrsam, Meyer, Smith and Tuchman invented the cipher block chaining (CBC) mode of operation in 1976. In CBC mode, each block of plaintext is XORed with the ...
Tomoki

How to Check if IP Address is in Private Network Space in Go

In Golang, using the IsPrivate function is the easiest way to check if IP address is in private network space. Using IsPrivate Function The IsPrivate() function reports whether ip is a private address, according to RFC 1918 (IPv4 addresses) and RFC...
aweis

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 Print the Memory Address of a Slice in Go

In Golang, using the %p verbs is the easiest way to print the memory address of a slice. Using fmt.Printf Function Pointer: %p base 16 notation, with leading 0x. The %b, %d, %o, %x and %X verbs also work with pointers, formatting the value exactly ...
Tomoki

How to Set Environment Variables in Python

In Python, using the os.environ variable is the easiest way to set environment variables Using os.environ Variable os.environ behaves like a python dictionary, so all the common dictionary operations can be performed. In addition to the get and set ...
Sambhav Khandelwal

How to Concatenate a List of Strings into a Single String in Python

In Python, using the str.join function is the easiest way to concatenate a list of strings into a single string Using str.join Function The str.join() method returns a string which is the concatenation of the strings in iterable. A TypeError will be...
aweis

How to Get a Function Name as a String in Python

In Python, there are 2 ways to get a function name as a string. Using __name__ Attribute Using __qualname__ is the preferred method as it applies uniformly. It works on built-in functions as well: #!/usr/bin/python3 def my_func(): pass class...
ada

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 Get the Difference in Hours Between Two Dates in Go

In Golang, there are 2 ways to get the difference in hours between two dates. Using time.Since Function The time.Since() function returns the time elapsed since t. It is shorthand for time.Now().Sub(t). For example, package main import ( "fm...
Unused

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 Get the Name of a Function in Go

In Golang, using the runtime.FuncForPC function is the easiest way to get the name of a function Using runtime.FuncForPC Function The runtime.FuncForPC() function returns a *Func describing the function that contains the given program counter addres...
Unused