App-Cheats

 view release on metacpan or  search on metacpan

cheats.txt  view on Meta::CPAN

E[A|='V']

# Matches all elements with tag name E that have attribute A whose value
# is equal to V or contains V delimited by spaces (JQuery,Selectors,Attribute,Table 2.3)
E[A~='V']

# Matches all elements with tag name E that have attributes that satisfy
# the criteria C1 and C2 (JQuery,Selectors,Attribute,Table 2.3)
E[C1][C2]


#############################################################
## JQuery Selectors - Position Filters. Table 2.4 (None are in CSS.)
#############################################################

# Selects the first match within the context. li a:first returns the first
# anchor that’s a descendant of a list item. (JQuery,Selectors,Position Filters,Table 2.4)
:first

# Selects the last match within the context. li a:last returns the last anchor
# that’s a descendant of a list item. (JQuery,Selectors,Position Filters,Table 2.4)
:last

# Selects even elements within the context. li:even returns every even-indexed
# list item.  (JQuery,Selectors,Position Filters,Table 2.4)
:even

# Selects odd elements within the context. li:odd returns every oddindexed
# list item.  (JQuery,Selectors,Position Filters,Table 2.4)
:odd

# Selects the nth matching element. (JQuery,Selectors,Position Filters,Table 2.4)
:eq(n)

# Selects elements after the nth matching element (the nth element is excluded).
# (JQuery,Selectors,Position Filters,Table 2.4)
:gt(n)

# Selects elements before the nth matching element (the nth element is excluded).
# (JQuery,Selectors,Position Filters,Table 2.4)
:lt(n)


#############################################################
## JQuery Selectors - Child Filters. Table 2.5 (All are in CSS.)
#############################################################

# Matches the first child element within the context (JQuery,Selectors,Child,Filters,Table 2.5)
:first-child

# Matches the last child element within the context (JQuery,Selectors,Child,Filters,Table 2.5)
:last-child

# Matches the first child element of the given type (JQuery,Selectors,Child,Filters,Table 2.5)
:first-of-type

# Matches the last child element of the given type (JQuery,Selectors,Child,Filters,Table 2.5)
:last-of-type

# Matches the nth child element, even or odd child elements, or nth child element
# computed by the supplied formula within the context based on the given parameter
# (JQuery,Selectors,Child,Filters,Table 2.5)
:nth-child(n),:nth-child(even|odd),:nth-child(Xn+Y)

# Matches the nth child element, even or odd child elements, or nth child element
# computed by the supplied formula within the context, counting from the last to
# the first element, based on the given parameter (JQuery,Selectors,Child,Filters,Table 2.5)
:nth-last-child(n),:nth-last-child(even|odd),:nth-last-child(Xn+Y)

# Matches the nth child element, even or odd child elements, or nth child element
# of their parent in relation to siblings with the same element name
# (JQuery,Selectors,Child,Filters,Table 2.5)
:nth-of-type(n),:nth-of-type(even|odd),:nth-of-type(Xn+Y)

# Matches the nth child element, even or odd child elements, or nth child element
# of their parent in relation to siblings with the same element name, counting from
# the last to the first element (JQuery,Selectors,Child,Filters,Table 2.5)
:nth-last-of-type(n),:nth-last-of-type(even|odd),:nth-last-of-type(Xn+Y)

# Matches the elements that have no siblings (JQuery,Selectors,Child,Filters,Table 2.5)
:only-child

# Matches the elements that have no siblings of the same type#
 (JQuery,Selectors,Child,Filters,Table 2.5)
:only-of-type


#############################################################
## JQuery Selectors - Form Filters. Table 2.6
#############################################################

# Selects only button elements (input[type=submit], input[type=reset], input[type=button],
# or button) (JQuery,Selectors,Form,Filters,Table 2.6)
:button

# Selects only check box elements (input[type=checkbox])
# (JQuery,Selectors,Form,Filters,Table 2.6)
:checkbox

# Selects check boxes or radio elements in the checked state or options of select
# elements that are in a selected state (JQuery,Selectors,Form,Filters,Table 2.6)
:checked

# Selects only elements in the disabled state (JQuery,Selectors,Form,Filters,Table 2.6)
:disabled

