Skip to content

Instantly share code, notes, and snippets.

View uzluisf's full-sized avatar
💼
On the hunt...

Luis Uceta uzluisf

💼
On the hunt...
View GitHub Profile
@uzluisf
uzluisf / html-tag-exercise.md
Created May 31, 2022 16:42
HTML Tag Class Exercise
  1. Design and implement a class (or other data structure) that can represent a single HTML tag.
my $html-tag = Tag.new("html");
  1. Write a function or method that can print/return the HTML string representation of a tag.
say $html-tag.new("html"); #=> "<html></html>"
  1. Extend tag data structure to model class attributes and content.
title: Three-stage compiler structure {
shape: text
near: frontend
style: {
font-size: 80
bold: true
}
}
direction: right
@uzluisf
uzluisf / nodejs-to-raku-buffers.md
Last active April 2, 2023 22:30
NodeJS to Raku — Buffers

NodeJS to Raku — Buffers

NodeJS handles raw binary data with the classes Buffer and Blob, while Raku does so with the roles Buf and Blob, which are mutable and immutable buffers respectively. In Raku, a Buf composes a Blob so all Blob methods are available to Buf objects.

The following table summarizes the similarities and differences between buffer constructs in NodeJS and Raku:

NodeJS Raku
Buffer/Buf Fixed-length sequence of bytes (No methods such as push, pop, etc.) Sequence of bytes that can grow or shrink dynamically. You can use methods such as push, pop, etc.
Iterable using the for..of syntax It cannot be iterated over using a looping construct. Use the method list to get hold of an iterator.
@uzluisf
uzluisf / collapsible-sections.md
Created May 8, 2023 20:40
Collapsible Sections in Github Markdown

Collapsible Sections

You can get collapsible blocks in Github Markdown by using the <details></details> and <summary></summary> tags. For example,

<details>
<summary>Poe's Law (click to expand)</summary>
A humorous law of Internet forums, stating that "The best way to get the right answer on
the Internet is not to ask a question; it's to post the wrong answer."
@uzluisf
uzluisf / sigilless-sigilled-vars-raku.md
Last active May 29, 2023 23:54
Sigilless and Sigilled Variables in Raku

Sigilless and Sigilled Variables in Raku

There are several differences between sigilless and sigilled variables, which are already documented in the Raku docs. This is simply my attempt at consolidating them in a single place.

Sigil

At the surface, a sigil or lack thereof is the most apparent difference between sigilless and sigilled variables. As their names imply, sigilless variable don't have sigils while sigilled variables do.

my \degrees = pi / 180;

Laws I've Heard Of

The best way to get the right answer on the Internet is not to ask a question; it's to post the wrong answer.

Without a clear indicator of the author's intent, any parodic or sarcastic expression of extreme views can be mistaken by some readers for a sincere expression of those views.

@uzluisf
uzluisf / README.md
Last active June 4, 2023 21:12
Node.js Transform Stream Example

Node.js Transform Stream Example

The JsonLineParser class implements a transform stream (using Node.js v20.2.0's Stream API) to parse a file that contains JSON objects separated by newlines (See data.ndjson). It's adapted from Young and Harter's Node.js in Practice book, especifically Technique 31: Implementing a readable stream.

@uzluisf
uzluisf / create-table-raku.md
Created June 14, 2023 23:56
Small Raku subroutine to pretty print a table.

Raku code

sub create-table(:@headers, :@columns, Bool :$markdown = False --> Nil) {

    unless @headers.elems == @columns.elems {
        $*ERR.spurt: "Table is out of shape: Number of headers must be equal to number of columns.\n";
        $*ERR.flush;
        return;
@uzluisf
uzluisf / dbf-parsing-with-raku.md
Created June 26, 2023 00:53
dBASE: Parsing a Binary File Format With Raku

dBASE: Parsing a Binary File Format With Raku

Working with binary data is kind of like solving a puzzle. You’re given clues by reading a specification of what the data means and then you have to go out and turn that data into something usable in your application.

— Young and Harter’s NodeJS in Practice

Text files, images, videos and anything you can store in a computer have a thing in common: all of them are stored as binary data. We make sense of what a sequence of binary data refers to purely based on how we interpret the binary data, and whether it conforms to what we expect it to be. If some chunk of binary data holds any meaning, we can tell it apart from another chunk by using a binary format specification, which describes how some binary data ought to be interpreted. For example, in the dBASE specification the first 32 bytes make up the header, which contains information such as date of last update, number of records in the database file, etc. Every binary file format you can ima

Original document: http://www.wall.org/~larry/natural.html Author: Larry Wall

Editor's Note: No changes to this document, aside for converting it to Markdown.


Natural Language Principles in Perl

Learn it once, use it many times