App-Cheats

 view release on metacpan or  search on metacpan

cheats.txt  view on Meta::CPAN

# Force Chrome to reload the website and not use the cache (page,renderStatic)
Control + F5

Open the previous page from your browsing history in the current tab (Chrome)
Alt + Left arrow

# Allow running local files in Chrome on Windows 10
# Close all Chrome windows
cd "C:\Program Files (x86)\Google\Chrome\Application"
chrome.exe --allow-file-access-from-files

# Chrome Full Screen Mode
F11

# Create a link in the console which can be opened in the browser (hyperlink,terminal)
using Control+Click
file://absolute_path

# Install Chrome on Ubuntu
#
# Add Key:
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
#
# Set repository:
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list
#
# Install package:
sudo apt-get update
sudo apt-get install google-chrome-stable

# Hide/Show favorites tab in Chrome.
Control + Shift + B


#############################################################
## CSS - Anchor
#############################################################

# CSS to keep an element anchor on the top side
    position: absolute;
    top: 15%;


#############################################################
## CSS - Blur
#############################################################

# Blur/Unblur (CSS,style)
# blanket is a direct child of body
function blur () {
    document.querySelector("#blanket").className = "overlay";
}
function unblur () {
    document.querySelector("#blanket").className = "";
}
.overlay{
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 10;
  background-color: rgba(0,0,0,0.5); /*dim the background*/
}


#############################################################
## CSS - Box
#############################################################

# Create an empty (check) box using CSS
h1::before {
    border: 2px solid black;
    width: 1rem;
    height: 1rem;
    content: "";
    box-sizing: border-box;
    display: inline-block;
    border-radius: 15%;
    margin-right: 1rem;
}


#############################################################
## CSS - Center
#############################################################

# Center a child of unknown width and height (CSS,style)
# both vertically and horizontally
.parent {
 	position: relative;
}
.child {
  	position: absolute;
  	top: 50%;
  	left: 50%;
  	transform: translate(-50%, -50%);
}


#############################################################
## CSS - Debug
#############################################################

# Show the element placement/position (css,color)
# Debug html/table
* { border: 1px dashed blue }


#############################################################
## CSS - Display
#############################################################

# Content inside an element is shown vertically. (CSS)
# This will make it be horizontal (spread out).
display: contents;


#############################################################
## CSS - Flex
#############################################################

# Vertically align elements inside a container (CSS,style)
.container {
  display:     flex;
  align-items: center;
}


#############################################################
## CSS - Force
#############################################################

# Force a style even though there is a longer (more specific one) (CSS Style)
#details .failed_validation {
  background-color: #ff5050 !important;
}


#############################################################
## CSS - Grid
#############################################################

# Avoid having to always set the grid-template-columns by using (HTML,section)
grid-auto-rows: min-content;


#############################################################
## CSS - Orientation
#############################################################

# Differentiate between portrait and landscape mode (PC versus PI,CSS styles)
//
#main {
  width:    -webkit-fill-available;
  height:   91%;
  position: relative;
}
@media all and (orientation:landscape) {
  #main {
    height:   100%;
  }
}


#############################################################
## CSS - Progress Bar
#############################################################

# Create a progress bar in HTML (css)
background: linear-gradient(90deg, rgb(40, 135, 20) 59%, rgb(129, 199, 132) 0);


#############################################################
## CSS - Readonly
#############################################################

# Readonly checkboxes (HTML)
# Use the attribute "disabled" to make a checkbox readonly
# Both "readonly" and "disabled" work with other elements like "select".
# Note: "readonly" form elements make show up when serialized.
#       "disabled" form elements will not show up when serialized.


#############################################################
## CSS - Scroll
#############################################################

# Make sure an element is seen when scroll (without using the mouse,javascript)
document.querySelector("#id").scrollIntoViewIfNeeded(true);


#############################################################
## CSS - Selectors
#############################################################

# "*" - Universal selector (CSS,Basic selectors)
# Selects all elements. Optionally, it may be restricted to a specific
# namespace or to all namespaces.
# Syntax:
	* ns|* *|*
# Example:
	* will match all the elements of the document.

# "<node>" - Type selector (CSS,Basic selectors)
# Selects all elements that have the given node name.
# Syntax:
	elementname
# Example:
	input will match any <input> element.

# ".class" - Class selector (CSS,Basic selectors)
# Selects all elements that have the given class attribute.
# Syntax:
	.classname
# Example:
	.index will match any element that has a class of "index".