# Selects only elements in the enabled state (JQuery,Selectors,Form,Filters,Table 2.6)
:enabled

# Selects only file input elements (input[type=file]) (JQuery,Selectors,Form,Filters,Table 2.6)
:file

# Selects elements that have the focus at the time the selector is run
# (JQuery,Selectors,Form,Filters,Table 2.6)
:focus

# Selects only image input elements (input[type=image])
# (JQuery,Selectors,Form,Filters,Table 2.6)
:image

# Selects only form elements (input, select, textarea, button)
# (JQuery,Selectors,Form,Filters,Table 2.6)
:input

# Selects only password elements (input[type=password])
# (JQuery,Selectors,Form,Filters,Table 2.6)

cheats.txt  view on Meta::CPAN

#
# Cached file content (seems to be like slurp mode)
perl -i -0pe 'INIT{$m=`cat marking.txt`} print $m' file1 file2

# GS2 par.txt into a data structure that can be evaled later
cat par.txt | perl -MData::Dumper -ln00e 'next if /^-/; my($t,@c)=split "\n"; $h{$t}=\@c }{ $d=Data::Dumper->new([\%h]); print $d->Terse(1)->Indent(1)->Deparse(1)->Purity(1)->Sortkeys(1)->Dump' > C


#############################################################
## Perl Math
#############################################################

# solve for 12x + 15y + 16z = 281 (perl,regex)
# maximizing x 
local $_ = 'a' x 281;
my $r    = qr{^ 
 (a*)\1{11}
 (a*)\2{14}
 (a*)\3{15}
$}x;
printf "x=%i y=%i z=%i\n", 
map{length}/$r/;
__END__
x=17 y=3 z=2

# Solve an algebra problem. get all solutions to: 3x + 4y + 5z = 100
perl -lE '("a"x100) =~ /^(a*)\1{2}(a*)\2{3}(a*)\3{4}$(?{ printf "3x+4y+5z=100 (x=%s,y=%s,z=%s)\n", map{length}($1,$2,$3) })(*F)/'

# Solve an algebra problem. get all solutions to: 3x + 4y + 5z = 20
perl -lE '("a"x20) =~ /^(a*)\1{2}(a*)\2{3}(a*)\3{4}$(?{ printf "3x+4y+5z=20 (x=%s,y=%s,z=%s)\n", map{length}($1,$2,$3) })(*F)/'

# View all the permutations of a list (List::Permutor)
perl -le '@a=qw(a b c); @rv=(0..$#a); sub n{@ret=@a[@rv]; @h=@rv; @t=pop @h; push @t,pop @h while @h and $h[-1]>$t[-1]; if(@h){ $x=pop @h; ($p)=grep{$x<$t[$_]}0..$#t; ($x,$t[$p])=($t[$p],$x); @rv=(@h,$x,@t) }else{ @rv=() } @ret} print "@n" while @n=n...

# Find the prime numbers
#
# Generate numbers
n=`perl -le 'print for 1..100'`
#
# Simple and incomplete (will report 0 and 1 as prime. they are not prime by definition)
echo "$n" | perl -nle 'sub is_prime{("N" x shift) !~ /^ (NN+?) \1+ $/x} print if is_prime($_)'
#
# Disallow 0 and 1
echo "$n" | perl -nle 'sub is_prime{("N" x shift) !~ /^ N? $ | ^ (NN+?) \1+ $/x} print if is_prime($_)'
echo "$n" | perl -nle 'sub is_prime{("N" x shift) !~ /^(?:N?|(NN+?)\1+)$/} print if is_prime($_)'
#
# "N" to 1
echo "$n" | perl -nle 'sub is_prime{(1 x shift) !~ /^ 1? $ | ^ (11+?) \1+ $/x} print if is_prime($_)'
echo "$n" | perl -nle 'sub is_prime{(1 x shift) !~ /^1?$|^(11+?)\1+$/} print if is_prime($_)'
echo "$n" | perl -nle 'sub is_prime{(1 x shift) !~ /^(?:1?|(11+?)\1+)$/} print if is_prime($_)'
#
# Deparse commands
echo "$n" | perl -MO=Deparse -nle 'sub is_prime{("N" x shift) !~ /^ (NN+?) \1+ $/x} print if is_prime($_)'
#
# Debug Regex 1
echo "$n" | perl -nle 'sub is_prime{($n)=@_; ("N" x $n) !~ /^ (NN+?) (?{ print "Trying: $n. Grouping by: $^N" }) \1+ $/x} is_prime($_); print ""'
#
# Debug Regex 2
echo "$n" | perl -Mre=debug -nle 'sub is_prime{("N" x shift) !~ /^ (NN+?) \1+ $/x} print if is_prime($_)'

