App-Cheats

 view release on metacpan or  search on metacpan

cheats.txt  view on Meta::CPAN

# Switch between windows/terminal in Rasberry Pi (pi)
Alt + Tab

# Force a hard reboot that may cause a "Connection Reset by Peer" Error
sudo reboot -f
Alt + Druck + b

# Get control back of linux, save data and reboot (stuck,terminal)
#
# 1. Hold down the Alt and SysRq (Print Screen) keys.
# 2. While holding those down, type the following keys in order, several seconds apart: R E I S U B
# 3. Computer should reboot.
# unRaw      (take control of keyboard back from X),
#  tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
#  kIll      (send SIGKILL to all processes, forcing them to terminate immediately),
#   Sync     (flush data to disk),
#   Unmount  (remount all filesystems read-only),
# reBoot.


#############################################################
## PostgreSQL (psql)
#############################################################

# Install psql
sudo apt install postgresql postgresql-contrib postgresql-server-dev-13 gcc
sudo apt-get install libdbd-pg-perl
cpan DBD::Pg


#############################################################
## Powershell
#############################################################

# Regular Expression Named Capture in Powershell
"  dev   master * release/2.00" -match "release/(?<MAJOR>\d+)\.(?<MINOR>\d+)"
echo $Matches
echo $Matches.MAJOR
echo $Matches.MINOR


#############################################################
## Python General
#############################################################

# Zen of Python (motto)
python -c 'import this'
# The Zen of Python, by Tim Peters
#
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those


#############################################################
## Python Compare
#############################################################

# Increment a list of numbers (compare)
python -c 'L=map((lambda x:x+10),[1,2,3,4]); print L'
perl -le '@L=map{$_+10}(1,2,3,4); print "@L"'
perl -le '@L=map{$_+10} 1,2,3,4; print "@L"'
perl -le '@L=map{$_+10} 1..4; print "@L"'

# Get the ordinal values of a string (compare)
python -c 'res=list(map(ord,"spam")); print res'
python -c 'res=[ord(x) for x in "spam"]; print res'
perl -le '@L=map ord, split "", "spam"; print "@L" '
perl -le '@L=map{ord} split "", "spam"; print "@L" '

# Square all numbers in a list (compare)
python -c 'A=list(map((lambda x: x**2), range(10))); print A'
python -c 'A=[x**2 for x in range(10)]; print A'
perl -le '@A=map{$_**2}0..9; print "@A"'

# Square all even numbers
python -c 'A=list(map((lambda x: x**2), filter((lambda x: x%2 == 0), range(10)))); print A'
python -c 'A=[x**2 for x in range(10) if x%2 == 0]; print A'
perl -le '@A=map{$_**2} grep{$_ % 2 == 0} 0..9; print "@A"'

# Add 2D lists (compare)
python -c 'A=[x + y for x in [0,1,2] for y in [100,200,300]]; print A'
perl -le '@A=map{$x=$_; map{$x+$_}100,200,300 }0,1,2; print "@A"'
perl -le 'local $,="+"; @A=map eval, <{0,1,2}+{100,200,300}>; print "@A"'

# Add 3D lists (compare)
python -c 'A=[x + y + z for x in [0,1,2] for y in [100,200,300] for z in [1000,2000,3000]]; print A'
perl -le '@A=map{$x=$_; map{$y=$_; map{$x+$y+$_}1000,2000,3000  }100,200,300 }0,1,2; print "@A"'
perl -le 'local $,="+"; @A=map{eval}<{0,1,2}+{100,200,300}+{1000,2000,3000}>; print "@A"'
perl -le 'local $,="+"; @A=map eval, <{0,1,2}+{100,200,300}+{1000,2000,3000}>; print "@A"'

# Add 4D lists (compare)
python -c 'A=[x + y + z + aa for x in [0,1,2] for y in [100,200,300] for z in [1000,2000,3000] for aa in [10000,20000]]; print A'
perl -le '@A=map{$x=$_; map{$y=$_; map{$z=$_; map{$x+$y+$z+$_}10000,20000  }1000,2000,3000  }100,200,300 }0,1,2; print "@A"'
perl -le 'local $,="+"; @A=map eval, <{0,1,2}+{100,200,300}+{1000,2000,3000}+{10000,20000}>; print "@A"'

# Interate through list combinations
python -c 'A=[x+y for x in "spam" for y in "SPAM"]; print A'
perl -le '@A=<{s,p,a,m}{S,P,A,M}>; print "@A"'
perl -le '@A=<{@{[join ",",split //,"spam"]}}{@{[join ",",split //,"SPAM"]}}>; print "@A"'

# Max constant for using glob (permutations)
perl -MPOSIX -le 'print POSIX::sysconf(_SC_ARG_MAX)'

# Add 2D lists with conditionals (compare)



( run in 0.737 second using v1.01-cache-2.11-cpan-5511b514fd6 )