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

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 Convert the Fahrenheit to Celsius in Golang

Calculate degrees celcius from farenheit in Go. Following program shows you how to convert fahrenheit to celsius. The function FToC below encapsu- lates the temperature conversion logic so that it is defined only once but may be used from multiple p...
Sambhav Khandelwal

How to Delete an Element from an Array in PHP

In PHP, there are 3 ways to delete an element from an array. Using unset Function The unset(mixed $var, mixed ...$vars): void function destroys the specified variables. For example, $arr = ["a", "b", "d"]; unset($arr[1]); print_r($arr); Arr...
Sambhav Khandelwal

How to Convert a String to int in Rust

In Rust, using the parse method is the easiest way to convert a string to int. Using parse Method The str::parse::<T>() method parses this string slice into another type. For example, fn main() { let s = "100".to_string(); println!("{}"...
Tomoki

How to Convert all Strings in a List to Int in Python

In Python, there are 2 ways to convert all strings in a list to int. Using map Method You can convert all strings in a list to int using the map method. For example, #!/usr/bin/python3 a = ["1", "2", "4", "5"] b = list(map(int, a)) print(b) ...
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 Convert a Str to a &[u8] in Rust

In Rust, there are 2 ways to convert a str to a &[u8]. Using as_bytes Function The as_bytes() method converts a string slice to a byte slice. To convert the byte slice back into a string slice, use the from_utf8 function. See the following example...
aweis

How to Convert a Bool to a String in Go

In Golang, there are 2 ways to convert a bool to a string. Using strconv.FormatBool Function The strconv.FormatBool() function returns "true" or "false" according to the value of b. For example, package main import ( "fmt" "strconv" ) fun...
Tomoki

How to Convert an Integer to a Float Number in Go

In Golang, using the float64 function is the easiest way to convert an integer to a float number. Using float64 Function The easiest way to convert an integer to a float number in Golang: package main import "fmt" func main() { i := 6 f ...
Patcher56

How to Read from Stdin in Python

In Python, there are 3 ways to read from stdin. Using fileinput Module This module implements a helper class and functions to quickly write a loop over standard input or a list of files. For example, #!/usr/bin/python3 # Import module import f...
pooriabt

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 Parse Unix Timestamp to time.Time in Go

In Golang, using the time.Unix() function is the easiest way to parse unix timestamp to time.Time Using time.Unix Function You can directly use time.Unix function of time which converts the unix time stamp to UTC. See the following example: pa...
pooriabt

How to Convert a String into a &'static Str in Rust

In Rust, there are 3 ways to convert a string into a &'static str. Using slicing Syntax To go from a String to a slice &'a str you can use slicing syntax. See the following example: // Rust 1.0+ fn main() { let s: String = "abc".to_owned(); ...
Tomoki

How to Access Command Line Parameters in Rust

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

How to Get the Current Time in Python

In Python, there are 2 ways to get the current time. Using datetime Module The datetime module supplies classes for manipulating dates and times. See the following example: #!/usr/bin/python3 # -*- coding: utf8 -*- # Import module import datet...
Patcher56