App-Cheats

 view release on metacpan or  search on metacpan

cheats.txt  view on Meta::CPAN

#############################################################

# Start new tmux
tmux

# Start new tmux withh a session name
tmux new -s SESSION_NAME

# Attach to a tmux
tmux a -t SESSION_NAME_OR_NUMBER

# List tmux sessions
tmux ls

# Kill tmux session
tmux kill-session -t SESSION_NAME_OR_NUMBER

# Kill all tmux sessions (NOT PERMITTED)
tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill

# Control-b help tmux menu
Control-b ?

# Dettach from a tmux session
Control-b d

# Kill all tmux sessions
tmux ls | perl -aF: -ne 'qx(tmux kill-session -t $F[0])'


#############################################################
## Linux Commands - touch
#############################################################

# Changes a timestamp to be a specific date
touch $FILE -d 'Feb 11 2015'
touch $FILE -d 'Apr 11 2017 10:11'


#############################################################
## Linux Commands - tr
#############################################################

# Remove all extra spaces in a line (squash)
echo " a    f    " | tr -s " "

# Convert a string to lower case (change case)
echo ABd | tr [:upper:] [:lower:]

# Convert a string to upper case (change case)
echo Abd | tr [:lower:] [:upper:]


#############################################################
## Linux Commands - useradd
#############################################################

# Create a new user account for BENCH
uid=$UID
user=SOME_USER
gid=123
/usr/sbin/useradd -u $uid -g $gid -d /home/$user -m $user
passwd SOME_USER          # asdf1234

# Create new user accounts
i=1001
for u in potapov SOME_USER; do
   /usr/sbin/useradd -u $i -g systems -d /home3/$u -m $u -s /bin/bash
   let "i++"
done
# run 'passwd $u' for each user

# Change default shell of current user (or use useradd -s /bin/bash)
chsh -s /bin/bash


#############################################################
## Linux Commands - userdel
#############################################################

# Remove all users accounts in a list
# $a contains a list of "username - home_directory"
echo "$a" | while read u h; do echo -e "\n# Deleting $u\n"; sudo userdel -r $u; done


#############################################################
## Linux Commands - usermod
#############################################################

# Change group id of a user (DES,gid)
sudo usermod -g 1000 potapov

# Change user id of a user (DES,uid)
sudo usermod -u 10285 potapov

# Add user to a new group/groups (passwd)
Log unto fs01
sudo usermod -a -G controls,system potapov
sudo make -C /var/yp

# Change the shell for a specific user
sudo usermod -s /bin/bash potapov   # can specify user here

# Change full name in passwd file
sudo usermod -c "Last First" xbeXXXX

# Change home directory
Log unto fs01
cd /home3
sudo usermod -d /home4/xbe4092 xbe4092

# Move home directory
Log unto fs01
sudo usermod -d /home4/xbe4092 -m xbe4092

# Add/append group to user
# Current user would need to log out and in again
# for changes to take effect.
sudo usermod -a -G GROUP_NAME USER
#
# A way to temporarily apply new group.
sudo su $USER


#############################################################
## Linux Commands - watch
#############################################################

# Watch the UI sessions
watch -d -n1 screen -list

# Alias command to watch all the files in the current directory for changes
alias watch_files='watch ls -alF'


#############################################################
## Linux Commands - wget
#############################################################

# Pass through wget firewall/proxy (Download)
read -sp "Password: " PASSWORD
export http_proxy=http://xbe4092:$PASSWORD@pratt-proxyva.utc.com:8080/
export https_proxy=http://xbe4092:$PASSWORD@pratt-proxyva.utc.com:8080/
# If password contains special characters (like #,@ ...)


#############################################################
## Linux Commands - whereis
#############################################################

cheats.txt  view on Meta::CPAN

      \?) echo "undefined option -$OPTARG"; exit 1;;
  esac
done


#############################################################
## Bash - Conditions
#############################################################

# If else condifion in bash on a single line
if [ $a -gt 0 ]; then echo -e $a; else echo $a; fi

# Case (switch) statement. Run of the possiblities (bash)
var="aaa"
   case $var in
   aaa) echo 10 ;;
   bbb) echo 20 ;&      # Fallthrough condition.
   ccc) echo 30 ;;
esac

