Merge pull request #99 from terminalforlife/master
More Comments & Code Tweaks & Additionspull/103/head
commit
4a1a6d1e77
@ -1,8 +1,15 @@
|
||||
int *int_Ptr; // Declare a pointer variable called iPtr pointing to an int (an int pointer)
|
||||
// It contains an address. That address holds an int value.
|
||||
double *double_Ptr; // Declare a pointer of type double.
|
||||
// Declare a pointer variable called iPtr pointing to an int (an int pointer)
|
||||
// It contains an address. That address holds an int value.
|
||||
int *int_Ptr;
|
||||
|
||||
int a = 5; // Initializes a to the integer value 5
|
||||
int *int_Ptr = &a // Set int_Ptr which is an int pointer to the address of a
|
||||
std::cout << int_Ptr; // Returns the address of a
|
||||
std::cout << *int_Ptr; // Returns 5 because it dereference the pointer to retrieve the value of a.
|
||||
// Declare a pointer of type double.
|
||||
double *double_Ptr;
|
||||
|
||||
// Initializes a to the integer value 5
|
||||
int a = 5;
|
||||
// Set int_Ptr which is an int pointer to the address of `a`.
|
||||
int *int_Ptr = &a
|
||||
// Returns the address of `a`.
|
||||
std::cout << int_Ptr;
|
||||
// Returns 5 because it dereference the pointer to retrieve the value of `a`.
|
||||
std::cout << *int_Ptr;
|
||||
|
@ -1,23 +1,23 @@
|
||||
func main() {
|
||||
// Basic one
|
||||
if x > 0 {
|
||||
return x
|
||||
} else {
|
||||
return -x
|
||||
}
|
||||
|
||||
// You can put one statement before the condition
|
||||
if a := b + c; a < 42 {
|
||||
return a
|
||||
} else {
|
||||
return a - 42
|
||||
}
|
||||
// Basic one
|
||||
if x > 0 {
|
||||
return x
|
||||
} else {
|
||||
return -x
|
||||
}
|
||||
|
||||
// You can put one statement before the condition
|
||||
if a := b + c; a < 42 {
|
||||
return a
|
||||
} else {
|
||||
return a - 42
|
||||
}
|
||||
|
||||
// Type assertion inside if
|
||||
var val interface{}
|
||||
val = "foo"
|
||||
if str, ok := val.(string); ok {
|
||||
fmt.Println(str)
|
||||
}
|
||||
// Type assertion inside if
|
||||
var val interface{}
|
||||
val = "foo"
|
||||
if str, ok := val.(string); ok {
|
||||
fmt.Println(str)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,40 +1,40 @@
|
||||
# Simple function
|
||||
def functionName():
|
||||
return True
|
||||
return True
|
||||
|
||||
# Function with parameters
|
||||
def functionName(a, b):
|
||||
if a < b:
|
||||
return a
|
||||
else:
|
||||
return b
|
||||
def functionName(a, b):
|
||||
if a < b:
|
||||
return a
|
||||
else:
|
||||
return b
|
||||
|
||||
# Return multiple values
|
||||
def functionName(a, b, c):
|
||||
return a, b, c # Returns a tuple
|
||||
return {'return_a':a, 'return_b':b ,'return_c':c } # Returns a dictionary
|
||||
def functionName(a, b, c):
|
||||
return a, b, c # Returns a tuple
|
||||
return {'return_a':a, 'return_b':b ,'return_c':c } # Returns a dictionary
|
||||
|
||||
# Function with default parameters
|
||||
def functionName(a=0, b=1):
|
||||
print(a, b)
|
||||
functionName() # 0 1
|
||||
functionName(3) # 3 1
|
||||
functionName(3, 4) # 3 4
|
||||
def functionName(a=0, b=1):
|
||||
print(a, b)
|
||||
functionName() # 0 1
|
||||
functionName(3) # 3 1
|
||||
functionName(3, 4) # 3 4
|
||||
|
||||
# Calling parameters by name
|
||||
def functionName(a, b, c):
|
||||
print(a, b, c)
|
||||
functionName(0, 1, 2) # 0 1 2
|
||||
functionName(a=2, c=3, b=4) # 2 4 3
|
||||
functionName(2, 3, c=4) # 2 3 4
|
||||
def functionName(a, b, c):
|
||||
print(a, b, c)
|
||||
functionName(0, 1, 2) # 0 1 2
|
||||
functionName(a=2, c=3, b=4) # 2 4 3
|
||||
functionName(2, 3, c=4) # 2 3 4
|
||||
|
||||
# Arbitrary number of parameters
|
||||
def functionName(*args):
|
||||
...
|
||||
functionName(*[1, 2]) # Equivalent of functionName(1, 2)
|
||||
functionName(*[1, 2, 3]) # Equivalent of functionName(1, 2, 3)
|
||||
...
|
||||
functionName(*[1, 2]) # Equivalent of functionName(1, 2)
|
||||
functionName(*[1, 2, 3]) # Equivalent of functionName(1, 2, 3)
|
||||
|
||||
# Arbitrary number of parameters with arbitrary name
|
||||
def functionName(**kwargs):
|
||||
...
|
||||
functionName(**{'a' : 3, 'b' : 4}) # Equivalent of functionName(a=3, b=4)
|
||||
...
|
||||
functionName(**{'a' : 3, 'b' : 4}) # Equivalent of functionName(a=3, b=4)
|
||||
|
@ -1,2 +1,16 @@
|
||||
# POSIX-ly correct way in which to cat(1); see cat(1posix).
|
||||
cat -u [FILE_1 [FILE_2] ...]
|
||||
|
||||
# Output a file, expanding any escape sequences (default). Using this short
|
||||
# one-liner let's you view the boot log how it was show at boot-time.
|
||||
cat /var/log/boot.log
|
||||
|
||||
# This is an ever-popular useless use of cat.
|
||||
cat /etc/passwd | grep '^root'
|
||||
# The sane way:
|
||||
grep '^root' /etc/passwd
|
||||
|
||||
# If in bash(1), this is often (but not always) a useless use of cat(1).
|
||||
Buffer=`cat /etc/passwd`
|
||||
# The sane way:
|
||||
Buffer=`< /etc/passwd`
|
||||
|
@ -1,26 +1,42 @@
|
||||
# Read from {/dev/urandom} 2*512 Bytes and put it into {/tmp/test.txt}
|
||||
# Note: At the first iteration, we read 512 Bytes.
|
||||
# Note: At the second iteration, we read 512 Bytes.
|
||||
dd if=/dev/urandom of=/tmp/test.txt count=512 bs=2
|
||||
# Note: both iterations each read 512 Bytes (the selected block size).
|
||||
dd if=/dev/urandom of=/tmp/test.txt count=2 bs=512
|
||||
|
||||
# Watch the progress of 'dd'
|
||||
dd if=/dev/zero of=/dev/null bs=4KB &; export dd_pid=`pgrep '^dd'`; while [[ -d /proc/$dd_pid ]]; do kill -USR1 $dd_pid && sleep 1 && clear; done
|
||||
# Watch the progress of dd(1).
|
||||
dd if=/dev/zero of=/dev/null bs=4KB &
|
||||
export dd_pid=`pgrep '^dd'`
|
||||
while [[ -d /proc/$dd_pid ]]; do
|
||||
kill -USR1 $dd_pid && sleep 1
|
||||
clear
|
||||
done
|
||||
|
||||
# Watch the progress of 'dd' with `pv` and `dialog` (apt-get install pv dialog)
|
||||
(pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
|
||||
# Watch the progress of dd(1) with pv(1) and dialog(1), both of which can be
|
||||
# installed with the following command: apt-get install pv dialog
|
||||
(
|
||||
pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror
|
||||
) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
|
||||
|
||||
# Watch the progress of 'dd' with `pv` and `zenity` (apt-get install pv zenity)
|
||||
(pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror) 2>&1 | zenity --title 'Running dd command (cloning), please wait...' --progress
|
||||
# Watch the progress of dd(1) with pv(1) and zenity(1), both of which can be
|
||||
# installed with the following command: apt-get install pv zenity
|
||||
(
|
||||
pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror
|
||||
) 2>&1 | zenity --title 'Running dd command (cloning), please wait...' --progress
|
||||
|
||||
# Watch the progress of 'dd' with the built-in `progress` functionality (introduced in coreutils v8.24)
|
||||
# Watch the progress of dd(1) with the built-in `progress` functionality, -
|
||||
# introduced in coreutils v8.24.
|
||||
dd if=/dev/zero of=/dev/null bs=128M status=progress
|
||||
|
||||
# DD with "graphical" return
|
||||
dcfldd if=/dev/zero of=/dev/null bs=500K
|
||||
|
||||
# This will output the sound from your microphone port to the ssh target computer's speaker port. The sound quality is very bad, so you will hear a lot of hissing.
|
||||
# This will output the sound from your microphone port to the ssh target
|
||||
# computer's speaker port. The sound quality is very bad, so you will hear a
|
||||
# lot of hissing.
|
||||
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
|
||||
|
||||
# Show current progress without interruption (USR1)
|
||||
dd if=/dev/zero of=/dev/null & pid=$!
|
||||
kill -USR1 $pid
|
||||
|
||||
# Create a 1GiB file with nothing but zeros, ready to mkswap(8) it.
|
||||
dd if=/dev/zero of=/swapfile count=1048576 bs=1024 status=progress
|
||||
|
@ -1,14 +1,17 @@
|
||||
# Printout disk free space in a human readable format
|
||||
# Print free disk space in a [h]uman-readable format.
|
||||
df -h
|
||||
|
||||
# Disk free space for ext2 file systems
|
||||
# Free disk space for [t]ype EXT2 file systems.
|
||||
df -t ext2
|
||||
|
||||
# Disk free space for file systems except ext2
|
||||
# Free disk space for filesystems, e[x]cluding EXT2.
|
||||
df -x ext2
|
||||
|
||||
# Show inode usage
|
||||
# Show [i]node usage.
|
||||
df -i
|
||||
|
||||
# Show information about a distinct file system /path
|
||||
df /path
|
||||
# Show information about a distinct filesystem path.
|
||||
df [PATH]
|
||||
|
||||
# List [a]ll filesystems, + unreadable, duplicates, pseudo, and inaccessible.
|
||||
df -a
|
||||
|
@ -1,17 +1,17 @@
|
||||
# exec
|
||||
#
|
||||
# Shell builtin command
|
||||
# It can start a new process to replace the shell, without a new process creation.
|
||||
# It can make redirections take effect in the current shell
|
||||
# It can start a new process to replace the shell, without a new process
|
||||
# creation. It can make redirections take effect in the current shell
|
||||
|
||||
# Redirect the output of an entire shell script within the script itself
|
||||
# Only stdout:
|
||||
# Redirect all STDOUT from within a script to the given file.
|
||||
exec > foo.log
|
||||
|
||||
# Redirect the output of an entire shell script within the script itself
|
||||
# Stdout and stderr:
|
||||
# Redirect all of both STDOUT & STDERR from within a script to the given file.
|
||||
exec > foo.log 2>&1
|
||||
# Or, if on bash(1), this syntax is also viable:
|
||||
exec &> foo.log
|
||||
|
||||
# Copy output to a log file
|
||||
# Copy output to a log file, allowing the outputs to still work as usual.
|
||||
exec > >(tee -ia foo.log)
|
||||
exec 2> >(tee -ia foo.log >&2)
|
||||
|
@ -1,33 +1,33 @@
|
||||
# lshw
|
||||
# Get hardware information on Linux
|
||||
|
||||
# Generate full information report about all detected hardware
|
||||
# Generate full information report about all detected hardware.
|
||||
lshw
|
||||
|
||||
# Display hardware information in short
|
||||
# Display brief hardware information.
|
||||
lshw -short
|
||||
|
||||
# Display only memory information
|
||||
# Display only memory information.
|
||||
lshw -short -class memory
|
||||
|
||||
# Display processor information
|
||||
# Display processor information.
|
||||
lshw -class processor
|
||||
|
||||
# Display the disk drives with the disk class
|
||||
# Display the disk drives with the disk class.
|
||||
lshw -short -class disk
|
||||
|
||||
# Display information about the partitions and controllers also,
|
||||
# specify the storage and volume class along with the disk class
|
||||
# specify the storage and volume class along with the disk class.
|
||||
lshw -short -class disk -class storage -class volume
|
||||
|
||||
# Network adapter information
|
||||
# Network adapter information.
|
||||
lshw -class network
|
||||
|
||||
# Display the address details of pci, usb, scsi and ide devices
|
||||
# Display the address details of PCI, USB, SCSI and IDE devices.
|
||||
lshw -businfo
|
||||
|
||||
# Generate report in html format
|
||||
# Generate report in HTML format.
|
||||
lshw -html > hardware.html
|
||||
|
||||
# Generate report in xml format
|
||||
# Generate report in XML format.
|
||||
lshw -html > hardware.html
|
||||
|
@ -1,6 +1,6 @@
|
||||
# This is a shell builtin available in bash, but not in the Bourne Shell (`sh`).
|
||||
# The contents of FILE (assuming shell script) will be sourced into the current
|
||||
# session, allowing external use of things like its functions and variables.
|
||||
# This is a shell built-in available in Bash, but not in the Bourne Shell
|
||||
# (`sh`). The contents of FILE (assuming shell script) will be sourced into the
|
||||
# current session, allowing external use of its functions, variables, etc.
|
||||
source FILE
|
||||
# The above can be written in short-hand, for the same effect:
|
||||
. FILE
|
||||
|
@ -1,28 +1,30 @@
|
||||
# svgo
|
||||
#
|
||||
# SVG Optimizer: a Nodejs-based tool for optimizing Scalable Vector Graphics files.
|
||||
# It applies a series of transformation rules (plugins), which can be toggled individually.
|
||||
# SVG Optimizer: a Node.js-based tool for optimizing Scalable Vector Graphics
|
||||
# files. It applies a series of transformation rules (plugins), which can be
|
||||
# toggled individually.
|
||||
|
||||
# Optimize a file using the default plugins (overwrites the original file):
|
||||
# Optimize a file using the default plugins, overwriting the original file.
|
||||
svgo test.svg
|
||||
|
||||
# Optimize a file and save the result to another file:
|
||||
# Optimize a file and save the result to another file.
|
||||
svgo test.svg test.min.svg
|
||||
|
||||
# Optimize all SVG files within a folder (overwrites the original files):
|
||||
svgo -f path/to/folder/with/svg/files
|
||||
# Optimize all SVG files within a directory, overwriting the original files.
|
||||
svgo -f path/to/directory/with/svg/files
|
||||
|
||||
# Optimize all SVG files within a folder and save the resulting files to another folder:
|
||||
svgo -f path/to/input/folder -o path/to/output/folder
|
||||
# Optimize all SVG files within a directory and save the resulting files to
|
||||
# another directory.
|
||||
svgo -f path/to/input/dir -o path/to/output/dir
|
||||
|
||||
# Optimize SVG content passed from another command, and save the result to a file:
|
||||
# Optimize SVG content passed from another command, then save result to a file.
|
||||
cat test.svg | svgo -i - -o test.min.svg
|
||||
|
||||
# Optimize a file and print out the result:
|
||||
# Optimize a file and print out the result.
|
||||
svgo test.svg -o -
|
||||
|
||||
# Optimize a file making sure a given plugin is enabled:
|
||||
# Optimize a file making sure a given plugin is enabled.
|
||||
svgo --enable=plugin_name
|
||||
|
||||
# Show available plugins:
|
||||
# Show available plugins.
|
||||
svgo --show-plugins
|
||||
|
Loading…
Reference in New Issue