# "#id" - ID selector (CSS,Basic selectors)
# Selects an element based on the value of its id attribute.
# There should be only one element with # a given ID in a document.
# Syntax:
	#idname
# Example:
	#toc will match the element that has the ID "toc".

# "[attr=val]" - Attribute selector (CSS,Basic selectors)
# Selects all elements that have the given attribute.
# Syntax:
	[attr]
	[attr=value]

cheats.txt  view on Meta::CPAN

# Syntax:
	A B
# Example:
	div span will match all <span> elements that are inside a <div> element.

# "A > B" - Child combinator (CSS,Combinators)
# The > combinator selects nodes that are direct children of the first element.
# Syntax:
	A > B
# Example:
	ul > li will match all <li> elements that are nested directly inside a <ul> element.

# "A ~ B" General sibling combinator (CSS,Combinators)
# The ~ combinator selects siblings. This means that the second element follows the first (though # not necessarily immediately), and both share the same parent.
# Syntax:
	A ~ B
# Example:
	p ~ span will match all <span> elements that follow a <p>, immediately or not.

# "A + B" - Adjacent sibling combinator (CSS,Combinators)
# The + combinator selects adjacent siblings. This means that the second element directly follows # the first, and both share the same parent.
# Syntax:
	A + B
# Example:
	h2 + p will match all <p> elements that directly follow an <h2>.

# "A || B" Column combinator (CSS,Combinators)
# The || combinator selects nodes which belong to a column.
# Syntax:
	A || B
# Example:
	col || td will match all <td> elements that belong to the scope of the <col>.

# "p::first-line" - Pseudo classes (CSS)
# The : pseudo allow the selection of elements based on state information
# 	that is not contained in # the document tree.
# Example:
	a:visited will match all <a> elements that have been visited by the user.
# Pseudo elements
# The :: pseudo represent entities that are not included in HTML.
# Example:
	p::first-line will match the first line of all <p> elements.


#############################################################
## CSS - Stack Order
#############################################################

# Update the stacking order of elements (CSS,style)
# Elements with bigger number are placed above this.
# Default is 0.
.child {
	z-index: 20;
}


#############################################################
## CSS - Text Input
#############################################################

# Overwrite the Chrome placeholder background color (CSS Style)
# Color after choosing a past selected value.
#details input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0px 1000px #ddd inset;
}


#############################################################
## CSS - Transform
#############################################################

# CSS uppercase text.
/* text-transform: uppercase; */


#############################################################
## CSS - Variables
#############################################################

# Use a variable inside CSS styling
html, body {
  --accent-color: #ae0000;
}
#main > span {
  background: var(--accent-color);
}


#############################################################
## CSS - Wrap
#############################################################

# Make an element (like div) wrap the text when too long
.wordwrap {
   white-space: pre-wrap;      /* CSS3. Chrome*/
   white-space: -moz-pre-wrap; /* Firefox */
   white-space: -o-pre-wrap;   /* Opera 7 */
   word-wrap: break-word;      /* IE */
   width: 8rem;
}


#############################################################
## Cowsay
#############################################################

# Ascii art messages.
sudo apt install cowsay
cowsaw hey


#############################################################
## Dig (nslookup)
#############################################################

# Install dig command.
apt install dnsutils


#############################################################
## Docker
#############################################################

# View docker log (warnings,errors)
docker compose logs -f --tail 200

# Install a mail server using docker
sudo apt install docker docker-compose
sudo usermod -a -G docker $USER
sudo su $USER # To avoid restarting for groups to take effect
docker pull mailserver/docker-mailserver:latest

# Check docker processes
docker ps
ctop


#############################################################
## Docker Setup
#############################################################

# Enable cgroups in ubuntu (for docker)
sudo vi /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash systemd.unified_cgroup_hierarchy=1 cgroup_enable=memory cgroup_memory=1"
sudo update-grub

cheats.txt  view on Meta::CPAN

sudo passwd root

# Reset password in a script with no prompt (change)
# Can only supply one user to "passwd"
echo asdf1234 | sudo passwd xbe4092 --stdin; sudo make -C /var/yp
echo -e "xbe4092:asdf1234\npotapov:asdf1234" | sudo chpasswd; sudo make -C /var/yp

# Reset password over ssh (change,admin)
ssh -qtY potapov@lnxbrfs01 'echo -e "xbe4092:asdf123\npotapov:asdf123" | sudo /usr/sbin/chpasswd; sudo make -C /var/yp'
sb fs1 'echo -e "xbe4092:asdf123\npotapov:asdf123" | sudo /usr/sbin/chpasswd; sudo make -C /var/yp'

