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 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 Marshal / Unmarshal Json with a Custom Type Attribute in Go

In Golang, using the Unmarshal JSON function is the easiest way to Marshal / Unmarshal json with a custom type attribute. JSON (JavaScript Object Notation) is a lightweight data-interchange format. Using UnmarshalJSON Function Example on custom Unm...
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 Escape the Html in Go

In Golang, there are 2 ways to escape the html. Using EscapeString Function The html.EscapeString() function escapes special characters like "
ada

How to Get the Size of a File in Python

In Python, there are 3 ways to get the size of a file. Using os.path.getsize Method The os.path.getsize() method returns the size, in bytes, of path. Raise OSError if the file does not exist or is inaccessible. For example, #!/usr/bin/python3 #...
aweis

How to Get File Creation and Modification Dates Times in Python

In Python, there are 3 ways to get file creation and modification dates times. Using os.path Function The os.path.getmtime() function returns the time of last modification of path. The os.path.getctime() function returns the system’s ctime which, o...
Patcher56

How to Get File Length in Go

In Golang, there are 2 ways to get file length. Using file.Stat Function Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. See the followin...
ada

How to Check the Version of the Interpreter in Python

In Python, there are 3 ways to check what version of the Interpreter is interpreting my script. Using sys.version String A string containing the version number of the Python interpreter plus additional information on the build number and compiler us...
ada

How to Check If a Directory Exists in Python

In Python, there are 3 ways to check if a directory exists. Using os.path.isdir Method You can use os.path.isdir() to check if a directory exists, it really simple. For example, #!/usr/bin/python3 # Import module import os d = "./folder" print...
aweis

How to Make a Time Delay in Python

In Python, there are 2 ways to make a time delay. Using time.sleep Function This function actually suspends execution of the calling thread for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep...
aweis

How to Check whether a File Exists in Python

In Python, there are 3 ways to check if a file exists. Using os.path.exists Method Return True if path refers to an existing path or an open file descriptor. Returns False for broken symbolic links. On some platforms, this function may return False ...
Patcher56

How to Check if a File Exists in Go

In Golang, there are 2 ways to check if a file exists.Using os.Stat Function Stat returns a FileInfo describing the named file. See the following example: package main import ( "errors" "fmt" "os" ) func main() { // since the additio...
aweis

Hello World in Python

Hello, World! is the first basic program in any programming language.Python Version Print the Python version number and exit. Example output could be: Python version python -V python --version Python 3.9.1 Running Files with Command Lines You c...
ada

How to check if a string contains a substring in JavaScript

How do you check if a string contains a substring?.Using String.prototype.includes The includes() method performs a case-sensitive search to determine whether one string may be found within another string, returning true or false as appropriate. 'Go...
pooriabt