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

How to Use Anonymous Functions in Golang

Closures and Anonymous Functions in Go. Anonymous Function A function literal is written like a function declaration, but without a name following the func keyword. It is an expression, and its value is called an anonymous function. package main ...
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 Get the Full URL in PHP

In PHP, using the $_SERVER variable is the easiest way to get the full URL. Using $_SERVER Variable $_SERVER is an array containing information such as headers, paths, and script locations. The following example should cover whatever you are trying...
url
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 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 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 Get Memory Size of the Variable in Go

In Golang, using the unsafe.Sizeof function is the easiest way to get memory size of the variable Using Sizeof Function You can use the unsafe.Sizeof function for this. It returns the size in bytes. See the following example: package main impo...
aweis

How to check if a variable exists in Python

In Python, there are 3 ways to check if a variable exists. Using locals Function The locals() function returns the dictionary of the current local symbol table. #!/usr/bin/python3 vName = 1 if 'vName' in locals(): print("exists") exists ...
Sambhav Khandelwal

How to Access Command-Line Arguments in Go

In Golang, there are 2 ways to access command-line arguments passed to a program. Using os.Args Variable You can access the command-line arguments using the os.Args variable. Note that the first value in this slice is the path to the program, and o...
Unused

How to Read a Whole File into a String Variable in Go

In Golang, there are 3 ways to read a whole file into a string variable. Using ioutil.ReadFile Function ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads...
aweis

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 Install Go in Linux

In Golang, there are 2 ways to install Go in Linux.Download Packages Download packages for Windows 64-bit, macOS, Linux, and more. Go install Linux Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extr...
Unused

Rust error: cannot assign twice to immutable variable

In Rust, variables by default are immutable.Variables Immutable You can make them mutable by adding mut in front of the variable name. For example, fn main() { let x = 2; println!("value x: {}", x); x = 4; println!("value x: {}", x); } ...
Patcher56

How To Install Rust in Linux

In Rust, there are two ways to install rust in Linux.Running the following in your terminal If you’re running macOS, Linux, or another Unix-like OS. To download Rustup and install Rust, run the following in your terminal, then follow the on-screen i...
pooriabt

How to format a string in Python

Python String Formatting Best Practices.Fancier Output Formatting To use formatted string literals, begin a string with f or F before the opening quotation mark or triple quotation mark. Inside this string, you can write a Python expression between {...
Sambhav Khandelwal