# Reset password of many users (admin,change)
echo "xbe4092:asdf1234" | sudo chpasswd
sudo make -C /var/yp

# Edit the password file. Disable/Lock user accounts before deleting
# Change /bin/bash to /bin/false
# Asterisk in password field disables account
sudo vipw
sudo make -C /var/yp

# Check if specific user account is:
# L  - Locked
# NP - No Password
# P  - Password is set (OK)
sudo passwd -S SOME_USER

# Check all user accounts if:
# L  - Locked
# NP - No Password
# P  - Password is set (OK)
sudo passwd -Sa

# Remove user from a group (delete, passwd)
Log unto fs01
sudo gpasswd -d potapov controls
sudo make -C /var/yp


#############################################################
## Linux Commands - pidof
#############################################################

# Process ID of a program (PID)
pidof omsCommand


#############################################################
## Linux Commands - ps
#############################################################

# Kill the ui when things aren't working
ps -ef | grep ui

# See all users on the bench
ps -elf | grep ui

# Show which processes were started by the current user
ps -elf | grep $USER

# Kill unigraph process if it is running in the background
ps -elf | grep unigraph | perl -anle '`skill -KILL $F[3]`'

# Be more specific in process selection (ps) options
ps -o user,ucmd --no-heading -C ui

# Currently running process (use in a script such as getinfo.sh)
ps -elf | grep getinfo.sh | grep -v grep | grep -v $$

# Check if puppet is running on all the benches
run_on_all_benches.pl 'ps -elf | grep puppet | grep -v grep'

# Check if systemd or init is used
ps -p 1


#############################################################
## Linux Commands - rcs
#############################################################

# Unlock a file
co -u file

# RCS error: file is in use
rm -f RCS/,file_name

# RCS error: file locked by pwxxxx
rcs -U file

# RCS: check in a file initially without the prompt message
ci -t-msg tiny2_rcs.tst


#############################################################
## Linux Commands - read
#############################################################

# Read input from the keyword/user without showing the password (much easier in bash)
read -s pass; echo "got [$pass]"
read -s -p "Password:" pass; echo; echo "got [$pass]"

# Read input from the keyword/user without showing the password. Limit password length
read -s -n 5 -p "Password:" pass; echo; echo "got [$pass]"


#############################################################
## Linux Commands - reptyr
#############################################################

# Attach to a running process on the existing terminal
sudo apt-get install reptyr


#############################################################
## Linux Commands - rsnapshot
#############################################################

# Install rsnapshot on centos
yum install epel-release
yum install rsnapshot

cheats.txt  view on Meta::CPAN

## Linux Commands - rm
#############################################################

# Apply a character class to remove files
rm -f *2[1-3]

