Skip to content

Instantly share code, notes, and snippets.

View JJ's full-sized avatar
🏠
Working from home

Juan Julián Merelo Guervós JJ

🏠
Working from home
View GitHub Profile
@JJ
JJ / is-product.p6
Last active November 23, 2022 10:46
Check whether an item in a list is a product
use JSON::Tiny;
use Wikidata::API;
sub MAIN( Str $toy-list = 'list.json' ) {
my $toys = from-json $toy-list.IO.slurp();
say $toys.grep( { is-product( $^þ) } );
}
sub is-product( Str $item ) {
@JJ
JJ / list.p6
Last active November 23, 2022 10:45
Find items in a markdown list
use Text::Markdown;
use JSON::Tiny;
sub MAIN( Str $letter-to-santa = 'letters/dear-santa-list.md' ) {
my $letter = Text::Markdown::Document.new($letter-to-santa.IO.slurp());
my $flip = False;
my $list = $letter.items
.grep( { $flip = ( $flip
or so ($^þ ~~ Text::Markdown::Heading
and $^þ.level == 2
@JJ
JJ / address.p6
Last active November 23, 2022 10:41
Extract heading from a markdown-marked letter
use Text::Markdown;
sub MAIN( Str $letter-to-santa = 'letters/dear-santa.md' ) {
my $letter = Text::Markdown::Document.new($letter-to-santa.IO.slurp());
say so $letter.items.grep( { $^þ ~~ Text::Markdown::Heading } );
}
@JJ
JJ / perl-modules-github-actions-ubuntu-runner.md
Created January 8, 2021 07:14
List of Perl modules installed in the Github action runner

Here's the list of modules installed in the Ubuntu runner for Github actions. They've been obtained using a script that list all modules installed

Module
AnyDBM_File
App::Cpan
App::Prove::State::Result::Test
App::Prove::State::Result
App::Prove::State
App::Prove
@JJ
JJ / Submitting Rmd to Arxiv.md
Last active April 12, 2022 08:00
Submitting RMarkdown articles to Arxiv

Mini-HowTo submit RMarkdown articles to ArXiV

ArXiV is a place for publishing scientific technical reports and drafts which is tightly tied to LaTeX. That is why if you generate a PDF from your RMarkdown article it will tell you, hey, this has been generated using LaTeX, I want the LaTeX source. In principle, RStudio does not admit LaTeX as a final format, only .doc, .pdf or HTML. But it is no big deal.

You only need to add this to the metadata in the RMarkdown document

output: 
  pdf_document:
    keep_tex: true
@JJ
JJ / chart-files-changed.yaml
Created December 23, 2021 08:47
GitHub action step to chart the latest number of files changed in commits using Raku
- name: Install Text::Chart
run: zef install Text::Chart
- name: Chart files changed latest commits
shell: raku {0}
run: |
use Text::Chart;
my @changed-files = qx<git log --oneline --shortstat -$COMMITS>
.lines.grep( /file/ )
.map( * ~~ /$<files>=(\d+) \s+ file/ )
.map: +*<files>;
@JJ
JJ / raku-test.yaml
Last active December 23, 2021 07:18
Github Action for testing Raku modules
name: "Test in a Raku container"
on: [ push, pull_request ]
jobs:
test:
runs-on: ubuntu-latest
permissions:
packages: read
container:
image: ghcr.io/jj/raku-zef-gha
steps:
@JJ
JJ / xmas-tree.raku
Created December 18, 2021 19:45
Painting a Xmas tree with Text::Chart
use Text::Chart;
my @data = < 1 2 3 4 5 6 7 6 5 4 3 2 1 >;
my $midway = (@data.elems/2).truncate;
my $max = max(@data);
my &left-pad = { " " x $midway ~ $_ ~ "\n"};
say left-pad("✶") ~ vertical( :$max, @data ) ~ left-pad("█") x 2;
@JJ
JJ / text-char.raku
Last active December 18, 2021 19:26
Embedding Text::Chart code
unit module Text::Chart;
constant $default-char is export = "█";
sub vertical ( Int :$max = 10,
Str :$chart-chars = $default-char,
*@data ) is export {
my $space = " ";
my @chars = $chart-chars.comb;
@JJ
JJ / adm.md
Last active September 26, 2021 16:39

Desde el punto de vista del estudiante (y también del profesor que viene más tarde) hay un tipo de asignaturas que vamos a denominar AdM (que evidentemente significa Asignaturas diseñadas Malamente) que tienen una serie de carencias, lo que causa una serie de actitudes en el estudiante. Vamos a tratar de caracterizar aquí estas diferencias

AdM Asignatura no-dM
En muchos casos, el contenido o el propio concepto de la asignatura no tiene nada que ver con la realidad laboral actual Hay un esfuerzo por estar al día de esa realidad laboral y usar siempre ejemplos y conceptos cercanos a la realidad conceptual y laboral
El que juzga si algo está bien o no es el profesor Los conceptos y si están bien o mal se pueden mirar en cualquier lado
En algunos casos, "lo que quiere el profe que escriba" está en contra de las buenas prácticas aprendidas en la práctica laboral Si hay alguna mala práctica o antipatrón, se puede solicitar una corrección y nunca resulta en mala nota