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 / get-tags-pod-perl6.sh
Created April 12, 2018 16:39
Extract the tags from the perl6/doc POD6
# git clone perl6/doc, cd doc
git grep "=begin pod" | perl6 -e 'say slurp().split("\n").grep( /tag/ ).map( * ~~ / \<(.+)\> / ).map( *.values.[0] ).join("\n")'
# (「convert」 「convert」 「convert」 「convert」 「convert」 「self」 「tutorial」 「self」 「tutorial」 「perl6」 「self」 「perl6」 「perl6」 「perl6」 「perl6」 「index」 「perl6」 「list」 「tutorial」 「perl6」 「convert」 「perl6」 「perl6」 「perl6」 「perl6」 「perl6」 「tutorial」 「perl6」 「perl6」 「perl6」 「perl6」 「perl6」 「perl6」 「tutorial」 「perl6」 「perl6」 「index」 「perl6」 「convert」 「perl6」 「perl6」 「perl6」 「perl6」 「pod6」 「perl6」 「tutorial」 「index」 「perl6」 「perl6」 「index」 「tutorial」 「perl6」)
@JJ
JJ / failing-c-channels.p6
Last active March 22, 2018 17:02
(Failing) concurrent channels in perl6
my Channel $c .= new;
my Channel $c2 = $c.Supply.batch( elems => 2).Channel;
my $count = 0;
$c.send($_) for ^40;
my $work = start react whenever $c -> $item {
$c.send( $item );
say "This is $item";
}
@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 / sections.p6
Created December 2, 2017 08:48
Finds the "good" in a series of sections
use Text::Markdown;
sub MAIN( Str $letter-to-santa = 'letters/dear-santa-sections.md' ) {
my $letter = Text::Markdown::Document.new($letter-to-santa.IO.slurp());
my $flip = False;
my @paragraphs = $letter.items.grep( { $flip = ($^þ ~~ Text::Markdown::Heading and $^þ.level == 2)?? !$flip !! $flip } );
say so any @paragraphs.map( {$^þ.Str ~~ /good/ } );
}
@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 / letter.elm
Created December 2, 2017 08:45
Letter to santa in Markdown
import Html
import Markdown
letter : Html msg
letter =
Markdown.toHtml [class "content"] """
# Letter to Santa
I've been *real* **good** so I want this for Christmas
1. A Death Star.
2. A green unicorn.
@JJ
JJ / txt.p6
Created December 2, 2017 08:43
Split by `and`
use JSON::Tiny;
sub MAIN( Str $letter-to-santa = 'letters/dear-santa.txt' ) {
say to-json $letter-to-santa.IO.slurp().split(/\s* «and» \s*/);
}
@JJ
JJ / genera-baraja,py
Created July 2, 2017 10:06
Generar una baraja de cartas en una lista en Python
# Tip de https://t.co/tQKo7Err73 para "aplanar" una lista de listas
sum(list(map( lambda n: [str(n)+'♠',str(n)+'♣',str(n)+'♥',str(n)+'♦'], ['A','J','Q','K',2,3,4,5,6,7,8,9,10])),[])
# El map genera una lista de listas, y sum agrega las listas del segundo nivel en una sola, usando la sobrecarga de + para listas
@JJ
JJ / cpu-hog-with-top.sh
Last active July 1, 2017 07:42
Get the process consuming the most CPU with a trimmed down version of ps, i.e., in busybox
# get the list of PIDs and cpu usage via the batch version of top if ps is not fully functional, take out the headers, sort numerically using the 9th column, which is the CPU usage as key, take the last one, and extract the second column
top -n 1 -b | tail -n +8 | sort -k9 -n | tail -1 | cut -d ' ' -f 2