# Time how long a process take
time rm -f file
#								# files:  100		20,000		30,000		50,000
# Delete all files using "rm"
rm -f dir/*						# real    0m0.329s	0m26.650s	0m33.476s	35m35.183
rm -fr dir						# real    0m0.181s	0m31.099s	0m45.349s	57m58.145s


#############################################################
## Linux Commands - screen
#############################################################

# Clean up dead UI sessions (for Tony, Cody)
screen -wipe


#############################################################
## Linux Commands - screen
#############################################################

# Fix screen -x when it is a display issue
script /dev/null


#############################################################
## Linux Commands - sed
#############################################################

# Remove lines which contain abc
a='
abc is here
its not here
nore here
but abs is here too
'
echo "$a" | grep -v abc
echo "$a" | sed '/abc/d'

# Remove first line from a file
cat my.csv | cut -d, -f1 | sed 1d

# Find and replace using sed
echo $STACK | sed 's/call/CALL/'
echo $STACK | sed 's/call/CALL/gi'

# Modify only select lines
echo "$a" | sed '/abc/  {s/here/NOT here/}'
echo "$a" | sed '/abc/! {s/here/NOT here/}'


#############################################################
## Linux Commands - set
#############################################################

# See what running running in the background of a linux script
set -x 		# Enable trace
set +x 		# Disable trace (default)

# Comparison of set and shopt in Bash
# set   -> $SHELLOPTS (Added: 2017-11-27 08:52:25 AM)
# shopt -> $BASHOPTS

# View manpage for bash builtin commands.
help set

# Check which bash set options are enabled.
echo $-

# Strict mode in bash.
set -euo pipefail


#############################################################
## Linux Commands - setxkbmap
#############################################################

# Reset xmodmap settings
setxkbmap


#############################################################
## Linux Commands - scp
#############################################################

# Copy a file over the network (using ssh)
scp file xbe4092@lnxbr35:location_to_place

# Copy a directory over the network (using ssh)
scp -r directory xbe4092@lnxbr35:location_to_place


#############################################################
## Linux Commands - shopt
#############################################################

# View various bash options that are set (Added: 2017-11-27 08:49:40 AM)
shopt


#############################################################
## Linux Commands - source
#############################################################

# Source a file
source .bashrc
. .bashrc

# Check if script is sourced
[[ $- = *i* ]] && echo "Sourced"

# Source a file from a file stream (Debian 7. at least bash 4.2)
source <(cat file | do_something)
source /dev/stdin <<<"$(cat <(cat file | do_something))"


cheats.txt  view on Meta::CPAN

trap -l

# Prevent control-C from doing anything (signal)
abc(){ echo -e "\n\nNOPE"; }
trap abc SIGINT
<Control-C>

# Prompt on a control-C (signal handling)
signal_handler(){ echo -e "\n${RED}Caught Control-C$RESTORE "; read -p "Are you sure you want to abort? (y/n): " ans; [[ $ans =~ [yY]  ]] && echo "continue" || echo "exit"; }
trap signal_handler SIGINT
<Control-C>

# Create a timer in bash (aborts the session)
handler(){ echo "done"; exit 1; }
set_timer(){ (sleep $1; kill -ALRM $$)& }
trap handler SIGALRM
set_timer 5
while [ 1 ]; do echo $$; sleep 1; done

# Trap alarm signal
trap 'echo "Hit alarm"; break' SIGALRM
while true; do echo $$; sleep 1; done
# In another window:
kill -s ALRM 11657

# List of Bash signals and meanings.
Signal      Standard   Action   Comment
------------------------------------------------------------------------
SIGABRT      P1990      Core    Abort signal from abort(3)
SIGALRM      P1990      Term    Timer signal from alarm(2)
SIGBUS       P2001      Core    Bus error (bad memory access)
SIGCHLD      P1990      Ign     Child stopped or terminated
SIGCLD         -        Ign     A synonym for SIGCHLD
SIGCONT      P1990      Cont    Continue if stopped
SIGEMT         -        Term    Emulator trap
SIGFPE       P1990      Core    Floating-point exception
SIGHUP       P1990      Term    Hangup detected on controlling terminal
                                or death of controlling process
SIGILL       P1990      Core    Illegal Instruction
SIGINFO        -                A synonym for SIGPWR
SIGINT       P1990      Term    Interrupt from keyboard
SIGIO          -        Term    I/O now possible (4.2BSD)
SIGIOT         -        Core    IOT trap. A synonym for SIGABRT
SIGKILL      P1990      Term    Kill signal
SIGLOST        -        Term    File lock lost (unused)
SIGPIPE      P1990      Term    Broken pipe: write to pipe with no
                                readers; see pipe(7)
SIGPOLL      P2001      Term    Pollable event (Sys V);
                                synonym for SIGIO
SIGPROF      P2001      Term    Profiling timer expired
SIGPWR         -        Term    Power failure (System V)
SIGQUIT      P1990      Core    Quit from keyboard
SIGSEGV      P1990      Core    Invalid memory reference
SIGSTKFLT      -        Term    Stack fault on coprocessor (unused)
SIGSTOP      P1990      Stop    Stop process
SIGTSTP      P1990      Stop    Stop typed at terminal
SIGSYS       P2001      Core    Bad system call (SVr4);
                                see also seccomp(2)
SIGTERM      P1990      Term    Termination signal
SIGTRAP      P2001      Core    Trace/breakpoint trap
SIGTTIN      P1990      Stop    Terminal input for background process
SIGTTOU      P1990      Stop    Terminal output for background process
SIGUNUSED      -        Core    Synonymous with SIGSYS
SIGURG       P2001      Ign     Urgent condition on socket (4.2BSD)
SIGUSR1      P1990      Term    User-defined signal 1
SIGUSR2      P1990      Term    User-defined signal 2
SIGVTALRM    P2001      Term    Virtual alarm clock (4.2BSD)
SIGXCPU      P2001      Core    CPU time limit exceeded (4.2BSD);
                                see setrlimit(2)
SIGXFSZ      P2001      Core    File size limit exceeded (4.2BSD);
                                see setrlimit(2)
SIGWINCH       -        Ign     Window resize signal (4.3BSD, Sun)


#############################################################
## Bash - Variables (Special)
#############################################################

# Return status $? (true/false are built-in commands)
true; echo $?
false; echo $?

# Note however that local var=$(command) will (bash)
NOT return the exit code. Instead you need to do
local var;
var=$(command)

# In bash, setting a variable in a subshell
# does not affect the outer shell.
v=1; echo $v; (echo $v; v=2; echo $v; ); echo $v
1
1
2
1
#
# An approach around this is to set the variable
# inside the function.
fun(){ echo $v; v=2; echo $v; }; v=1; echo $v; fun; echo $v

# In bash return 0 means no error. return 1 means error
abc(){ return 0; }; abc && echo "OK" || echo "BAD"
abc(){ return 1; }; abc && echo "OK" || echo "BAD"

# Check if using Bash
echo $0


#############################################################
## Bash - Variables (User)
#############################################################

# Example of using a local variable
n=aaa; echo "1. n = $n"; a(){ m=$n; local n=xyz; echo "2. m = $m"; echo "3. n = $n"; }; a; echo "4. n = $n";
1. n = aaa
2. m = aaa
3. n = xyz
4. n = aaa

# Find out how many characters(length) are in a bash variable
n1=abcd
echo ${#n1}

cheats.txt  view on Meta::CPAN

</script>

# JQuery ToolTip does NOT require a title (using "items")
<div class="cell" data-data-details="my tip" title="">ABC2</div>
<script>
	// Runs only when page has loaded
	$(function() {
		$( ".cell" ).tooltip({
			content: function(event, ui) { return $(this).attr("data-details"); },
			items: ".row .cell",
		});
	});
</script>

// Jquery html and css to show tooltips (body no longer jumps or flickers).
#	function _init(){
#
#		$(".row .cell").tooltip({
#			content: function(event, ui) {
#				const details_raw = $(this).attr('data-details');
#				const details     = details_raw.replace(/\n|\\n/g, "<br>");
#				return details;
#			},
#			items: ".row .cell",
#			show:  false,
#			hide:  false,
#		});
#
#		$(".row .cell").on("click", (event) => {
#			const $cell    =  $(event.target);
#			let tooltip_id = $cell.attr("data-tooltip_id");
#			if(tooltip_id){
#				// Hide
#				$(document.getElementById(tooltip_id)).remove();
#				$cell.removeAttr("data-tooltip_id");
#				$cell.removeClass("clicked_tooltip");
#			}
#			else{
#				// Show
#				tooltip_id = "clicked_tooltip_" + next_uid++;
#				$('.ui-tooltip[id*=ui-id-]')
#					.clone()
#					.attr("id", tooltip_id)
#					.removeAttr("opacity")
#					.appendTo("body");
#				// Clicked cell knows about the tooltip
#				$cell.attr("data-tooltip_id", tooltip_id);
#				$cell.addClass("clicked_tooltip");
#			}
#
#		});
#	}

# JQuery Tooltip CSS
#/* ------------------- Tooltip ------------------------- */
#.ui-tooltip {
#    padding: 				10px 20px;
#    border-radius: 			20px;
#    font: 					bold 14px"Helvetica Neue", Sans-Serif;
#    box-shadow: 			0 0 7px black;
#    background-color: 		white;
#    width: 					fit-content;
#    position:				absolute;
#}
#
#/* Prevent seeing content appended to the body */
#.ui-helper-hidden-accessible {
#    display:				none;
#}
#
#.table .cell.clicked_tooltip {
#    color: 					#06a003;
#    font-weight: 			600;
#}


