Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 
avatar of Christopher Bottoms

Christopher Bottoms

Christopher Bottoms has asked 81 questions and find answers to 59 problems.

Stats

1.7k
EtPoint
379
Vote count
81
questions
59
answers

About

I use Python, Raku, Perl, R, Java, bash, and anything else that is needed.

Utilizo Python, Raku, Perl, R, Java, bash, o lo que sea necesario.

A good explanation of creating good reproducible R questions

How to get help in R


Python 3 vs Raku

Python 3: Unordered common lines between two files:

#!/bin/env python

import argparse

parser = argparse.ArgumentParser(description='Determine the lines in common between two files')

parser.add_argument('fileA', help='file name')
parser.add_argument('fileB', help='file name')

args = parser.parse_args()

with open(args.fileA) as x: linesA = x.readlines()
with open(args.fileB) as x: linesB = x.readlines()

intersection = set(linesA).intersection(set(linesB))

print("".join(sorted(intersection)))

Usage message resulting from python intersection_of_lines.py --help:

usage: intersection_of_lines.py [-h] fileA fileB

Determine the lines in common between two files

positional arguments:
  fileA       file name
  fileB       file name

optional arguments:
  -h, --help  show this help message and exit

Raku: Unordered common lines between two files:

#!/bin/env raku

sub MAIN #= Determine the lines in common between two files
(   $fileA, #= file name
    $fileB, #= file name
)
{
    my @linesA = $fileA.IO.lines;
    my @linesB = $fileB.IO.lines;

    my $intersection = @linesA ∩ @linesB;

    put $intersection.keys.sort.join("\n");
}

Yes that is , a real Unicode intersection symbol. The ASCII version (&) also works.

You also get a nice usage message resulting from raku intersection_of_lines.raku --help:

Usage:
  ./intersection_of_lines.raku <fileA> <fileB> -- Determine the lines in common between two files

    <fileA>    file name
    <fileB>    file name

Raku tidbits

Raku is a very clean, concise, understandable language. Its design pulls from the strengths of other languages.

Raku's rotor (the "king of list manipulation").

Error handling example.

SLURM

Pass variables to SLURM: Passing SLURM batch command line arguments to R

sbatch --export=GREETING=Hello,PLACE=world --wrap='echo "$GREETING $PLACE" > howdy.txt'

convert Jupyter notebook (https://stackoverflow.com/a/50567584/215487)

jupyter-nbconvert --to python notebook.ipynb --stdout --TemplateExporter.exclude_input_prompt=True

Why adjusted P-values are so important: https://www.xkcd.com/882