In Golang, using the IsPrivate function is the easiest way to check if IP address is in private network space.
Using IsPrivate Function
The IsPrivate() function reports whether ip is a private address, according to RFC 1918 (IPv4 addresses) and RFC...
In Golang, using the %p verbs is the easiest way to print the memory address of a slice.
Using fmt.Printf Function
Pointer:
%p base 16 notation, with leading 0x. The %b, %d, %o, %x and %X verbs also work with pointers,
formatting the value exactly ...
In Python, using the str.join function is the easiest way to concatenate a list of strings into a single string
Using str.join Function
The str.join() method returns a string which is the concatenation of the strings in iterable. A TypeError will be...
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...
In Golang, using the runtime.FuncForPC function is the easiest way to get the name of a function
Using runtime.FuncForPC Function
The runtime.FuncForPC() function returns a *Func describing the function that contains the given program counter addres...
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 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...
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 ...
In Rust, there are 4 ways to concatenate strings.
Using String.push_str Function
This function actually appends a given string slice onto the end of this `String`. See the following example:
fn main() {
let mut s1: String = "Hello ".to_owned(...
In Python, there are 3 ways to read a file line-by-line.
Using For Loop
For reading lines from a file, you can loop over the file object. This is memory efficient, fast, and leads to simple code:
#!/usr/bin/python3
# -*- coding: utf8 -*-
# read a...
Secure hashes and message digests.Hash algorithms
The hashlib module implements a common interface to many different secure hash and message digest algorithms. Included are the FIPS secure hash algorithms SHA1, SHA224, SHA256, SHA384, and SHA512 (def...
user interface to the TELNET protocol.
Telnet is an application protocol used on the Internet or local area network to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection. User data is interspe...
Display amount of free and used memory in the system.
free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo....
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 ...
compile packages and dependencies.
Build compiles the packages named by the import paths, along with their dependencies, but it does not install the results.
Build
go build
go build hello.go
ls -lh
1.9M Jun 29 17:38 hello
...