#############################################################
## JQuery - Variables
#############################################################

# Store jquery variables inside html elements
# Using data() preserves the type of the variable.
# Using attr() simply converts the variable to a string.
var1 = 123
var2 = [123,456]
var3 = {a:123,b:456}
//
$('#level1').data("var", var1)
$('#level1').data("var")
	123
typeof $('#level1').data("var")
	"number"
//
$('#level1').data("var", var2)
$('#level1').data("var")
(2) [123, 456]
typeof $('#level1').data("var")
"object"
//
$('#level1').data("var", var3)
$('#level1').data("var")
{a: 123, b: 456}
typeof $('#level1').data("var")
"object"


#############################################################
## Make
#############################################################

# Go to a particular directory before running make
make -Cdir

# Show what commands make will do (but don't do it, executed)
make -n
make --just-print

# Show make database variables
make --print-data-base

# Count how many items are in a list

cheats.txt  view on Meta::CPAN

perl -MTk -le '$mw=MainWindow->new; my @b; sub id{my($n)=grep{$b[$_] eq $_[0]}0..$#b; $n} for my $fi(1..3){my $f=$mw->Frame->pack; push @b,$f; $f->Button(-text => "Btn - $fi - $_", -width => 20)->pack(-side => "left") for 1..3} $mw->bind("<ButtonRele...