# Calculate pi using the formula:
# pi = SUMMATION(x:0.5 to 0.5): 4 / (1 + x^2)
perl -le '$int = 5; $h = 1/$int; for m^C$i(1..$int){ my $x = $h * ($i - 0.5); $sum += 4 / (1 + $x**2) }; $pi = $h * $sum; print $pi'

# Example of having true value that is numerically 0.
# Documented in: perldoc perlfunc
# Can also use "0E0".
perl -wE '
    $_ = "0 but true";
    printf "numeric=%d, bool=%s string=%s\n",
        0+$_,
        !!$_,
        "".$_;
'
numeric=0, bool=1 string=0 but true

# Special string to represent infinity.
perl -E 'say "nan" == "nan"' # false
perl -E 'say "nan" eq "nan"' # true
perl -E 'say "Inf" + 1'

# Inf and Infinity are similar.
perl -E 'say "Inf" == "Inf"'            # 1
perl -E 'say "Inf" == "Infinity"'       # 1
perl -E 'say "Infinity" == "Infinity"'  # 1

# v5.32 allows chaines comparisons.
# The comparison variable is evaluated only once.
perl -E 'say 1 < 2 < 3 < 4'     # 1
perl -E 'say 1 < 2 < 3 == 4'    # ""

# Can use eval in perl for doing basic arithmetic (math)
for(qw (+ - * /)){
  my $exp = "3 $_ 3";
  my $ans = eval "$exp";
  print "$exp = $ans\n";
}

# In perl to  get  the  log  of  another  base,
# use  basic  algebra: the base-N  log
# of  a  number  is  equal  to  the
# natural  log  of  that  number  divided
# by the natural log of  N. For example:
sub log10 {
  my $n = shift;
  return log($n)/log(10);
}

# Perl Math
# For other bases, use the mathematical
# identity: log
# log_B(N) = log_e(N) / log_e(B)
# where x is the number whose logarithm you want,
# n is the desired base, and e is the natural
# logarithm base.
sub log_base {
  my ($base, $value) = @_;
  return log($value)/log($base);
}

# Calculate GCD and LCM using euclids formula.
perl -E '
    $_m = $m = 35;
    $_n = $n = 20;
    while ( 1 ) {
        say "$m, $n, ", ($_m * $_n / $m);
        last if !$n;
        ($m,$n) = ($n, $m % $n);
    }
'
35, 20, 20
20, 15, 35
15, 5, 46.6666666666667
5, 0, 140

# Factorial recursive.
perl -E 'sub factorial { my ($n) = @_; return 1 if $n <= 1; $n * factorial($n-1) } say factorial(4)'
24

# Factorial non-recursive.
perl -E 'sub factorial { my ($n) = @_; my $f = 1; $f *= $_ for 1..$n; $f } say factorial(4)'
24
perl -E 'sub factorial { my ($n) = @_; my $f = 1; $f *= $n-- while $n > 1; $f } say factorial(4)'
24


#############################################################
## Perl Math - Trigonometry
#############################################################

# Generate a sine/cosine wave.
perl -E 'my $i=0; while(1) { my $sin = sin $i; my $cos = cos $i; my @spots = map { int($_*20+20) } $sin, $cos; my $dots = " " x 40; substr $dots, $_, 1, "." for @spots; say "$dots [$i] @spots"; $i+=0.25; last if $i > 100 }'
                    .                   . [0] 20 40
                        .              . [0.25] 24 39
                             .       .   [0.5] 29 37
                                 ..      [0.75] 33 34
                              .     .    [1] 36 30
                          .           .  [1.25] 38 26
                     .                 . [1.5] 39 21
                .                      . [1.75] 39 16
           .                          .  [2] 38 11
       .                           .     [2.25] 35 7
   .                           .         [2.5] 31 3
 .                         .             [2.75] 27 1
