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

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 Count the Items in the Map in Go

In Golang, using the len function is the easiest way to count the items in the map structure. Using len Function The built-in function len take arguments of various types and return a result of type int. The implementation guarantees that the result...
Sambhav Khandelwal

How to Reverse a String in Python

In Python, there are 3 ways to reverse a string. Using slicing Slice notation takes the form [start:stop:step]. #!/usr/bin/python3 s = "Hello World" print(s[::-1]) # syntax # a[start:stop] # items start through stop-1 # a[start:] # items...
pooriabt

How to Check If an Object Is of a Given Type in Python

In Python, there are 2 ways to check if an object is of a given type. Using isinstance Method The isinstance(object, classinfo) method returns True if the object argument is an instance of the classinfo argument, or of a (direct, indirect, or virtua...
Unused

How to Find the Index of an Element in a Vector in Rust

In Rust, using the position function is the easiest way to find the index of an element in a vector. Using position Method The position() method searches for an element in an iterator, returning its index. position() is short-circuiting; in other ...
pooriabt

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 Unpack Array as Arguments in Go

In Golang, there are 2 ways to unpack array as arguments. Using Variadic Functions Variadic functions can be called with any number of trailing arguments. Here’s a function that will take an arbitrary number of ints as arguments. For example, p...
Unused

How to Check the Equality of two Slices in Go

In Golang, there are 3 ways to check the equality of two slices. Using bytes.Equal Function Equal reports whether a and b are the same length and contain the same bytes. A nil argument is equivalent to an empty slice. For example, package main...
aweis

How to Get a Slice of Keys from a Map in Go

In Golang, there are 3 ways to get a slice of keys from a map.Using For Range The easiest way to get keys of map in Golang: package main import "fmt" func main() { m := map[string]int{ "a": 1, "b": 1, "c": 1, } // minimize ...
Sambhav Khandelwal

How to Convert Byte Array to String in Go

In Golang, there are 2 ways to convert byte array to string.Using string Function The easiest way to convert []byte to string in Golang: package main import "fmt" func main() { b := []byte{'a', 'b', 'c'} s := string(b[:]) fmt.Printf("%...
Tomoki

How To Split a list into equally sized chunks in Python

In Python, there are 3 ways to split a list into equally sized chunks. Using List Comprehension List comprehensions provide a concise way to create lists. The following example: #!/usr/bin/python3 # -*- coding: utf8 -*- # initialize lst = ['a'] *...
Patcher56

How to convert string to json in Rust

In Rust, there are 3 ways to convert string to json. Using Serde JSON Serde is a framework for serializing and deserializing Rust data structures efficiently and generically. Adding dependencies In Cargo.toml file we’ll add this information. [de...
Patcher56

How to fill a list with same values in Python

3 ways to initialize a Python Array .Initialize a list with values If you want to initialize a list of any number of elements where all elements are filled with any values, you can use the * operator as follows. #!/usr/bin/env python3 arr = ['H'] *...
aweis