# Bash, multi if elseif (ternary)
a=5
[ $a -gt 3 ] && echo "A" || ([ $a -gt 2 ] && echo "B" || echo "C")
if [ $a -gt 3 ]; then echo "A"; elif [ $a -gt 2 ]; then echo "B"; else echo "C"; fi


#############################################################
## Bash - Expressions
#############################################################

# Check if variable has a value (not empty) (and logic)
[[ ! -z $msg ]] && echo "A"

# Check if variable has a value (not empty)
if [[ ! -z $msg ]]; then echo "A"; fi

# Bash regular expression (regex) comparision
[[ "R_EECB" =~ [LR]_EEC[AB] ]] && echo "A"
[[ ! "L_EECA" =~ [LR]_EEC[AB] ]] && echo "A"

# Check if a file is newer than another file
[ FILE1 -nt FILE2 ] && echo "is newer" || echo "not newer"


#############################################################
## Bash - File Test Operators
#############################################################

# Bash File Test Operators
# Operator syntax           Description
# -a <FILE>  True if <FILE> exists. (not recommended, may collide with -a for AND, see below)
# -e <FILE>  True if <FILE> exists.
# -f <FILE>  True, if <FILE> exists and is a regular file.
# -d <FILE>  True, if <FILE> exists and is a directory.
# -c <FILE>  True, if <FILE> exists and is a character special file.
# -b <FILE>  True, if <FILE> exists and is a block special file.
# -p <FILE>  True, if <FILE> exists and is a named pipe (FIFO).
# -S <FILE>  True, if <FILE> exists and is a socket file.
# -L <FILE>  True, if <FILE> exists and is a symbolic link.
# -h <FILE>  True, if <FILE> exists and is a symbolic link.
# -g <FILE>  True, if <FILE> exists and has sgid bit set.
# -u <FILE>  True, if <FILE> exists and has suid bit set.
# -r <FILE>  True, if <FILE> exists and is readable.
# -w <FILE>  True, if <FILE> exists and is writable.
# -x <FILE>  True, if <FILE> exists and is executable.
# -s <FILE>  True, if <FILE> exists and has size bigger than 0 (not empty).
# -t <fd>  True, if file descriptor <fd> is open and refers to a terminal.
# <FILE1> -nt <FILE2>  True, if <FILE1> is newer than <FILE2> (mtime).
# <FILE1> -ot <FILE2>  True, if <FILE1> is older than <FILE2> (mtime).
# <FILE1> -ef <FILE2>  True, if <FILE1> and <FILE2> refer to the same device and inode numbers.

# Read from either PIPE or from standard input STDIN (in Bash. 0 is STDIN)
[ -t 0 ] && echo "A"
cat file | [ -t 0 ] && echo "A"

# Read from either PIPE or from standard input STDIN (in Bash. 0 is STDIN)
if [ -t 0 ]; then    # RIGHT side
    list=( "$@" )
else                 # LEFT side (PIPE)
    list=($(cat -))
fi

# Detect if piped result.
local piped
# Pipe (from grep).
if [ -p /dev/stdin ]; then
    piped=($(cat -))
fi


#############################################################
## Bash - Functions
#############################################################

# Create a heredoc
cat <<HERE
stuff to print
more stuff
HERE

# Create a heredoc and put in a file (Bash)
cat <<HERE > file
stuff to print
more stuff
HERE

# Create a heredoc and put in a variable (Bash)
my_var=$(cat<<HERE
stuff to print
more stuff
HERE
);

# Get name of current function you are in (bash)
echo $FUNCNAME

# Get name of parent function you are in (bash)
echo ${FUNCNAME[0]}

# Get full stack trace of functions that lead you to current function (bash)
echo ${FUNCNAME[*]}

cheats.txt  view on Meta::CPAN

{
  "593943" => [
    "From-1"
  ],
  "593944" => [
    "From-2"
  ],
  "593945" => [
    "From-3"
  ],
  "593946" => [
    "From-4"
  ],
  "593947" => [
    "From-5"
  ]
}

# Run multiple processes and collect their data (no debug output).
perl -MMojo::Util=dumper -E 'use strict; use warnings; local $| = 1; my @Wait; for my $Count (1..200){ my($In,$Out); pipe($In,$Out); my $PID = fork; if (!$PID){ close $In; sleep int(rand(5)); say $Out "From-$Count"; close $Out; exit 0 } close $Out; p...

