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 / random-audio-card-anki.md
Created April 4, 2024 01:51
An Anki card for testing your listening skills.

Anki Random Audio Card

An Anki note type with 5 audios and 5 transcriptions for a single word/phrase, from which one is selected randomly whenever the card is shown. The card has only a front side with the audio, and a collapsible section with the audio's transcription and more info (e.g., definitions, image, etc).

Screenshots image image
@uzluisf
uzluisf / ls-wc-pipes-example.c
Created November 23, 2023 23:59
C program that implements a pipeline between two child processes using fork(), dup2(), and execlp().
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
/*
* C program that implements the pipeline
*
* ls -l /tmp/ | wc -l
*

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

@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

@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 / 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.

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 / 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;
@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 / 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.