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...
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...
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 =...
In Python, there are 2 ways to retrieve a module's path.
Using __file__ Attribute
You can retrieve a module's path using the __file__ attribute. For example,
#!/usr/bin/python3
# Import module
import os
print(os.__file__)
/usr/local/lib/pyt...
In Python, there are 2 ways to get a function name as a string.
Using __name__ Attribute
Using __qualname__ is the preferred method as it applies uniformly. It works on built-in functions as well:
#!/usr/bin/python3
def my_func():
pass
class...
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
...
In Python, there are 2 ways to determine if an object is iterable.
Using Duck Typing
Duck typing is a concept related to dynamic typing, where the type or the class of an object is less important than the methods it defines. When you use duck typing...
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...
In Python, there are 4 ways to know if an object has an attribute.
Using hasattr Method
The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. For example,
#!/usr/...
command line tool and library for transferring data with URLs.
cURL (pronounced 'curl') is a computer software project providing a library (libcurl) and command-line tool (curl) for transferring data using various network protocols. The name ...
The chown command changes user ownership of a file, directory, or link in Linux.
The command chown, an abbreviation of change owner, is used on Unix and Unix-like operating systems to change the owner of file system files, directories.
cha...
Compiles an Angular app into an output directory named dist/ at the given output path.The command can be used to build a project of type "application" or "library". When used to build a library, a different builder is invoked, and only the ts-config,...
This page provides the usage information for the docker-compose Command.The following show the Docker-Compose version information:
Version information
docker-compose version
docker-compose -v
docker-compose --version
docker...
A modern approach to copy text to clipboard No Flash. No frameworks. --pname-- lets you easily copy text to the clipboard. At 3kb gzipped and no need for Flash, it’s a great lightweight way to allow your visitors to copy bits of text and code on your...
LitElement is a simple base class for creating fast, lightweight web components that work in any web page with any framework.--pname-- uses lit-html to render into shadow DOM, and adds API to manage properties and attributes. Properties are observed ...