.                     .                  [3] 22 0
.                .                       [3.25] 17 0
 .          .                            [3.5] 12 1
   .    .                                [3.75] 8 3
    . .                                  [4] 4 6
  .        .                             [4.25] 2 11
.              .                         [4.5] 0 15
.                   .                    [4.75] 0 20
.                        .               [5] 0 25
  .                           .          [5.25] 2 30
     .                            .      [5.5] 5 34
         .                           .   [5.75] 9 37
              .                        . [6] 14 39
                   .                   . [6.25] 19 39
                        .              . [6.5] 24 39


cheats.txt  view on Meta::CPAN


#############################################################
## Perl Modules - Email::Outlook::Message
#############################################################

# Parse an outlook message .msg file
perl -MEmail::Outlook::Message -le 'print Email::Outlook::Message->new(shift)->to_email_mime->as_string' "$m"


#############################################################
## Perl Modules - Enbugger
#############################################################

# Using a read,evaluate,print,loop in perl.
# Not updated since 2014 and failing to build.


#############################################################
## Perl Modules - Encode
#############################################################

# Example of using Encode to show string in different supported encodings (broken).
perl -C -MEncode -E '$s1="Ue: Ü"; $s2="Euro: \N{EURO SIGN}"; for ( encodings ) { printf "%-15s: [%-7s] [%s]\n", $_, encode($_,$s1), encode($_,$s2) }'

# Why use Encode?
perl -E 'say "\xe1"'    # �
perl -C -E 'say "\xe1"' # á
perl -MEncode -E 'say encode "UTF-8", "\xe1"' # á
perl -MEncode -E 'use open ":std", ":encoding(UTF-8)"; say "\xe1"' # á
perl -MEncode -E 'use open qw(:std :utf8); say "\xe1"' # á

# Mixed up encoding.
perl -MEncode -E '$s = encode("UTF-8","é", Encode::FB_CROAK|Encode::LEAVE_SRC); say length($s) . " $s"'
4 é
perl -C -MEncode -E '$s = encode("UTF-8","é", Encode::FB_CROAK|Encode::LEAVE_SRC); say length($s) . " $s"'
4 é
perl -Mutf8  -MEncode -E '$s = encode("UTF-8","é", Encode::FB_CROAK|Encode::LEAVE_SRC); say length($s) . " $s"'
2 é
perl -C -Mutf8  -MEncode -E '$s = encode("UTF-8","é", Encode::FB_CROAK|Encode::LEAVE_SRC); say length($s) . " $s"'
2 é

# Decoding example.
perl -C -MEncode -E 'say decode("UTF-8", chr(0xc3).chr(0xa9), Encode::FB_CROAK)'
é


#############################################################
## Perl Modules - Excel::Writer::XLSX
#############################################################

# Excel - Simple: Generate a blank xlsx file
perl -MExcel::Writer::XLSX -E "$wb = Excel::Writer::XLSX->new('my.xlsx'); $wb->close"

# Excel - Simple: Check for errors openning an excel file and write to a cell
# Also rename the worksheet
perl -MExcel::Writer::XLSX -E "$wb = Excel::Writer::XLSX->new('my.xlsx') or die qq($!\n); $ws = $wb->add_worksheet('my'); $ws->write('A1', 'Hello Excel'); $wb->close"

# Excel - Simple: Add a format to make a cell bold
perl -MExcel::Writer::XLSX -E "$wb = Excel::Writer::XLSX->new('my.xlsx') or die qq($!\n); $ws = $wb->add_worksheet('my'); $format = $wb->add_format; $format->set_bold; $ws->write(0, 0, 'Hello Excel', $format); $wb->close"

# Create a spreadsheet/excel with formulas using perl (only on lnxbr42)
perl -MExcel::Writer::XLSX -le '
   $wb=Excel::Writer::XLSX->new("new.xlsx");
   $ws=$wb->add_worksheet;
   $ws->write("A1","In Excel");
   $ws->write("B2",3);
   $ws->write("B3",4);
   $ws->write("B4","=B2+B3");
   $ws->write("B5","=SUM(B2:B4)");
   $wb->close
'