# Run multiple processes and collect their data.
# Sends a structure back from the children.
perl -Mojo -E 'local $| = 1; my @Wait; for my $Count (1..5){ my($In,$Out); pipe($In,$Out); my $PID = fork; if (!$PID){ close $In; sleep int(rand(5)); say $Out j { Title => "From-$Count", Count => $Count }; close $Out; exit 0 } close $Out; push @Wait,...
{
  "1" => {
    "ChildPid" => 28843,
    "Count" => 1,
    "Title" => "From-1"
  },
  "2" => {
    "ChildPid" => 28844,
    "Count" => 2,
    "Title" => "From-2"
  },
  "3" => {
    "ChildPid" => 28845,
    "Count" => 3,
    "Title" => "From-3"
  },
  "4" => {
    "ChildPid" => 28846,
    "Count" => 4,
    "Title" => "From-4"
  },
  "5" => {
    "ChildPid" => 28847,
    "Count" => 5,
    "Title" => "From-5"
  }
}

# Process killing example:
perl -E '$pid = fork; if (!$pid){ say "[$$] child", sleep 1 while 1 } else {  say "[$$] parent"; waitpid $pid, 0; say "[$$] parent end" }'
perl -E '$pid = fork; if (!$pid){ say "[$$] child", sleep 1 while 0; say "start"; system qq(google-chrome --headless --virtual-time-budget=15000 --window-size=200,200 --screenshot=$ENV{HOME}/Downloads/my.png log); say "wait"; sleep 10 } else {  say "...
#
perl -E 'for ( shift ) { say kill 0, $_; sleep 1; say kill -9, $_; sleep 1; say kill 0, $_ }' 3022126


#############################################################
## Perl Functions - getpwnam, getgrent, getgrnam, getgrgid
#############################################################

# UID in scalar context, all fields in list
perl -lE '$a=getpwnam("<USER>"); say $a'
perl -lE 'say for getpwnam("<USER>")'

# Group name entry
perl -lE 'say getgrent'

# Get name
perl -lE 'say for getgrnam("systems")'

# Group ID
perl -lE 'say for getgrgid("systems")'

# Get password file entry for a username (check if they exist)
perl -le 'print for getpwnam "<USER>"'


#############################################################
## Perl Functions - local
#############################################################

# Can use local actually with a lexical/my variable.
perl -Mojo -E 'my %h; { local $h{abc}=1; say r \%h } say r \%h'
perl -Mojo -E 'my %h; sub show { say "show: " . r \%h } { local $h{abc}=1; show() } show()'
show: {
  "abc" => 1
}
show: {}

# Comparing lexical and global (quite similar).
perl -E 'sub show { my ($ref) = @_; say "$ref $$ref" } my $my = 111; our $our = 222; show \$my; show \$our; { my $my = 112; local $our = 223; show \$my; show \$our } show \$my; show \$our'                                SCALAR(0xb4000075870a0168) 111...
SCALAR(0xb4000075870a0198) 222
SCALAR(0xb4000075870a1498) 112
SCALAR(0xb40000758701f678) 223
SCALAR(0xb4000075870a0168) 111
SCALAR(0xb4000075870a0198) 222


#############################################################
## Perl Functions - msgsnd, msgrcv
#############################################################

# Send and receive message from the queue (IPC)
perl -le 'msgsnd 99483684, "123456789", 0'
perl -le 'msgrcv 99483684, $var, 24, 0, 0; print "[$var]"'


#############################################################
## Perl Functions - ord
#############################################################

# Show ascii ordinal values
perl -E "say qq($_ ) . chr for 1..227"
perl -E "say qq($_ = ) . ord for qw/ a A ä ö ü ß /"


#############################################################
## Perl Functions - select
#############################################################

# Show the currently selected file handle.
perl -E 'say select'
main::STDOUT


#############################################################
## Perl Functions - split
#############################################################

# Idiom to collapse whitespace.
perl -E 'say for split " ", "   i have so many spaces   here  "'
i

cheats.txt  view on Meta::CPAN

# M - is a controller number (0-3). corresponds to the CPU
# board on which the clock resides
# c - stands for clock
# N - specifies a real-time clock number (0-4 on the first CPU board,
#     and 0-2 on additional CPU boards)