# Notebook example 1. multiple pages/tabs (PTk)
perl -MTk -MTk::NoteBook -le '$nb=MainWindow->new->NoteBook->pack(-fill => "both", -expand => 1); @pgs = map { $nb->add("page$_", -label => "Page $_") } 0..5; $pgs[0]->Button(-text => "Button $_")->pack(-fill => "both") for 1..5; $pgs[1]->Label(-text...

# Notebook example 2. multiple pages/tabs (PTk)
# Command when clicking a page/tab
perl -MTk -MTk::NoteBook -le '$nb=MainWindow->new->NoteBook(-font => "Courier 14 bold")->pack(-fill => "both", -expand => 1); @pgs = map { $nb->add("page$_", -label => "Page $_") } 0..20; $pgs[0]->Button(-text => "Button $_")->pack(-fill => "both") f...

# Notebook example 3. multiple pages/tabs (PTk)
# Page deletion
perl -MTk -MTk::NoteBook -le '$nb=MainWindow->new->NoteBook->pack(-fill => "both", -expand => 1); @pgs = map { $nb->add("page$_", -label => "Page $_") } 0..10; $nb->pagecget("page0", "-state"); $pgs[0]->Button(-text => "Button $_")->pack(-fill => "bo...

# Notebook example 4. multiple pages/tabs (PTk)
# Get page by name
perl -MTk -MTk::NoteBook -le '$nb=MainWindow->new->NoteBook->pack(-fill => "both", -expand => 1); @pgs = map { $nb->add("page$_", -label => "Page $_") } 0..10; $nb->pagecget("page0", "-state"); $pgs[0]->Button(-text => "Button $_")->pack(-fill => "bo...

# Notebook example 5. multiple pages/tabs (PTk)
# 2 rows
perl -MTk -MTk::NoteBook -le '$nb=MainWindow->new->NoteBook->pack(-fill => "both", -expand => 1); $nb->add("page0$_", -label => "Page $_") for 1..5; map { my $nb = $_; $nb->add("page1$_", -label => "Page $_") for 6..10;   } map $_->NoteBook->pack, ma...

# Notebook example 6. multiple pages/tabs (PTk)
perl -MTk -MTk::NoteBook -le '$nb=MainWindow->new->NoteBook->pack; $nb->add("page0$_", -label => "Page $_") for 1..5; @pgs = map $nb->page_widget($_), $nb->pages; ($p,@rest)=@pgs; $nb1=$p->NoteBook->pack; $nb1->add("page1$_", -label => "Page $_") for...

# Entry widget validation options (PTk)
perl -MTk -le 'MainWindow->new->Entry(-validate => "key", -validatecommand => sub{$_[1] =~ /\d/}, -invalidcommand => sub{ print "ERROR" })->pack->focus; MainLoop'

# Making Scrollbars (PTk)
# When text widget is scrolled its "-yscrollcommand" command is invoked. This calls $s->set(...)
# When the scrollbar is clicked on "-command" is invoked which calls $t->yview(...)
perl -MTk -le '$mw=MainWindow->new; $s=$mw->Scrollbar; $t=$mw->Text(-yscrollcommand => ["set" => $s]); $s->configure(-command => ["yview" => $t]); $s->pack(-side => "right", -fill => "y"); $t->pack(-fill => "both"); MainLoop'

# Scale widget example (PTk)
perl -MTk -le 'MainWindow->new->Scale(-from => 1, -to => 5, -tickinterval => 1, -showvalue => 0)->pack; MainLoop'

# Balloon widget example (PTk)
perl -MTk -MTk::Balloon -le '$mw=MainWindow->new; $b=$mw->Button(-text => "DO NOTHING")->pack; $mw->Balloon->attach($b, -msg => "button"); MainLoop'

# Balloon widget example (PTk)
perl -MTk -le '$w=tkinit; $bt=$w->Button(-text => "this does nothing")->pack; $w->Balloon->attach($bt, -msg => "really nothing"); MainLoop'

