App-Cheats
view release on metacpan or search on metacpan
:selected
# Selects only submit buttons (button[type=submit] or input[type=submit])
# (JQuery,Selectors,Form,Filters,Table 2.6)
:submit
# Selects only text elements (input[type=text]) or input without a type specified
# (because type=text is the default) (JQuery,Selectors,Form,Filters,Table 2.6)
:text
#############################################################
## JQuery Selectors - Content Filters. Table 2.7
#############################################################
# Selects only elements containing the specified text (the text of the children and
# the descendants is also evaluated). (JQuery,Selectors,Content,Filters,Table 2.7)
:contains(text)
# Selects only elements that have no children (including text nodes).
# (JQuery,Selectors,Content,Filters,Table 2.7)
:empty
# Selects only elements that contain at least one element that matches the specified
# selector. (JQuery,Selectors,Content,Filters,Table 2.7)
:has(selector)
# Selects only elements that have at least one child node (either an element or text).
# (JQuery,Selectors,Content,Filters,Table 2.7)
:parent
#############################################################
## JQuery Selectors - Other Filters. Table 2.8
#############################################################
# Selects only elements that are currently under animated control
# (JQuery,Selectors,Other,Filters,Table
# 2,8)
:animated
# Selects only elements that are headers: <h1> through <h6>
# (JQuery,Selectors,Other,Filters,Table
# 2,8)
:header
# Selects only elements that are hidden (JQuery,Selectors,Other,Filters,Table 2,8)
:hidden
# Selects elements in a specified language (JQuery,Selectors,Other,Filters,Table 2,8)
:lang(language)
# Negates the specified selector (JQuery,Selectors,Other,Filters,Table 2,8)
:not(selector)
# Selects the element thatÎÃÃs the root of the document
# (JQuery,Selectors,Other,Filters,Table
# 2,8)
:root
# Selects the target element indicated by the fragment identifier of the documents
# URI (JQuery,Selectors,Other,Filters,Table 2,8)
:target
# Selects only elements that are visible (JQuery,Selectors,Other,Filters,Table 2,8)
:visible
#############################################################
## JQuery - Serialize
#############################################################
# Encode/serialize a key=value using JQuery
obj = {key:"val", comment: "hey there äöü"}
$.param(obj)
#
# This works also, but above is nicer.
$('<input name="comment" value="hey there äöü">').serialize()
# Encode/serialize a key=value using JQuery
# Convert to object
#
function decode_data(data_raw) {
const data_obj = {};
data_raw
.split(/&/)
.forEach( (p) => {
[k,v] = p.split(/=/).map( n => decodeURIComponent(n) );
data_obj[k] = v;
});
return data_obj;
}
#############################################################
## JQuery - SVG
#############################################################
After adding an svg element with jquery, need to reflesh the element
(otherwise it will not render on the screen)
$('.svg_help').html($('.svg_help').html())
class SvgHelper {
// CSS SvgHelper
constructor() {
this.svg_def = {
svg_help: () => { return this.define_svg_help() },
svg_settings: () => { return this.define_svg_settings() },
svg_about: () => { return this.define_svg_about() },
};
this.svg_about_id = 1;
}
// CSS SvgHelper
define_svg_help() {
return $('<svg class="svg_help" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">').append(
$('<path d="M11 18h2v-2h-2v2zm1-16C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm0-14c-2.21 0-4 1.79-4 4h2c0-1.1.9-2 2-2s2 .9 2 2c0 2-3 1.75-3 5h2c0-2.25 3-2.5 3-5 0-2.21-1...
).get(0);
}
0aa
0a
1:
aaab
aaa
aa
a
2:
aab
aa
a
3:
ab
a
# Perl regex verb - THEN (Level1,example)
# Mainly to speed up alternations.
# Otherwise it behaves like *PRUNE.
# Appently not necessary in perl due to other optimizations.
perl -E '"123ABC" =~ / 123 B | .{3} /x; say $&'
perl -E '"123ABC" =~ / 123 (*THEN) B | .{3} /x; say $&'
123
# Perl regex verb - PRUNE (Level2, example)
# Will not backtrack past that point.
# Goes right to next position.
# Similar to a possessive quantifier
perl -E '"123ABC" =~ / 123 (*PRUNE) B | .{3} /x; say $&'
23A
# Perl regex verb - SKIP (Level3, example)
# Like *PRUNE, but also advances the string position to after the failure.
perl -E '"123ABC" =~ / 123 (*SKIP) B | .{3} /x; say $&'
ABC
# Perl regex verb - COMMIT (Level4, example)
# All or nothing.
perl -E '"123ABC" =~ / 123 (*COMMIT) B | .{3} /x; say $&'
perl -E '"123ABC" =~ / 1 (*COMMIT) 23 (*PRUNE) B | .{3} /x; say $&'
# empty
#
# SKIP on right inhibits COMMIT.
perl -E '"123ABC" =~ / 1 (*COMMIT) 23 (*SKIP) B | .{3} /x; say $&'
ABC
# Perl regex verb - MARK,SKIP
perl -E '"123ABC456" =~ / 123 (*MARK:past_digits) [A-Z]+ (*SKIP) 9.. | .* /x; say $&'
456
perl -E '"123ABC456" =~ / 123 (*MARK:past_digits) [A-Z]+ (*SKIP:past_digits) 9.. | .* /x; say $&'
ABC456
# Perl regex verb - MARK
perl -E '"1x2" =~ /(?:x(*MARK:x)|y(*MARK:y)|z(*MARK:z))/; say $^N'
perl -E '"1x2" =~ /(?:x(*MARK:mx)|y(*MARK:my)|z(*MARK:mz))/; say $REGMARK'
# Use atomic script runs to prevent named attacks. (paypal.com,perl regex verb ASR)
perl -C -E 'say "\N{CYRILLIC SMALL LETTER ER}aypal.com" =~ /^\w+\.com$/' # 1
perl -C -E 'say "\N{CYRILLIC SMALL LETTER ER}aypal.com" =~ /(*asr:^\w+\.com$)/' # 0
# Control verb: FAIL versus split.
perl -Me -e 'n { split => sub{ my %c; $c{lc($_)}++ for split("", "supercalifragilisticexpialidocious") }, fail => sub { my %c; "supercalifragilisticexpialidocious" =~ /([aeiou])(?{ $c{$1}++; })(*FAIL)/i } }, 1000000'
Rate fail split
fail 114679/s -- -17%
split 137741/s 20% --
#############################################################
## Perl Regular Expressions - Word Boundary
#############################################################
# Normal word boundary.
perl -E "say for q(Tim's favorite candy) =~ /(\b\w.*?\b)/g"
Tim
s
favorite
candy
# More precise and newer word boundary.
# Available from v5.22.
# https://perldoc.perl.org/perlrebackslash#%5Cb%7B%7D%2C-%5Cb%2C-%5CB%7B%7D%2C-%5CB
perl -E "say for q(Tim's favorite candy) =~ /(\b{wb}\w.*?\b{wb})/g"
Tim's
favorite
candy
# More precise and newer word boundary.
# Only with word like characters
# (not double quotes).
perl -E 'say for q(Tim"s favorite candy) =~ /(\b{wb}\w.*?\b{wb})/g'
Tim
s
favorite
candy
#############################################################
## Perl Signal Handling
#############################################################
# Catch Control-C
perl -lE '$SIG{INT}=sub{die "\n\nYou hit control C\n\n"}; say "Press Enter" and <> while 1'
# Assign many signal handlers
perl -MData::Dumper -lE 'sub pr{my $d=Data::Dumper->new(\@_)->Purity(1); say $d->Dump} $SIG{INT}=sub{die"\nINT\n"}; $SIG{QUIT}=sub{die"\nQUIT\n"}; $SIG{TERM}=sub{die"\nTERM\n"}; $SIG{PIPE}=sub{die"\nPIPE\n"}; $SIG{ALRM}=sub{die"\nALRM\n"}; $SIG{HUP}...
# Assign many signal handlers
perl -MData::Dumper -le 'sub pr{print Data::Dumper->new(\@_)->Deparse(1)->Dump} for my $s(qw/INT QUIT TERM PIPE ALRM HUP CHLD __WARN__ __DIE__/){ $SIG{$s} = sub{die"\n$s\n"}} pr \%SIG; <> while 1'
perl -MData::Dumper -le 'sub pr{print Data::Dumper->new(\@_)->Deparse(1)->Dump} for my $s(keys %SIG){ $SIG{$s} = sub{print "\n$s\n"}} pr \%SIG; print $$; <> while 1'
# Alarm signal handler
perl -le 'for my $s(qw/INT QUIT TERM PIPE ALRM HUP CHLD/){ $SIG{$s} = sub{die"\n$s\n"}} alarm 2; <> while 1'
perl -le '$SIG{ALRM}=sub{die"\n\nEND OF TIME\n\n"}; alarm 1; <> while 1'
# Perl signal handling (eval,die,exit)
perl -E 'eval { exit 1 }; say $@; say "here"' # Blank
perl -E 'eval { exit 0 }; say $@; say "here"' # Same
perl -E 'eval { return 1 }; say $@; say "here"' # Return early from an eval. ürints "here"
perl -E 'eval { die }; say $@; say "here"' # caught die, prints "here"
perl -E 'eval { exit 1 }; say $@; END {say "here"}' # Run before final exit. prints "here"
perl -E 'eval { die }; say $@; END {say "here"}' # Same.
perl -E 'open FH, ">", "file"; say FH "123"; exit 1' # File closed and contains "123"
( run in 1.386 second using v1.01-cache-2.11-cpan-b16cb0d3907 )