20140909

a nice Perl regex debugger

A nice Perl Regex debugger -- Regexp::Debugger

Install
# cpan Regexp::Debugger


cpan or cpanm should put rxrx in your path eg:
/usr/local/bin/rxrx
invoke with
$ rxrx
or
$ perl -MRegexp::Debugger -E 'Regexp::Debugger::rxrx(@ARGV)'


a usage example:
$ rxrx
enter a pattern in the "pattern register" eg:
/\s.*(fo{1,2}\s*bar)[\.\,\:\s]*/i
enter a string to match against
'The Foo bar.'
enter m to Match current string against current pattern --start the stepping process
m
Now hit n for single steps xor m for partial match steps --all the steps required up to the next partial match at once. These are not the only stepping options. Anyways, it is a nice debugger with colors, explanations, forward, backward and jump stepping.

A few pictures with the above example.





How coool is that!
( it does not show the /i modifier but it 'obviously' knows about it )

It is easier to have the debugger reading your Regular Expressions from a file or a perl program. The debugger will find them.
eg:
$ echo '"The Foo Bar." =~ /\s.*(fo{1,2}\s*bar)[\.\,\:\s\;\?]*/i;' > rxtest.pl
$ echo '"say Foo Bar;" =~ /\s.*(fo{1,2}\s*bar)[\.\,\:\s\;\?]*/i;' >> rxtest.pl
$ rxrx rxtest.pl


sound|video play style controls description:s > , n > , m >> , c >FullMatch_END , - < , f >FAIL

but better
________________________________________________/ Help \______

  Motion:    s : step forwards
             - : step backwards
             m : continue to next partial match
             f : continue to next partial failure
             c : continue to end of full match
          : repeat last motion

  Display:   v : change to visualization
             e : change to event log
             h : change to heatmaps
             j : change to JSON representation
             d : describe the regex in detail

  Snapshot:  V : take snapshot of current visualization
             E : take snapshot of current event log
             H : take snapshot of current heatmaps
             J : take snapshot of current JSON representation
             D : take snapshot of regex description

  Control:   q : quit debugger and continue program
             x : exit debugger and terminate program

______________________________________________________________



https://metacpan.org/pod/Regexp::Debugger
http://search.cpan.org/~dconway/Regexp-Debugger-0.001020/lib/Regexp/Debugger.pm



A nice Perl Regex Debugger

20140831

showunicode





Description

showunicode is a simple program that displays unicode characters in your terminal emulator (if the appropiate fonts are installed on your system)


USAGE

% showunicode | less

% showunicode U+1234-U+12FF

% showunicode hex

% showunicode U+218f-U+23ff | less

% showunicode U+2190-U+21ff hex


Author

g0 , http://ipduh.com/contact


License

Same as Perl, free software.


Install ( in *nix and clones )

# wget kod.ipduh.com/lib/showunicode && chmod 755 showunicode && mv showunicode /usr/bin/







Source:

#!/usr/bin/perl
use strict;
no warnings;

=head1 Description

showunicode is a simple program that displays unicode characters in your terminal emulator 
(if the appropiate fonts are installed on your system) 

=cut

my $USAGE= <<"EOU";

=head1 USAGE


% showunicode | less

% showunicode U+1234-U+12FF 

% showunicode hex

% showunicode U+218f-U+23ff | less

% showunicode  U+2190-U+21ff hex

=cut

EOU

=head1 Author

g0 , L<http://ipduh.com/contact>

=head1 License

Same as Perl, free software.

=head1 Install ( in *nix and clones )

# wget kod.ipduh.com/lib/showunicode && chmod 755 showunicode && mv showunicode /usr/bin/  

=cut

my $PRINT_HEX=0;
my $COLS=50;
my $MIN=256;
my $MAX=110_000;

if(@ARGV){
  $PRINT_HEX=1 if($ARGV[0] =~ /^hex/i);

  if($ARGV[0] =~ /^U\+([0-9a-f]{1,6})-U\+([0-9a-f]{1,6})/i){
    my ($from,$to)=(sprintf("%d",hex($1)),sprintf("%d",hex($2)));
    if( $to > $from ){
      if($ARGV[1] =~ /^hex/i) { $PRINT_HEX=1; }
      unicode_range($from , $to);
      print "\n"; 
      exit 0;
    } else {
      print "U+$1 is greater than U+$2 \n";
      exit 3;
    }
  }
 
  if($ARGV[0] =~ /^U\+([0-9a-f]{1,6})/i){
    my $code=$1;
    print "U+$code: " if ($ARGV[1] =~ /^hex/i);
    print chr sprintf("%d",hex($code)), "\n"; 
    exit 0;
  }

  if($ARGV[0] =~ /^help|-h|-help|--h|--help/i){
    print "\nShowunicode Usage Examples\n";
    for my $line (split /\n/,$USAGE){
      print "$line\n" unless ($line =~ /^=.*/);
    }
    print "\nWould you like to see the  perldoc for showunicode? [y/*]:";
    my $answer=<STDIN>;
      system("perldoc $0") if($answer =~ /^y|yes/i); 
    exit 0;
  }
}