# RTCP Commands (DES)
ats    Attach timing source to an FBS
chs    Change permissions for an FBS
cs     Configure an FBS
dts    Detach timing source from an FBS
rms    Remove an FBS
svs    Save scheduler configuration
vc     View minor cycle/major frame count
vr     View a rdevfs file configuration
vs     View scheduler configuration
rc     Start real-time clock
rd     Register a Coupled FBS device
sc     Stop real-time clock
stc    Set real-time clock values
gtc    Get real-time clock values
start  Start scheduling on an FBS
reg    Register a Closely-Coupled FBS timing device
resume Resume scheduling on an FBS
stop   Stop scheduling on an FBS
rmp    Remove a process from an FBS
rsp    Reschedule a process
sp     Schedule a process on an FBS
unreg  Unregister a Closely-Coupled FBS timing device
urd    Unregister a Coupled FBS device
vp     View processes on an FBS
pm     Start/stop performance monitoring
cpm    Clear performance monitor values
vcm    View or modify performance monitor timing mode
vpm    View performance monitor values
ex     Exit real-time command processor
he     Display help information

# RTCP Options (DES,rtcp he options)
-a               remove program from FBS and terminate
-b {F|R|O}       scheduling policy
-c cpu_bias      cpu bias (* = all CPUs) (default = current CPU)
-d name          devicename or filename
-e               EOC flag
-f frequency     number of minor cycles to next wakeup (default = 1)
-h {halt|nohalt} halt FBS on deadline violation (default = nohalt)
-i fpid          process fpid number  (default = -1)
-m start_cycle   1st minor cycle to wakeup  (default = 0)
-n proc_name     process name
-o {halt|nohalt} halt FBS on overrun flag (default = nohalt)
-p priority      process priority
-r {cycle|task}  deadline origin flag  (default = cycle)
-s scheduler     FBS scheduler key
-t {in|ex}       include or exclude interrupt time in pm monitor
-v parameter     process initiation parameter
-x {av|mi|ma|al} performance monitor display option (default = average)

# RTCP Options (DES,rtcp he opt2)
-C cycles/frame  number of minor cycles per major frame
-D duration      clock tick duration  (default = 10us)
-G gid           effective group ID for FBS  (default = current user)
-I permissions   permissions for FBS in octal  (default = 0600)
-L soft_limit    soft overrun limit  (default = 0)
-M progs/cycle   maximum number of processes per minor cycle
-N progs/fbs     maximum number of processes per FBS
-O clock_ticks   number of clock ticks per minor cycle
-P {ON|OFF}      enable/disable performance monitor (default = OFF)
-R {-1 | 0 | 1}  reset process flag  (default = 0)
-S delay         time to delay, in seconds
-T deadline      deadline microseconds (default = "Clear")
-U uid           effective user ID for FBS  (default = current user)
-W tick_count    #ticks before watchdog RTC takes over(special devices)

# RTCP syntax for a command (DES)
# rtcp he <command>
rtcp he ats
rtcp he start
rtcp he sp

# RTCP pass arguments to a process (DES)
# Use "--" to pass everything after to the process
# sys requires "-dt 1000" be passed to it.
rtcp sp -s 1 -n ~/run/sys -- -dt 1000

# Monitor rtcp status, which programs are attached, (DES)
# ipcx, simsec keys, and commands to rtcp "arg*"
watch -d -n1 -t "rtcp ls; rtcp vp -s 1 -c '*'; ipcx; ls -l /dev/keys/simsec; grep '' arg*"


#############################################################
## Ruby
#############################################################

# Check all of the ruby libraries for puppet
ruby -e 'puts $:' | while read n; do ll -d $n/*puppet* 2> /dev/null; done


#############################################################
## Selenium Testing
#############################################################

# Python script to run a simple selenium test
#
+ #!/usr/bin/python3
+
+ import time
+ from selenium import webdriver
+
+ driver = webdriver.Chrome()  # Optional argument, if not specified will search path.
+ driver.get('http://www.google.com');
+ time.sleep(2)
+
+ elem = driver.find_element_by_name('q')
+ elem.send_keys('ChromeDriver')
+ elem.submit()
+ time.sleep(2)
+
+ driver.quit()

# Perl script to run a simple selenium test
# Requires having the selenium to be already running:



( run in 1.432 second using v1.01-cache-2.11-cpan-97f6503c9c8 )