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 / 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.
title: Three-stage compiler structure {
shape: text
near: frontend
style: {
font-size: 80
bold: true
}
}
direction: right
@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.
@uzluisf
uzluisf / data.json
Last active June 15, 2022 23:00
Simple JSON API
{
"recipes": [
{
"name": "scrambledEggs",
"ingredients": [
"1 tsp oil",
"2 eggs",
"salt"
],
"instructions": [
@uzluisf
uzluisf / git-commands-chain.md
Created December 19, 2020 14:43
Git Commands I Forget Too Often

Keeping fork up to date

git clone /url/to/original/repo                     # clone fork
git remote add upstream /url/to/original/repo       # add remote from original repo
git fetch upstream                                  # fetch content from upstream (i.e., repo forked from)
git pull upstream master                            # fetch and merge upstream into master

Clean up fork and restart from upstream

=begin pod :kind("Language") :subkind("Language") :category("tutorial")
=TITLE Iterating
=SUBTITLE Functionalities available for visiting all items in a complex data structure
Similar to other many programming languages, Raku makes a fine distinction among
the terms I<iteration>, I<iterable>, and I<iterator>. Familiarizing yourself
with them is key for understanding the Raku constructs that implement these
concepts:
@uzluisf
uzluisf / delegation-raku.rakudoc
Last active March 8, 2020 14:00
Short write-up about delegation in Raku
=begin pod
X<|Delegation>
=head2 Delegation
Delegation is a technique whereby a member of an object (the I«delegatee») is
evaluated in the context of another original object (the I«delegator»). In other
words, all method calls on the delegator are I«delegated» to the delegatee.
In Raku, delegation is specified by applying the L«handles|/language/typesystem#trait_handles»
trait to an attribute. The arguments provided to the trait specify the methods
@uzluisf
uzluisf / iters.md
Created January 13, 2020 16:53
Iterators and Iterables in Raku [Draft]

Iteration, Iterables, and Iterators in Raku.

What's iteration?

As general concept, iteration can be defined as the process of doing some repeated action over something in order to generate a sequence of outcomes. At a more detailed and programmatic level, iteration is the process of visiting all the elements of an iterable object using another object known as an iterator.

Word Ladder

A word ladder is a sequence of words [w0, w1, ..., wn] such that each word wi in the sequence is obtained by changing a single character in the word wi-1. All words in the ladder must be valid English words.

Given two input words and a file that contains an ordered word list, implement a routine (e.g., find_shortest_ladder(word1, word2, wordlist)) that finds the shortest ladder between the two input words. For example, for the words cold and warm, the routine might return:

("cold", "cord", "core", "care", "card", "ward", "warm")
@uzluisf
uzluisf / ProjectFour.pm6
Created April 20, 2019 17:06
Project 4 for CS253 implemented in Raku Perl 6
unit module ProjectFour;
=begin pod
=TITLE ProjectFour
=SUBTITLE Find a route in map by backtracking using a Stack
The module C<ProjectFour> implements two classes (C<City> and C<RouteMap>)
to find a route, if one exists, from an origin city to a destination city,
given a particular map. In a map, a city B is adjacent to a city A if there's
an arrow pointing from A to B. For example, in N->Q we say that Q is adjacent