print "\n";
unicode_range($MIN,$MAX);
print "\n";
exit 0;

sub unicode_range {
  my ($from,$to)=@_;
  $COLS=8 if ($PRINT_HEX);
  for ($from..$to){
    print sprintf("U+%x",$_) , ":" if ($PRINT_HEX);
    print chr $_, ($_ - $from + 1)%$COLS?" ":"\n";
  }
}






Screenshots





showunicode

20140830

debian, console speak greek

Show and Input greek and other utf8 characters in a debian console

on
Debian GNU/Linux 7 \n \l
If you are using the gnome windows manager, then the gnome-terminal is the culprit (I could not figure out how to make it UTF-8 literate) and the Internets are full of bad advice ...

The easiest way to get a slick utf-8 able terminal emulator is to use xterm with UTF-8 encoding eg -en UTF-8

Even though xterm in debian 7 is using UTF-8 encoding by default beeing explicit does not hurt
$ xterm -en UTF-8


an easy way to put it in your gnome menu is to use alacarte
# apt-get install alacarte
# exit
$ 
and put in Accessories -> New Item
NAME => xterm-UTF8
Command => /usr/bin/xterm -en UTF-8







debian console speak Greek ....

20140825

perl locale debian ...

to fix


$ perl
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
 LANGUAGE = "en_US.UTF-8",
 LC_ALL = (unset),
 LC_MONETARY = "en_US.utf8",
 LC_NUMERIC = "en_US.utf8",
 LC_MEASUREMENT = "en_US.utf8",
 LC_TIME = "en_US.utf8",
 LANG = "en_GB.utf8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
^C




on
$ cat /etc/debian_version; uname -a
7.5
Linux debie64 3.2.0-4-amd64 #1 SMP Debian 3.2.57-3 x86_64 GNU/Linux


upon installing stuff that broke my|your bash env locale variables

do

$ echo "export LANGUAGE=en_US.UTF-8" >> ~/.bashrc 
$ echo "export LC_ALL=en_US.UTF-8" >> ~/.bashrc 
$ echo "export LANG=en_US.UTF-8" >> ~/.bashrc 
$ source ~/.bashrc 



$ perl
^C

taraaaaa

perl should not warn and fall back to C from now on.


perl ... debian package ... bash env ... locale .... crap ... tarrraaaa

20140802

raspbian watchdog



Install the watchdog daemon on raspberry pi raspbian

update `firmware`
$ sudo -s
# rpi-update


install the watchdog deamon
# apt-get install watchdog


load the watchdog module
# modprobe bcm2708_wdog
# echo "bcm2708_wdog" >> /etc/modules  


set /etc/watchdog.conf ...
this is what I ended up enabling
# cat /etc/watchdog.conf |egrep -v "^#.*"

max-load-1  = 24
max-load-5  = 18
max-load-15  = 12



watchdog-device = /dev/watchdog



realtime  = yes
priority  = 1

I just need to watch for system hangs ... the ping and the user commands seem nice though.

# shutdown -r now


raspberry pi software watchdog

keep raspberry pi images small



remove the GUI if you don 't need it

delete downloaded .deb packages
# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          3.6G  1.2G  2.3G  34% /
...

# ls /var/cache/apt/archives/
autoconf_2.69-1_all.deb      libldap2-dev_2.4.31-1+nmu2_armhf.deb     lockfile-progs_0.1.17_armhf.deb
automake_1%3a1.11.6-1_all.deb     liblockfile1_1.09-5_armhf.deb      m4_1.4.16-3_armhf.deb
autotools-dev_20120608.1_all.deb    liblockfile-bin_1.09-5_armhf.deb

...



# apt-get clean
# ls /var/cache/apt/archives/ 
lock  partial



# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          3.6G  1.1G  2.4G  32% /
...




keep raspberry pi images small

20140619

drut default route manager

Drut --Default RoUTe manager-- is a simple script that manages default routes.