# Listbox example (PTk)
perl -MTk -le '$w=MainWindow->new; $lb=$w->Scrolled("Listbox", -scrollbars => "osoe")->pack; $lb->insert(0,1..10); $w->Button(-text => "SHOW", -command => sub{@s=$lb->curselection; print $lb->get(@s) if @s})->pack; MainLoop'

# Handle clicking the "X" button on a window to close (PTk)
perl -MTk -le '$w=MainWindow->new; sub e{print "safe exit"; $w->destroy} $w->protocol("WM_DELETE_WINDOW", \&e); $w->Button(-text => "EXIT", -command => \&e)->pack; MainLoop'

# Menu(bar) example (PTk)
perl -MTk -le '$w=MainWindow->new; $m=$w->Menu; $w->configure(-menu => $m); %h=map{$_ => $m->cascade(-label => "~$_")} qw/File Edit Help/; $h{File}->command(-label => "Exit", -command => sub{exit}); MainLoop'

# Menu(bar) example using -menuitems (PTk)
perl -MTk -le '$w=MainWindow->new; $m=$w->Menu; $w->configure(-menu => $m); %h=map{$_ => $m->cascade(-label => "~$_", -menuitems => [[checkbutton => "MY_CHECK"],[command => "MY_CMD", -command => sub{print "exit"}, -accelerator => "Ctrl-o"],[radiobutt...

# Simple Menu(bar) example using -menuitems (PTk)
perl -MTk -le '$w=MainWindow->new; $m=$w->Menu; $w->configure(-menu => $m); $m->cascade(-label => "~File", -menuitems => [[command => "new", -accelerator => "Ctrl-n"],"",[command => "Open", -accelerator => "Ctrl-o"]]); MainLoop'

# Simple 2 Menu(bar) example using -menuitems (PTk)
perl -MTk -le '$w=MainWindow->new; $m=$w->Menu; $w->configure(-menu => $m); $m->cascade(-label => "~File", -menuitems => [[cascade => "new", -accelerator => "Ctrl-n", -menuitems => [map [command => $_],qw/PNG JPEG TIFF/], -tearoff => 0],"",[command =...

# Color changing menu(bar) (PTk)
perl -MTk -le '$color="$red"; $w=MainWindow->new; $mi=[[cascade => "~Edit", -menuitems => [[cascade => "~Background", -menuitems => [map [radiobutton => $_, -variable => \$color, -command => [sub{my $c=shift; $w->configure(-background => $c); print "...

# Very primitive notebook (poor man's notebook) (PTk)
perl -MTk -le '$w=MainWindow->new; ($top,$bot)=map{$w->Frame->pack} 1..2; @b=map { $top->Button(-text => "B$_", -command => [sub{print shift}, $_])->pack(-side => "left") } 1..3; @f=map{$bot->Frame} 1..3; $f[0]->pack; $f[0]->Label(-text => "L1")->pac...

# Wait until variable is changes. Other button can still be pressed though. (PTk)
perl -MTk -le '$w=MainWindow->new; $w->Entry(-width => 20, -textvariable => \$t)->pack; $w->Button(-text => "PRINT", -command => sub{print "ABC"})->pack; $w->Button(-text => "PAUSE", -command => sub{$w->waitVariable(\$t); print "DONE"})->pack; MainLo...

# Simple composite Mega-Widget based on a Toplevel (PTk)
perl -MTk -le '{package Tk::My; use base "Tk::Toplevel"; Construct Tk::Widget "My" } $w=MainWindow->new; $w->My; MainLoop'

# Define own bitmap
perl -MTk -le '$w=MainWindow->new; $p=pack("b5"x5,"..1..",".111.","11111",".111.","..1.."); $bm=$w->DefineBitmap(up => 5,5,$p); $w->Button(-width => 10, -height => 30, -bitmap => "up")->pack; MainLoop'

# Define own bitmap (fansy)
cat star.bm
..............................
..............................
..............................
..............1...............
..............1...............
.............111..............
.............111..............
............1.1.1.............
.......11...1.1.1...11........
.......11..1..1..1..11........
.........1.1..1..1.1..........
..........1...1...1...........
.........1.1..1..1.11.........
.......11...1.1.1....11.......
.....11......111.......11.....
...111111111111111111111111...
.....11......111.......11.....
.......11...1.1.1....11.......
.........1.1..1..1.11.........
..........1...1...1...........
.........1.11.1.11.1..........
.......11...1.1.1...11........
.......11...1.1.1...11........
.............111..............
.............111..............
..............1...............
..............1...............
..............................
..............................
..............................
perl -MTk -le '$w=MainWindow->new; $s=30; $p=pack("b$s"x$s,`cat start.bm`); $w->DefineBitmap(start => $s,$s,$p); $w->Button(-bitmap => "start")->pack; MainLoop'

