Wednesday, December 29, 2021

Chess 960 posible starting positions

Examples in several programming languages
http://rosettacode.org/wiki/Generate_Chess960_starting_position

All the positions with the standard ID number
https://chess960.net/wp-content/uploads/2018/02/chess960-starting-positions.pdf

https://www.chessprogramming.org/Chess960

https://github.com/MichaelB7/Chess960-Lookup/blob/master/src/960v09.c

https://en.wikipedia.org/wiki/Fischer_Random_Chess_starting_position

Very good explanation of the rules
https://codegolf.stackexchange.com/questions/12322/chess960-position-lookup/12333#12333

B   B   Q   N   N   R K R
4 * 4 * 6 * 5 * 4 * 1     = 1920

Bishops have to be of different colors (4 black squares, 4 whites squares).

There is only 1 possible position for the King and Rooks because it has to go
between the Rooks and there are only 3 squares available at that time.

Because the Knights change color when they move they could be interchanged
without any difference then 5 * 4 should be divided by 2 then
total number of positions = 960.

Tmux commands

# List sessions
# Alias ls
tmux list-sessions
tmux ls

# Create new session
# It is good practice to name sessions
tmux new -s right_window

# Detach a session
Ctrl-b d

# Attach a session using name
tmux a -t right_window

# Use mouse to select pane
Ctrl-b :
# then type
set -g mouse on

# Zoom a pane
Ctrl-b z

# Scroll
Ctrl-b [
# Quit
q

Backup bash script

https://github.com/64board/Bash/blob/main/backup.sh

 

Perl sort example

Sorting in Perl with user defined subroutines.

https://github.com/64board/Perl/blob/main/sort.pl

Perl Getopt::Std example

Example of using Getopt::Std module.

https://github.com/64board/Perl/blob/main/get_opt.pl

Tuesday, August 31, 2021

Perl Date::Manip::Date business day

 #!/usr/bin/perl

# Creates /etc/cron.d file entries, one per month,
# for a program that should run on the previous
# day to last business day of the month.
# Uses Date::Manip::Date module, https://metacpan.org/dist/Date-Manip/view/lib/Date/Manip/Date.pod.
# 64board@gmail.com
# 2021-08-31
 
use strict;
use warnings;

use Date::Manip::Date;

sub cron_entry {

    my ($date) = @_;

    return $date->printf("30 19 %d %m %a\troot\t/opt/balmo_id/run.sh");
}

##MAIN##

my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);

my $date = new Date::Manip::Date;

foreach my $month (@months) {

    print "Month: $month\n";

    # Get the last day of the month of current year.
    $date->parse("last day in $month");

    print 'Last day of the month: ', $date->printf('%Y-%m-%d, %a'), "\n";

    # Don't check time for business day.
    my $checktime = 0;

    my $offset = 1;
    # Case of last day of the month is not a business day.
    if (!$date->is_business_day($checktime)) {
    $offset = 2;
    }

    # The pevious day to last business day of the month.
    $date->prev_business_day($offset, $checktime);

    print 'Previous business day: ', $date->printf('%Y-%m-%d, %a'), "\n";

    # The CRON entry, use CRON: label to filter the cron entries
    # from the output.
    print "CRON: ", cron_entry($date), "\n";
}

__END__

Saturday, July 3, 2021

SSH Passwordless Login Using SSH Keygen in 5 Easy Steps.

 Step 1: Create Authentication SSH-Keygen Keys on the originating machine.

$ ssh-keygen -t rsa

On Windows you could use puttygen.exe

Use a passphrase to protect keys.

On Linux private key goes to .ssh/id_rsa
Public key goes to id_rsa.pub

Step 2: Create .ssh Directory on the destination machine.

Step 3: Upload Generated Public Keys to the destination machine.

$ cat .ssh/id_rsa.pub | ssh <username>@<destination_ip> 'cat >> .ssh/authorized_keys'

<username> should be the login on the destination machine.
<destination_ip> is the public IP of the destination machine.

Step 4: Set Permissions on the destination machine.

$ ssh <username>@<destination_ip> "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"

<username> should be the login on the destination machine.
<destination_ip> is the public IP of the destination machine.

Step 5: Login from originating machine to destination machine without password.

$ ssh <username>@<destination_ip>

<username> should be the login on the destination machine.
<destination_ip> is the public IP of the destination machine.

On Windows you could use putty.exe

Taken from https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/