I use Drut in systems that need Internet connectivity in LANs with multiple Routers routing through different uplinks. Drut is not a replacement for VRRP and VRRP is not a replacement for Drut, the same goes for tables ... blah ... blah ... it is easier to read what it does ...



#!/bin/bash 
#g0 2014 , http://ipduh.com/contact
#drut.sh , Default RoUTe manager

#Default Gateways
MYGWS=("10.21.241.120" "10.21.241.121" "10.21.241.122" "10.21.241.123")
#IP addresses to ping
PONG=("8.8.8.8" "8.8.4.4")

PING_COUNT=3
FAIL=0
ALTGW=0
SET_GW=`route -n |grep "^0.0.0" |awk '{print $2}'`

for PIP in ${!PONG[*]};do
 if ! ping -c ${PING_COUNT} ${PONG[$PIP]} 1>/dev/null 2>/dev/null; then
  FAIL=`expr ${FAIL} + 1`
 fi
done

if [ ${FAIL} -eq 0 ]; then
 exit 0
else
 for GW in ${!MYGWS[*]}; do
  if [ " ${MYGWS[$GW]}" != "${SET_GW}" ]; then
   FAIL=0
   route add default gw ${MYGWS[$GW]}
   route del -net 0/0 gw ${SET_GW}
   
    for PIP in ${!PONG[*]};do
           if ! ping -c ${PING_COUNT} ${PONG[$PIP]} 1>/dev/null 2>/dev/null; then
                   FAIL=`expr ${FAIL} + 1`
           fi
    done

    [ ${FAIL} -eq 0 ] && exit 0
  fi
 done
 
 exit 3
fi









Drut --Default RoUTe manager

20140618

raspberry pi set keyboard to a US keyboard and get rid off the british keyboard and the # madness



Install locales and set default locale with
$ sudo -s
# raspi-config


To set the keyboard layout to "us" in /etc/default/keyboard
$ cat /etc/default/keyboard 
# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="gb"
XKBVARIANT=""
XKBOPTIONS=""

BACKSPACE="guess"



do it ... save a copy of the original keybord in keyboard.0 and reboot the system
# cd /etc/default/
# perl -i.0 -p -e 's/gb/us/g;' ./keyboard
# shutdown -r now




Raspberry Pi set keyboard layout to US

20140605

raspberrypi get rid off GUI



Notes on getting rid of the desktop environment on raspbian --the arm debian optimized for raspberry pi put together by the raspberry pi foundation.



Set boot on CLI
$ sudo -s
# raspi-config
Choose 3)
3 Enable Boot to Desktop/Scratch Choose whether to boot into a desktop environment, Scratch, or the command-line


Check file system usage
# df
Filesystem     1K-blocks    Used Available Use% Mounted on
rootfs           3731208 2085704   1448600  60% /
/dev/root        3731208 2085704   1448600  60% /
devtmpfs          215824       0    215824   0% /dev
tmpfs              44820     200     44620   1% /run
tmpfs               5120       0      5120   0% /run/lock
tmpfs              89620       0     89620   0% /run/shm
/dev/mmcblk0p1     57288   19064     38224  34% /boot


Purge everyging that depends on-requires X --the following packgages
ii  libx11-6:armhf                        2:1.5.0-1+deb7u1+wheezy                armhf        X11 client-side library
ii  libx11-data                           2:1.5.0-1+deb7u1+wheezy                all          X11 client-side library
ii  libx11-xcb1:armhf                     2:1.5.0-1+deb7u1+wheezy                armhf        Xlib/XCB interface library


with
# apt-get remove --auto-remove --purge libx11*


Check filesystem usage again
# df 
Filesystem     1K-blocks    Used Available Use% Mounted on
rootfs           3731208 1011460   2522844  29% /
/dev/root        3731208 1011460   2522844  29% /
devtmpfs          215824       0    215824   0% /dev
tmpfs              44820     200     44620   1% /run
tmpfs               5120       0      5120   0% /run/lock
tmpfs              89620       0     89620   0% /run/shm
/dev/mmcblk0p1     57288   19064     38224  34% /boot



# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          3.6G  988M  2.5G  29% /
/dev/root       3.6G  988M  2.5G  29% /
devtmpfs        211M     0  211M   0% /dev
tmpfs            44M  200K   44M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            88M     0   88M   0% /run/shm
/dev/mmcblk0p1   56M   19M   38M  34% /boot


that 's over one GiB in savings , 1/4 of the SD in this pi!



remove the desktop environment from raspberry pi raspbian