# DirTree example (PTk)
perl -MTk -le 'MainWindow->new->Scrolled("DirTree")->pack(qw/-fill both -expand 1/); MainLoop'

# LabEntry example (PTk,label and entry in one)
perl -MTk -le 'tkinit->LabEntry(-label => "name", -textvariable => \$name, -labelPack => [qw/ -side left /], -width => 20)->pack; MainLoop'

# Clicking a button will send it to the top. Cycle through
perl -MTk -le '$w=tkinit; @b=map{$w->Button(-text => $_)->pack} a..c; $_->configure(-command => sub{$b[-1]->pack(-before => $b[0]); unshift @b, pop @b }) for @b; MainLoop'

# Show or hide widgets based on a checkbutton (advanced options)
perl -MTk -le '$w=tkinit; $b=$w->Button->pack(qw/ -side bottom /); $p=1; $w->Checkbutton(-text => "Pack", -variable => \$p, -command => sub{ if($p){ $i=$b->{packInfo}; $b->pack(@$i) } else { $b->{packInfo} = [$b->packInfo]; $b->packForget }  })->pack...

# Sleep/Wait (PTk)

cheats.txt  view on Meta::CPAN

# to enter their password to do anything that would bring up a UAC console in
# Windows. You can create accounts with these permissions (I do it for my
# guest account) with the "Add Remove User Accounts" menu in the Control Panel.

# Find out who have a file opened
# Need to have this setup one time (as admin)
openfiles.exe /local on
# restart PC


#############################################################
## Windows - Outlook
#############################################################

# Windows Outlook.
# Monospaced font
Courier New


#############################################################
## Windows - Registry
#############################################################

# Registry file location on windows 10
C:\Users\<USER>\NTUSER.DAT

# Script to update the windows registry
#
@echo off
echo.
cd ..
reg add HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\MY_PATH /t REG_SZ /v AppPath /d %cd% /f
echo.
echo AppPath = %cd%
echo.
pause

# Dump windows 10 registry to a file (query,view,search)
reg export "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\MY_PATH" my.reg
reg export "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\MY_PATH" my.reg /y

# Enable Restore Points in Windows 10
Win + r
Type: regedit
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\SystemRestore
Double - Click "DisableSR"
1	- Disabled
0	- Enabled
#
# Restart PC for changes to take effect.

# Add the "Open command window here" option back to windows 10 commamd prompt (registry,DOS)
# when doing right click.
#
# Go to the regestry
Win + r
type: regedit
#
# For these paths:
Computer\HKEY_CLASSES_ROOT\Directory\shell\cmd
Computer\HKEY_CLASSES_ROOT\Directory\background\shell\cmd
#
# Update permissions:
	- Right-click the PowerShell (folder) key, and click Permissions.
	- Click the Advanced button.
	- On "Advanced Security Settings," click the Change link next to "Owner".
	- Type your account name in the provided field, click Check Names to verify
		you're typing the account name correctly, and click OK.
	- Check the Replace owner on subcontainers and objects option.
	- Click Apply.
	- Click OK.
	- On "Permissions," select the Administrators group.
	- Under "Permissions for Administrators," select Allow for the Full Control option.
	- Click Apply.
	- Click OK.
#
# Show option:
	- Inside the cmd (folder) key, right-click the HideBasedOnVelocityId DWORD,
		and click Rename.
	- Change the DWORD name from HideBasedOnVelocityId to ShowBasedOnVelocityId,
		and press Enter.
#
# Hide option (undo the change):
	- rename the DWORD from from ShowBasedOnVelocityId to HideBasedOnVelocityId


#############################################################
## Windows - Variables
#############################################################

# Get windows script directory (DOS,pwd,windows vars)
echo %~dp0

# Start in currect script directory (windows vars)
cd /d %~dp0


#############################################################
## Windows Commands - ipconfig
#############################################################

# Internet not working on Windows
# Disable all adapters, but Ethernet 2.
# Then:
ipconfig /renew
ipconfig /release
# Enable the adapters again.


#############################################################
## Windows Commands - net
#############################################################

# See which folders are being shared on windows 10
net share


#############################################################
## Windows Commands - netstat
#############################################################



( run in 2.472 seconds using v1.01-cache-2.11-cpan-d8267643d1d )