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

How to Use Deferred Function Calls in Golang

Understanding defer in Go. Deferred Function Calls A defer statement is an ordinary function or method call prefixed by the keyword defer. The function and argument expressions are evaluated when the statement is executed, but the actual call is def...
ada

How to Get correct file base name in Golang

Golang path and filepath Examples. Using filepath.Base The number is the index of the last slash in the string. If you want to get the file's base name, use filepath.Base: package main import ( "fmt" "path/filepath" ) func main() { path ...
Patcher56

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 Get Name of Current Script in Python

In Python, using the __file__ is the easiest way to get name of current script. Using Module Attributes You can use __file__ to get the name of the current file. When used in the main module, this is the name of the script that was originally invoke...
Unused

How to Get a Random Number Between a Float Range in Python

In Python, using the uniform function is the easiest way to get a random number between a float range. Using uniform Method The random.uniform(a, b) method returns a random floating point number N such that a
Unused

How to Get a SHA256 Hash from a String in Go

In Golang, using the Sum256 function is the easiest way to get a SHA256 hash from a string.Go implements several hash functions in various crypto/* packages. Using Sum256 Function The sha256.Sum256() function returns the SHA256 checksum of the data...
ada

How to Get a MD5 Hash from a String in Go

In Golang, using the Sum function is the easiest way to get a MD5 hash from a string. Using Sum Function The md5.Sum() function returns the MD5 checksum of the data. The following example should cover whatever you are trying to do: package mai...
aweis

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 Set the Current Working Directory in Python

In Python, using the os.chdir method is the easiest way to set the current working directory Using chdir Method The os.chdir(path) method changes the current working directory to path. For example, #!/usr/bin/python3 # Import module import os ...
Unused

How to Get the Psition of a Character in Python

In Python, there are 3 ways to get the position of a character. Using find Method The str.find(sub[, start[, end]]) method returns the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start an...
aweis

How to Get Current Time in Milliseconds in Python

In Python, there are 3 ways to get current time in milliseconds. Using time Method The time.time() method returns the time in seconds since the epoch as a floating point number. For example, #!/usr/bin/python3 # Import module import time ms =...
Patcher56

How to Get the Day of Week Given a Date in Python

In Python, there are 2 ways to get the day of week given a date. Using weekday Method The weekday() method returns the day of the week as an integer, where Monday is 0 and Sunday is 6. The following example should cover whatever you are trying to ...
Sambhav Khandelwal

How to Remove the First Character of a String in Go

In Golang, using the DecodeRuneInString function is the easiest way to remove the first character of a string. Using DecodeRuneInString Function The following example should cover whatever you are trying to do: package main import ( "fmt" ...
Patcher56

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 Get a List of All Subdirectories in the Current Directory in Python

In Python, there are 2 ways to get a list of all subdirectories in the current directory. Using os.walk Function The os.walk() method generates the file names in a directory tree by walking the tree either top-down or bottom-up. The following examp...
pooriabt