# Create a spreadsheet/excel with color formats using perl (only on lnxbr42)
perl -MExcel::Writer::XLSX -le '
   $wb=Excel::Writer::XLSX->new("new2.xlsx");
   $ws=$wb->add_worksheet;
   $format=$wb->add_format(color => 'red');
   $ws->write("A1","No Color");
   $ws->write("A2","Red Color", $format);
   $wb->close
'

# Create a spreadsheet/excel with color formats using perl (only on lnxbr42). same thing
perl -MExcel::Writer::XLSX -le '
   $wb=Excel::Writer::XLSX->new("new2.xlsx");
   $ws=$wb->add_worksheet;
   $ws->write("A1","No Color");
   $ws->write("A2","Red Color", $wb->add_format(color => 'red'));
   $wb->close
'


#############################################################
## Perl Modules - File::Copy
#############################################################

# Copy using perl
perl -MFile::Copy -lE 'copy("abc2","abc3")'


#############################################################
## Perl Modules - File::Find
#############################################################

# find2perl.pl script.
use File::Find;
use e;
our ($name);
*name  = *File::Find::name;
*find  = *File::Find::find;
find( {
        wanted => sub { say $name if /tri/ },
    },
    '.'
);


#############################################################
## Perl Modules - File::Tee
#############################################################

cheats.txt  view on Meta::CPAN

#############################################################
## WII
#############################################################

# Write files/games to WII.
https://mariokartwii.com/showthread.php?tid=121
https://www.gametdb.com/Wii/Search


#############################################################
## Windows Bugs
#############################################################

# Windows stuck in control mode (Tobias Wulf,windows bug)
Recovery: Most of the time, Ctrl + Alt + Del re-sets key status
to normal if this is happening. (Then press Esc to exit system screen.)
Another method: You can also press stuck key: so if you clearly see that
it is Ctrl which got stuck, press and release both left and right Ctrl .

# Why I have to press keys two times to get the ^ or ´ or ` (windows bug)
With this keyboard layout the ^ keystroke becomes a modifier to
enabling entering of special characters.
To get a single ^ character you will need to type ^+Space.


#############################################################
## Windows Command Prompt (DOS)
#############################################################

# Set an environmental variable (DOS)
setx <variable> <value>

# Unset an environmental variable (DOS)
setx <variable> ""

# Append path environmental variable (DOS)
setx path "new_dir_to_append"

# Change the width and height of a DOS window
mode con: cols=120 lines=20


#############################################################
## Windows - Drives
#############################################################

# Get mapped windows drives
net use

# Map windows drives
net use k: \\path /persistent:yes


#############################################################
## Windows - Excel
#############################################################

# Get last row in an excel column
=MATCH(TRUE,INDEX($K$3:$K$22="",0),0)-1

# Show excel formulas
Ctrl + `

# Insert the current date
Ctrl + :

# Insert the current time
Ctrl + Shift + :

# Drag excel column
Ctrl + r

# Drag excel row
Ctrl + d


#############################################################
## Windows - Filesystem
#############################################################

# /etc/hosts on Windows
C:\Windows\System32\drivers\etc

# Check if a program on Windows is 32 or 64 bit (objdump,stat,file)
Control + Shift + ESC
-> More Details
-> "Details" tab
Right Click
Select Columns
Platform
#
# Another way
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\bin\Hostx64\x64\dumpbin" /headers hinstall.exe | findstr machine

# Find windows start location folder (autostart scripts)
Windows + R
type:
	shell:startup
    shell:common startup

# Delete a deeply nested folder on Windows
cd bad_dir
mkdir empty
robocopy empty bad_dir /mir 	:: mirror blank directory over nested
rmdir empty bad_dir

# Question:
# What differences are between Authenticated Users, SYSTEM, Administrators
# (ADMIN\Administrators), and Users (ADMIN\Users) (Windows 10)
#
# Answer:
# They are all default users and groups Windows uses to maintain
# permissions, typically for security purposes.
#
# Authenticated Users is a pseudo-group (which is why it exists, but is not
# listed in Users & groups), it includes both Local PC users and Domain users.
#
# SYSTEM is the account used by the operating system to run services,
# utilities, and device drivers. This account has unlimited power and access
# to resources that even Administrators are denied, such as the Registry's SAM.
#



( run in 1.487 second using v1.01-cache-2.11-cpan-2398b32b56e )