App-Cheats
view release on metacpan or search on metacpan
# Move the window to the top/left corner of the display (Putty,xterm)
echo -e '\e[3;0;0t'
# Zoom the window (Putty,xterm)
echo -e '\e[9;1t'
# Bring the window to the front (without changing keyboard focus) (Putty,xterm)
echo -e '\e[5t'
Change the name of an xterm window to "string"
echo -ne "\033]2;string\007"
# Change the name of an xterm icon to "string"
echo -ne "\033]1;string\007"
# Change the name of an xterm icon and window to "string"
echo -ne "\033]0;string\007"
# Create alias to easily change the window name and icon name
# Must be run together!
set_title(){ echo -ne "\033]0;$@\007"; }
alias title='set_title'
# Get dimensions/size of a screen/xterm
xdpyinfo | grep dimensions
xrandr | grep '*'
# Get the size of an xterm window
xwininfo
# Get info about current xterm window
xdpyinfo
# Get size info of a named xterm window
xwininfo -name omsGUI_0_3
# Get info about an xterm window
xprop -id <window_id>
xprop -id 0x2400022
# Get position of the cursor
perl -e '$/ = "R";' -e 'print "\033[6n";my $x=<STDIN>;my($n, $m)=$x=~m/(\d+)\;(\d+)/;print "Current position: $m, $n\n";'
# Print how many columns and rows an xterm window uses for its screen size
tput cols
tput lines
reset
# Change fond/colors of an xterm window
RESTORE='\033[0m'
RED='\033[00;31m'
GREEN='\033[00;32m'
YELLOW='\033[00;33m'
VIOLET='\033[00;35m'
TEAL='\033[00;36m'
GREY='\033[00;37m'
# View color ansi escapes with less (like Vim)
less -R file
# Make xterm text color bold
BOLD='\033[1m'
# Make xterm text color blink
BLINK='\033[5m'
# Move mouse to a specific location on the screen/xterm window (on lnxbr42)
xdotool mousemove 764 11
# Click on a button (cannot on top bar , like the X for close)
xdotool click 1
# Get mouse location
xdotool getmouselocation
# Move mouse to a location and click at the same time
xdotool mousemove 1747 30 click 1
# print contents of X events (mouse activity/movement)
xev
# Install xdotool dependencies
sudo apt-get install libxcb-xtest0:i386 libxcb-xtest0-dbg:i386 libxcb-xtest0-dev:i386
dpkg -l | grep xtest
# Other xdotool dependenacies
sudo aptitude install
# install xdotool from repository
cd ~junk/xdo/xdotool-master
sudo make install
# Check dependencies of a debian package
dpkg -I xdotool_3.20160512.1-1_i386.deb
# Install package from source (.deb)
sudo dpkg -i xdotool_3.20160512.1-1_i386.deb
sudo apt-get install -f
# Launch an xterm window into a certain directory
xterm -e 'cd ~/dsu && /bin/bash'
xterm -fg White -bg Black -sl 10000 -fn a14 -geometry 84x51+1722-78 -title "sre2bin" -e 'cd ~/dsu && /bin/bash'
xterm -fg White -bg Black -sl 10000 -fn a14 -geometry 84x51+1722-78 -title "sre2bin" -e 'cd ~/dsu; /bin/bash'
xterm -fg White -bg Black -sl 10000 -fn a14 -geometry 84x51+1722-78 -title "sre2bin" -e 'cd ~/dsu; bash'
# Check if xterm environment is working (Added: 2017-11-02 03:56:18 PM)
xeyes
# Check what kind of terminal I am using (xterm,bench)
echo $TERM
# Wrap long lines unto next row in bash/linux
# Exclose PS1 in '\[PS1_VALUE\]'
# Function which run on each prompt.
PROMPT_COMMAND=__prompt_command
__prompt_command ()
{
local EXIT="$?";
PS1=$_PS1;
if [ $EXIT != 0 ]; then
});
});
</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
"user" => "First"
}, 'Email::Address::XS' )
#############################################################
## 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
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)
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...
..............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)
$mw->after(3000) # ms
#############################################################
## Perl Modules - Tk (Bind)
#############################################################
# Make Control-C binding (PTk)
perl -MTk -le '$b=tkinit->Button(-text => "Try Control-C"); $b->configure(-command => sub{$b->focus}); $b->pack->bind("<Control-Key-c>", sub{print "Hit C"}); MainLoop'
# Show the name an value of each pressed key (PTk)
perl -MTk -le '$e=tkinit->Entry->pack; $e->focus; $e->bind("<Key>", sub{my($w)=@_; my $E=$w->XEvent; printf "%s %s\n", $E->K, $E->N}); MainLoop'
#
# Simpler
perl -MTk -le '$e=tkinit->Entry->pack; $e->focus; $e->bind("<Key>", sub{my $E=shift->XEvent; printf "%s %s\n", $E->K, $E->N}); MainLoop'
#
# Using newer "Tk::event"
perl -MTk -le '$e=tkinit->Entry->pack; $e->focus; $e->bind("<Key>", sub{printf "%s %s\n", $Tk::event->K, $Tk::event->N}); MainLoop'
# Three (3) ways to get the widget reference of a binding (PTk)
perl -MTk -le '$b=tkinit->Button(-command => \&cb)->pack; $b->bind("<ButtonRelease-3>", \&cb); sub cb {print "\nargs: @_"; print "->W" . $Tk::event->W; print "widget " . $Tk::widget}; MainLoop'
# Find out value of keypress
perl -MTk -le 'tkinit->Entry->pack->bind("<KeyPress>", sub{$e=$Tk::event; print $e->K . " " . $e->N}); MainLoop'
#############################################################
## Perl Modules - Tk (Canvas)
#############################################################
# Take a canvas and create a postscript then a pdf
perl -MTk -le '$w=tkinit; $c=$w->Canvas->pack; $c->createLine(20,20,200,200,200,20); $b=$w->Button(-text => "Save", -command => sub{$c->postscript(-file => "tk.ps")})->pack; MainLoop'
ps2pdf tk.ps tk.pdf
xpdf tk.pdf
#############################################################
## Perl Modules - Tk (Tags)
#############################################################
# Text tags example (PTk)
perl -MTk -le '$t=tkinit->Text->pack; $t->tagConfigure("bold", -font => "Courier 24 bold"); $t->insert("end", "Normal Text\n"); $t->insert("end", "Bold Text\n", "bold"); MainLoop'
# Make select text bold (PTk)
perl -MTk -le '$w=tkinit; $t=$w->Text->pack; $t->tagConfigure("bold", -font => "bold"); $t->insert("end", "A Bunch of text"); $w->Button(-text => "BOLD", -command => sub{$t->tagAdd("bold", "sel.first", "sel.last")} )->pack; MainLoop'
# Check if a selection exists (PTk)
perl -MTk -le '$w=tkinit; $t=$w->Text->pack; $t->tagConfigure("bold", -font => "bold"); $t->insert("end", "A Bunch of text"); $w->Button(-text => "BOLD", -command => sub{$t->tagAdd("bold", "sel.first", "sel.last") if $t->tagRanges("sel")} )->pack; Ma...
#############################################################
## Perl Modules - Tk (Appendix B)
#############################################################
# Adjuster example (PTk,Appendix B)
perl -MTk -le '$w=tkinit; %def=qw/-fill both -expand 1/; $b=$w->Button(-text => "Button A")->pack(%def); $w->Adjuster(-side => "top", -widget => $b)->pack(qw/-fill x/); $w->Button(-text => "Button B")->pack(%def); MainLoop'
# Balloon Example (Ptk,Appendix B)
perl -MTk -le '$w=tkinit; $btn=$w->Button(-text => "Button A")->pack; $bl=$w->Balloon; $bl->attach($btn, -msg => "click me"); MainLoop'
# Bitmap Example (Ptk,Appendix B)
# BrowseEntry Example (Ptk,Appendix B)
#
# Simple
perl -MTk -MTk::BrowseEntry -le 'tkinit->BrowseEntry(-label => "label", -variable => \$v, -choices => [1..10], -browsecmd => sub{print "Clicked $v"})->pack; MainLoop'
#
# Insert additional values
perl -MTk -MTk::BrowseEntry -le '$b=tkinit->BrowseEntry(-label => "label", -variable => \$v, -choices => [1..10], -browsecmd => sub{print "Clicked $v"})->pack; $b->insert("end",20,30); MainLoop'
# Button Example (Ptk,Appendix B)
# Canvas Example (Ptk,Appendix B)
#
# Simple useless canvas
perl -MTk -le '$c=tkinit->Scrolled("Canvas")->pack; MainLoop'
#
# Click in canvas window will show x,y coordinates
perl -MTk -le 'sub print_xy { my($c,$x,$y)=@_; print "(x,y) = @{[ $c->canvasx($x) ]}, @{[ $c->canvasy($y) ]} " } $c=tkinit->Scrolled("Canvas")->pack; $c->Subwidget("canvas")->CanvasBind("<Button-1>", [ \&print_xy, Ev("x"), Ev("y") ]); MainLoop'
# ColorEditor Example (Ptk,Appendix B)
# Dialog Example (Ptk,Appendix B)
# DirTree Example (Ptk,Appendix B)
# Entry Example (Ptk,Appendix B)
# ErrorDialog Example (Ptk,Appendix B)
# FileSelect Example (Ptk,Appendix B)
# Frame Example (Ptk,Appendix B)
# HList Example (Ptk,Appendix B)
perl -MTk -MTk::HList -le '$h=tkinit->HList(-indent => 20)->pack; $h->add(qw/A -text a/); $h->add(qw/A.B -text a->b/); MainLoop'
# Label Example (Ptk,Appendix B)
# LabEntry Example (Ptk,Appendix B)
# Learn how to use Text indices (demo)
perl -MTk -le '%def=qw/-side left/; $mw=tkinit; $t=$mw->Text->pack; ($i,$d)=map{my $v; $mw->LabEntry(-label => "$_:", -textvariable => \$v, -labelPack => [%def])->pack(%def); \$v} qw/Index Data/; $mw->Button(-text => "INSERT", -command => sub{$t->ins...
# LabFrame Example (Ptk,Appendix B)
# ListBox Example (Ptk,Appendix B)
# MainWindow Example (Ptk,Appendix B)
# Create tags of all OMS functions (Vim)
sudo apt-get install exuberant-ctags
ctags `find ~/omspp/trunk/ -type f -name "*.[ch]" -o -name "*.cpp"`
ctags -f $tag_file $(find $oms_tree -type f -name "*.[ch]" -o -name "*.cpp")
# Jump to the tag/function underneath the cursor (Vim)
<Control> + ]
:tag
# Search for a particular tag (Vim)
:ts <tag>
# Go to the next definition for the last tag (Vim)
:tn
# Go to the previous definition for the last tag (Vim)
:tp
# List all of the definitions of the last tag (Vim)
:ts
# Jump back up in the tag stack (Vim)
<Control> + o # One jump in jump list
<Control> + t # Can be many jumps
#############################################################
## Vim Tab Spacing (Indentation)
#############################################################
# Increase indentation (with autoindent set) (Vim)
<Control> + T
# Descrease indentation (with autoindent set) (Vim)
<Control> + D
# Indent the next 2 lines (Vim)
>2j
# Indent all the lines to the end of the file (Vim)
>G
#############################################################
## Vim Syntax
#############################################################
# Comment lines in vimrc should start with "
" this is a comment
# Name of file that is opened in vim
let _curfile = expand("%:t")
# Show line numbers in vim (vimrc)
set number
# Vim resource (vimrc) file. other features.
set nowrap
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40
set cursorcolumn
# Do not go past the end of the file when searching (Vim)
set nowrapscan
# View the current file type of a Vim file
:set filetype?
# Check the file type (Vim,xterm,shell)
file ~/bin/enter_ui.sh
# Force the syntax to be a certain type in Vim
:set syntax=perl
#############################################################
## Vim Case Changing
#############################################################
# Toggle upp and lower case (Vim)
~
# Toggle case of the next three characters (Vim)
3~
# Toggle case of the next three words (Vim)
g~3w
# Toggle case of the current word (inner word - cursor anywhere in word (Vim)
g~iw
# Toggle case of all characters to end of line (Vim)
g~$
# Toggle case of the current line (Vim)
g~~
V~
# Uppercase the visually-selected text (Vim)
v
U
# Lowercase the visually-selected text (Vim)
v
u
# Change the current line to uppercase (Vim)
gUU
VU
# Change the current line to lowercase (Vim)
guu
Vu
# Change current word to uppercase (Vim)
gUiw
# Change current word to lowercase (Vim)
guiw
( run in 0.924 second using v1.01-cache-2.11-cpan-d7f47b0818f )