App-Cheats
view release on metacpan or search on metacpan
# Sample frontend:
frontend:
container_name: frontend
build: ./frontend
image: "poti1/kub-demo-frontend"
depends_on:
- users
- tasks-service
- auth
stdin_open: true
tty: true
ports:
- "3000:80"
#############################################################
## Docker Kubernetes - Namespaces
#############################################################
# Docker Kubernetes - Namespaces
# Check namespaces.
kubectl get namespaces
# Docker Kubernetes - Namespaces
# Create a new namespace
apiVersion: v1
kind: Namespace
metadata:
name: iam-ns
labels:
name: keycloak
# Docker Kubernetes - Namespaces
# View all relevant pods:
kubectl get pods --namespace iam-ns
# Docker Kubernetes - Namespaces
# Check the logs for errors:
kubectl logs --namespace iam-ns pods/keycloak-deployment-PRESS_TAB
# View metrics (kubectl).
minikube addons enable metrics-server
k run myapp --image nginx
k top node
k top pod
#############################################################
## Docker Kubernetes - Roles
#############################################################
# Docker Kubernetes - Roles
# Check for permissions.
auth can-i delete nodes --as dev-user # no
k auth can-i delete nodes # yes
#############################################################
## DOM
#############################################################
# DOM - Update the text of an iframe.
document.querySelector('iframe').contentDocument.querySelector('body').innerText += '\n' + text;
# DOM - Get the html content of an iframe.
document.querySelector('iframe').contentDocument.querySelector('body').innerHTML;
#
# Perl
$Selenium->switch_to_frame(
$Selenium->find('//iframe')
)
my $HTML = $Selenium->find('//body')->get_attribute('innerHTML');
$Selenium->switch_to_frame()
## E
#############################################################
## FontForge
#############################################################
# FontForge program can update a .ttf file pixmap
#############################################################
## FTP Server/Client
#############################################################
# Create an ftp server on ubuntu.
https://linuxconfig.org/how-to-setup-and-use-ftp-server-in-ubuntu-linux
# 1. Install
sudo apt install vsftpd
#
# 2. backup original /etc/vsftpd.conf
#
# 3. Update /etc/vsftpd.conf
write_enable=YES # Dont forget THIS!
local_root=/home/$USER # Not needed? Works when commented out.
local_umask=002
chroot_local_user=YES
pasv_enable=Yes
pasv_min_port=10000
pasv_max_port=10100
allow_writeable_chroot=YES
#
# 4. Allow ftp through firewall.
#
# 5. Restart ftp daemon.
sudo systemctl restart vsftpd
#
# 6. Create a dedicated ftp user account.
sudo useradd -m ftpuser
sudo passwd ftpuser
#
# 7. Append group to current user
sudo usermod -a -G ftpuser $USER
#
# 8. Apply new group.
sudo su $USER
# Test ftp client on ubuntu.
sudo apt install ftp
ftp
ftp> ftp
192.168.178.48
#
# Not sure about this:
ftp://127.0.0.1/test.html
# Check firewall rules (ubuntu).
sudo ufw status verbose
# on Linux Systems and Mac OS X systems via network.
# It is rated with a severity of 9.9 out of 10.
# Block port 631 UDP via firewall settings or deinstall cups if not needed.
sudo ufw deny 631/udp
# Allow ftp through firewall.
sudo ufw allow from any to any port 20,21,10000:10100 proto tcp
# Monitor file transfer activity.
sudo tail -f /var/log/vsftpd.log
#############################################################
## GCC
#############################################################
# Compile a c program (-g is for debugging, -o is for a new name)
gcc -g main.c -o new_name
# Compile a c++ program (-g is for debugging, -l is to include a library, -o is for a new name)
gcc -g cnt.cpp -l stdc++ -o cnt.exe
$ gcc documentation manual page
sudo apt-get install gcc-doc
# View Symbol table of C object file ".o" (OMS)
# Can also do it from an executable file
gcc -c mangle.c
nm mangle.o
nm mangle
# Specify output file with -o
gcc -o out
# Specify libraries ('-la' means there is a "a.a" or "a.so" file in "path")
gcc -o out 1.o 2.o -la -lb -c -Lpath
# Speficify header path with -Ipath
# only compile the source code. Need to link after.
gcc -c 1.c -Ipath
# View compiler optimizations
#
# Summary of each
gcc --help=optimizers
#
# Status of each optimization (enabled or disabled)
gcc -Q --help=optimizers
# Print search paths of gcc (gnu make,c programming)
# Default for "-L"
gcc -print-search-dirs
# Create shared library (.so)
gcc -Wall -fPIC -c *.c
gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 *.o
# Definition: (c programming,gcc)
# -fexceptions
# Enable exception handling. Generates extra code needed to propagate exceptions. For some targets,
# this implies GCC will generate frame unwind information for all functions, which can produce
# significant data size overhead, although it does not affect execution. If you do not specify this
# option, GCC will enable it by default for languages like C++ which normally require exception
# handling, and disable it for languages like C that do not normally require it. However, you may need
# to enable this option when compiling C code that needs to interoperate properly with exception
# handlers written in C++. You may also wish to disable this option if you are compiling older C++
# programs that don't use exception handling.
# -l library (gcc option,flag,order)
# Search the library named library when linking.
#
# "
# It makes a difference where in the command you write this option;
# the linker searches and processes libraries and object files in the order they are specified.
# Thus, foo.o -lz bar.o
# searches library z after file foo.o but before bar.o.
# If bar.o refers to functions in z, those functions may not be loaded.
# "
#
# Think: at this point what is needed?
# If its not needed by now it wont be loaded in (although it may be available)
# Problem: Seeing these errors
# undefined reference to ...
#
# Solution: Change order of libraries
#############################################################
## GDX
#############################################################
# Install gdx on termux.
pkg install ecj dx
cd ~/git
git clone https://github.com/ravener/libgdx-termux
cd libgdx-termux/
./fetch.sh
#############################################################
## Geb - General
#############################################################
# Geb manual
https://gebish.org/manual/current/
# Setup Geb (stuck)
#
# Go here
https://search.maven.org/
#
# Search and download these:
org.gebish:geb-core
org.seleniumhq.selenium:selenium-chrome-driver
org.seleniumhq.selenium:selenium-support
#
# Setup Geb (from repo,starting out)
cd D:\my\setup\geb\sample
git clone https://github.com/geb/geb-example-gradle
// else {
// // console.log("LEFT");
// last = mid;
// }
// }
//
// mid = first + Math.trunc( (last-first) / 2 );
// // console.log(`END: first=${first}, mid=${mid}, last=${last}`);
// $row.insertBefore($rows[mid][ELEM]);
// }
//
// return $rows;
// }
#############################################################
## Javascript - Spinner
#############################################################
# Function to show a loading spinner
function show_loading(){
const screen = document.querySelector("#glass");
#
// Return if we already have a screen up.
if(screen.children.length)
return;
#
const canvas = document.createElement("canvas");
const spinner = document.createElement("div");;
const svg_box = document.createElement("div");
const logo = document.querySelector(".logo svg").cloneNode(true);
canvas.className = "center";
spinner.className = "center loader";
svg_box.className = "center loading-svg";
#
screen.append(canvas);
screen.append(spinner);
screen.append(svg_box);
svg_box.appendChild(logo);
#
svg_box.addEventListener("click", hide_loading);
show_glass();
#
// Setup
const radius = 75; // Inner circle radius
const ctx = canvas.getContext('2d');
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
ctx.beginPath();
#
// Draw shape
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = '#ffffff'; // light grey
ctx.fill();
}
# Create a simple CSS/HTML animation (blink an element)
.blink {
animation: blinker 2s linear infinite;
}
@keyframes blinker {
50% {
opacity: 0.5;
}
}
# Function to unshow the loading spinner
function hide_loading(){
const screen = document.querySelector("#glass");
#
if(screen.children.length){
setTimeout(() => {
while(screen.firstChild)
screen.removeChild(screen.firstChild);
hide_glass();
}, 500);
}
else{
hide_glass();
}
}
# CSS for the loading spinner
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.loading-svg {
width: 5.7375rem;
height: 2.23125rem;
cursor: pointer;
}
.loading-svg svg > path, .loading-svg svg > ellipse, .loading-svg svg > rect {
fill: #888;
}
.loading-svg svg > .thicker {
fill: #888;
}
.loading-svg svg > .thinner {
fill: #777;
}
.loader {
border-top: 2px solid #777; /* dark */
border-bottom: 2px solid #777; /* dark */
border-left: 2px solid #ccc; /* light */
border-right: 2px solid #ccc; /* light */
border-radius: 50%;
height: 150px; /* Diameter of ring */
width: 150px; /* Diameter of ring */
margin-top: -77px; /* height/2 + border */
margin-left: -77px; /* width/2 + border */
animation: spin 3s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#############################################################
## Javascript - Strings
#############################################################
# Capitalize first letter of a word in Javascript
string = string.charAt(0).toUpperCase() + string.slice(1);
# Addition versus concatenation (javascript,to integer)
5 + 2 => 7
"5" + "2" => 52
"5" + 2 => 52
Number("5") + Number("2") => 7
Number("5") + 2 => 7
# Javascript convert a string to lowercase (uppercase is similar)
"AAA".toLowerCase()
# Javascript check if a variable is defined
if(typeof file_root_name == 'undefined'){
return;
}
if(file_root_name == null){
return;
}
# String interpolation in javascript (only with backticks and curlys)
n = 123
console.log("here is: ${n}") // here is: ${n}
console.log('here is: ${n}') // here is: ${n}
console.log(`here is: ${n}`) // here is: 123
console.log(`here is: $n` ) // here is: $n
# Encode a url using Javascript
encodeURI('159278 #01')
159278%20#01
#
# Better Javascript encoding
encodeURIComponent('159278 #01')
159278%20%2301
#############################################################
## Javascript - WebSockets
#############################################################
# Create a websocket in Javascript (usage)
const ws = new WebSocket(`ws://${location.host}/${module}.ws`);
//
ws.send(JSON.stringify(data));
//
ws.onmessage = msg => {
try {
const data = JSON.parse(msg.data);
console.log("onmessage msg: ", msg);
} catch(e) {
perl -E 'my $f = 'foo'; sub func { while ($i++ < 3) { my $f = $f; $f .= "bar"; say $f }} func; say "Finally $f\n"' foobar foobar
foobar
Finally foo
# Perl lexical variable eval bug (fixed after 5.40).
https://www.perlmonks.org/?node_id=11158351
https://github.com/Perl/perl5/pull/22097
# Refresh a Module (bug):
https://www.perlmonks.org/?node_id=11161935
#############################################################
## Perl Compile
#############################################################
# Compile a perl script into c code (only on lnxbr42) (really slow)
pp -o hello hello.pl
# Run c/cpp code inside perl (Compile)
perldoc Inline
#############################################################
## Perl Configuration
#############################################################
# Print all the perl configuration variables
perl -V:.*
# Check if little or big endian
perl -V:byteorder
byteorder='12345678' # Little
# Show all perl configuration options.
perl -MConfig -Me -e 'p \%Config'
#############################################################
## Perl Debugger
#############################################################
# Library to enable using up arrow key in perl debugger window (-de0)
sudo apt install libreadline-dev
# Check for paste bracketing
bind -V | grep paste
enable-bracketed-paste is set to `on'
#
# Enable paste bracketing
if [ -n "$PS1" ]; then
bind 'set enable-bracketed-paste on'
fi
# Create a perl debug file. Watch parameters. view code around (v) (debugger)
cat > .perldb
@DB::typeahead = (
'{{v',
# 'c',
# 'Nonstop',
# 'frame=0',
);
parse_options('inhibit_exit=0');
# Go into a similar session as with python (debugger)
perl -de0
# Graphical perl debugger (only on lnxbr42)
perl -d:ptkdb -e 'print for 1..10'
#############################################################
## Perl DOS
#############################################################
# Template to use the same file for perl and dos
@REM='
@echo off
perl -x -S -l %0 %*
exit /b
';
#!perl
print "HELLO WORLD";
#############################################################
## Perl Endian
#############################################################
# Check type of endian (little or big)
perl -le 'print unpack "h*", pack "S2",1,2' # 10002000 means little endian
# Big to little endian converter
perl -nle 'print pack "V*", unpack "N*", $_'
# Check if Big Endian
perl -le 'print unpack "H08",pack "L",2'
2 -> 02000000 mean Big Endian
# Force little endian
perl -le 'print unpack "H08",pack "L<",2'
# Force big endian
perl -le 'print unpack "H08",pack "L>",2'
# Convert Big Endian to Little Endian (approach 1)
echo 0x89346512 | perl -ple 's/(\d\d)(\d\d)(\d\d)(\d\d)/$4$3$2$1/'
# Convert Big Endian to Little Endian (approach 2)
echo 0x3487 | perl -ple 's/(?:(\d\d)(\d\d))?(\d\d)(\d\d)/$4$3$2$1/'
echo 0x89346512 | perl -ple 's/(?:(\d\d)(\d\d))?(\d\d)(\d\d)/$4$3$2$1/'
#############################################################
## Perl Error Handling
#############################################################
# Perl Error Handling
# die can return more detailed info. (perl)
eval {
die {
# WhoAmI to all functions in a class.
+ #!/usr/bin/perl
+
+ package Subs::Trace;
+
+ use v5.32;
+
+ sub import {
+ my $pkg = caller();
+
+ INIT {
+ no strict 'refs';
+
+ for my $func (sort keys %{"${pkg}::"}) {
+ my $code = ${"${pkg}::"}{$func}->*{CODE};
+ next if not $code;
+
+ ${"${pkg}::"}{$func}->** = sub {
+ say "-> $pkg\::$func";
+ &$code;
+ }
+ }
+ }
+ }
+
+
+ 1
# Subs::Trace use case (example)
perl -I. -E '{ package P; use Subs::Trace; sub F1{10} sub F2{20} } say P::F1() + P::F2()'
# Subs::Trace cpan modules.
cpanm Subs::Trace
perl -E '{ package P; sub F1{10} sub F2{20} sub F4{40} use Subs::Trace; sub F3{30} } say P::F1() + P::F2() + P::F3() + P::F4()'
-> P::F1
-> P::F2
-> P::F4
100
#############################################################
## Perl Modules - Template (Toolkit,tt)
#############################################################
# Concatenation operator in template tookkit (tt)
Data.var1 _ Data.var2
# Compare |html and |uri:
perl -MTemplate -E 'my $out; Template->new->process( \("[% id | html %]"), { id => "has & and spaces" }, \$out); say $out'
has & and spaces
#
perl -MTemplate -E 'my $out; Template->new->process( \("[% id | uri %]"), { id => "has & and spaces" }, \$out); say $out'
has%20%26%20and%20spaces
#############################################################
## Perl Modules - Term::Animation
#############################################################
# Using a terminal animation framework
perl -MTerm::Animation -MCurses -E 'use v5.32; my $anim = Term::Animation->new; halfdelay(2); $anim->new_entity(shape => "<=0=>", position => [3,7,10], callback_args => [1,0,0,0], wrap => 1); while(1){ $anim->animate; my $in = getch(); last if $in eq...
# Using a terminal animation framework (with colors)
perl -MTerm::Animation -MCurses -E 'use v5.32; my $anim = Term::Animation->new; halfdelay(1); $anim->color(1); $anim->new_entity(shape => "<=0=>", position => [3,7,10], callback_args => [1,0,0,0], wrap => 1, default_color => "yellow"); while(1){ $ani...
#############################################################
## Perl Modules - Term::ANSIColor
#############################################################
# Proper way to color text in perl instead of hardcoding
# escape codes (which are not all the same on all devices).
perl -MTerm::ANSIColor -E 'say colored ($_,$_) for qw( RED YELLOW GREEN ON_BRIGHT_BLACK )'
# Color an remote color (uncolor).
perl -MTerm::ANSIColor=colored,colorstrip -E 'say length colorstrip(colored("HEY", "YELLOW"))'
3
#############################################################
## Perl Modules - Term::ProgressBar
#############################################################
# Progress bar example 1
perl -Mojo -MTerm::ProgressBar -CO -E "STDOUT->autoflush(1); my $ua = Mojo::UserAgent->new; $ua->on(prepare => sub($ua,$tx){ my($len,$bar); $tx->res->on(progress => sub($res){ return unless $len ||= $res->headers->content_length; my $prog = $res->con...
# Progress Bar example 2
perl -MTerm::ProgressBar -E "$|++; @a=1..100; $bar = Term::ProgressBar->new({count => ~~@a}); $bar->update($_), select undef,undef,undef,0.05 for @a"
GetTerminalSize
# Progress Bar in Perl (more features shown here)
perl -MTerm::ProgressBar -E "$|++; $max=100_000; $progress = Term::ProgressBar->new({count => $max, name => 'File-1', term_width => 50, remove => 1}); $progress->minor(0); my $next_update = 0; for (0..$max){ my $is_power = 0; for (my $i = 0; 2**$i <=...
#############################################################
## Perl Modules - Term::ReadKey
#############################################################
# Get terminal width in perl
perl -MTerm::ReadKey= -E "my ($w) = GetTerminalSize(); say $w"
# Read input from the keyword/user without showing the password
perl -MTerm::ReadKey -le 'ReadMode(2); $pass .= $key while(ord($key = ReadKey(0)) !~ /^(?: 10|13 )$/x); ReadMode(0); print "Got [$pass]"'
# Read input from the keyword/user without showing the password (same, but using keywords)
perl -MTerm::ReadKey -le 'ReadMode(noecho); $pass .= $key while(ord($key = ReadKey(0)) !~ /^(?: 10|13 )$/x); ReadMode(restore); print "Got [$pass]"'
perl -MTerm::ReadKey -e 'ReadMode(2); while($c=ReadKey(0), ord($c) !~ /^(?:10|13)$/x){ $pass .= $c } ReadMode(0); print "[$pass]\n"'
# Read input from the keyword/user without showing the password (same, but more compact)
perl -MTerm::ReadKey -le 'ReadMode(2); $pass = ReadLine(0); chomp $pass; ReadMode(0); print "Got [$pass]"'
perl -MTerm::ReadKey -le 'ReadMode(2); $_ = ReadLine(0); chomp; ReadMode(0); print "[$_]"'
# Read input from the keyword/user without showing the password (same, but on windows)
perl -MTerm::ReadKey -le "ReadMode 2; $pass = ReadLine 0; chomp $pass; ReadMode 0; print qq([$pass])"
# Read input from the keyword/user without showing the password. replace characters with a star "*"
perl -MTerm::ReadKey -e 'ReadMode(4); while($c=ReadKey(0),$o=ord($c),$o != 10 and $o != 13){ if($o == 127 || $o == 8){chop $p; print "\b \b"}elsif($o < 32){}else{ $p .= $c; print "*" }} ReadMode(0); print "[$p]\n"'
perl -MTerm::ReadKey -e 'ReadMode 3; while($c=ReadKey(0),$o=ord($c),$o != 10 and $o != 13){ if($o == 127 || $o == 8){chop $p; print "\b \b"}elsif($o < 32){}else{ $p .= $c; print "*" }} ReadMode 0; print "[$p]\n"'
perl -MTerm::ReadKey -e 'ReadMode 4; while($c=ReadKey(0),$o=ord($c),$o!=10){ if($o==127 or $o==8){chop $p; print "\b \b"}elsif($o < 32){}else{$p.=$c; print "*"}} ReadMode 0; print "[$p]\n"'
#############################################################
## Perl Modules - Term::ReadLine::Gnu
#############################################################
# Coordinates (relative to root of window)
Ev('X')
Ev('Y')
#
# Button Number (of mouse click)
Ev('b')
#
# Size of widget
Ev('h') # height
Ev('w') # width
#
# Keyboard Info
Ev('k') # Physical Key Value 37 37
Ev('K') # Letter A a
Ev("N") # Decimal 65 97
#
# Event Type
Ev('T') # KeyPress
# Perl Tk Event Info (PTk,bin methods,Ev)
# Stop events in callback.
return # Exits only current sub
Tk::break # Stops all callbacks for an event
# View order of bindings for a widget (PTk,bin methods,Ev)
print for $b->bindtags
print "$_: ", $b->bind($_) for $b->bindtags
# Order order of bindings for a widget (PTk,bin methods,Ev)
$b->bindtags("[all]")
# View the bindtags for (PTk):
# Class
# Install
# Toplevel
# All
perl -MTk -le '$b=MainWindow->new->Button->pack; $b->bind("<ButtonRelease-1>", sub{exit}); map {print $_; printf " $_\n" for $b->bind($_)} $b->bindtags'
# Check if widget exists, if widget if packed (mapped,PTk)
perl -MTk -le '$mw=MainWindow->new; $b=$mw->Button(-text => "unpack", -command => sub{$b->packForget})->pack; $mw->Button(-text => "Check status", -command => sub{print for "",Exists($b), $mw->appname, $b->ismapped()})->pack; MainLoop'
# Track mouse movements (PTk)
perl -MTk -le '$mw=MainWindow->new; $mw->geometry("200x200+0+0"); $w=$mw->Label(-textvariable => \$t, -width => 20)->pack; $mw->bind("<Motion>", sub{$t=join ", ", $mw->pointerxy}); MainLoop'
# Track mouse movements (PTk)
# More positional values
perl -MTk -le '$w=tkinit; $w->geometry("200x200"); $w->Label(-textvariable => \$t, -justify => "left")->pack; $w->bind("<Motion>", sub{$t=sprintf "pointerxy:%s,%s\nxy:%s,%s\nroot:%s.%s\nvroothw:+%s,+%s\nvrootxy:%s,%s\nscreen:%s", $w->pointerxy, $w->x...
# Add tab completion to an entry widget
perl -MTk -le '$mw=MainWindow->new; $e=$mw->Entry(-textvariable => \$t)->pack; $e->focus; $e->bind("<Tab>", sub{@a=glob "$t*"; $t=shift @a if @a; $e->selectionClear}); MainLoop'
# Bind Enter/Carriage Return key (PTk)
$e->bind("<Return>"
# Swap button (PTk)
perl -MTk -le '$mw=MainWindow->new; for(1..3){my $b=$mw->Button(-text => "B$_", -width => 20)->pack; $b->configure(-command => sub{ ($n)=grep{$b[$_] eq $b}0..$#b; return unless $n > 0; @b[$n,$n-1]=@b[$n-1,$n]; $_->packForget for @b; $_->pack for @b})...
# Drag and swap buttons (PTk)
perl -MTk -le '$mw=MainWindow->new; my @b; sub id{my($n)=grep{$b[$_] eq $_[0]}0..$#b; $n} for(1..3){push @b, $mw->Button(-text => "B$_", -width => 20)->pack} $mw->bind("<ButtonRelease-1>",[sub{$m=id(shift); $n=id($mw->containing(@_)); @b[$m,$n]=@b[$n...
# Swap frames of buttons (PTk)
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)
#
# Make sure to use tab separators
snapshot_root /media/<USER>/SRTO_BACKUP/BACKUP
no_create_root 1
#
retain hourly 24
retain daily 7
retain weekly 4
retain monthly 12
#
link_dest 1
#
backup /home/<USER> timPC
backup /etc timPC
backup /opt timPC
backup /root timPC
# Test rsnapshot configuration file
rsnapshot configtest
# Create crontab for rsnapshot
crontab -e
#
# min hr dom mon dow command
0 * * * * /usr/bin/rsnapshot_runner.pl hourly
50 23 * * * /usr/bin/rsnapshot_runner.pl daily
40 23 * * 6 /usr/bin/rsnapshot_runner.pl weekly
30 23 1 * * /usr/bin/rsnapshot_runner.pl montly
# Rsnapshot example
http://www.edwiget.name/2018/05/simple-rsnapshot-incremental-backups-to-removable-disks/#codesyntax_1
#############################################################
## RTCP (RBS,real time command processor)
#############################################################
# Show rtcp options (DES,DEBHAWK)
rtcp he
rtcp he options
rtcp he op2
# List fbs status
rtcp ls
# Real-time clock device (rtc,DES)
/dev/rrtc/McN
# 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()
( run in 0.457 second using v1.01-cache-2.11-cpan-e1769b4cff6 )