Skip to content

Instantly share code, notes, and snippets.

View rpivo's full-sized avatar

Ryan Pivovar rpivo

View GitHub Profile
@rpivo
rpivo / index.md
Last active December 30, 2022 03:13
Comparing Type Assignment, "as", and "satisfies" in TypeScript

Comparing Type Assignment, "as", and "satisfies" in TypeScript

Say we have two types:

Screen Shot 2022-12-29 at 6 55 10 PM

Using these types, I'll look at the similarities and differences between:

@rpivo
rpivo / index.md
Last active June 4, 2022 04:04
Recursion & the Call Stack

Recursion & the Call Stack

Recursion is so powerful. Even with a seemingly small change to the code, the results of a recursive function can be wildly different.

When working with recursive functions, you have a choice of processing a graph top-down, or bottom-up.


Let's look at these two functions. They both traverse through a linked list and print the value of each node.

@rpivo
rpivo / index.md
Last active April 23, 2022 13:21
Giving a component multiple animations in solidjs

Giving a component multiple animations in solidjs

The following example gives a component multiple animations within its animation style prop, resulting in an animation prop that looks something like this:

animation: 3000ms ease 0s infinite normal none running fade-in, 3000ms ease 0s infinite normal none running slide-up, 3000ms ease 0s infinite normal none running fade-out;

The above is essentially three separate animations with all animation properties set, each running infinitely. The animation duration (3000ms) is dynamic based on the interval prop passed to the component. It would be easy to make other animation properties dynamic as well.

@rpivo
rpivo / index.md
Last active November 21, 2021 17:18
Recording Microphone Audio in the Browser
@rpivo
rpivo / index.md
Last active September 18, 2021 13:48
The Left Shift Operator in Rust

The Left Shift Operator in Rust

Quoted from Tutorialspoint:

It moves all the bits in its first operand to the left by the number of places specified in the second operand. New bits are filled with zeros. Shifting a value left by one position is equivalent to multiplying it by 2, shifting two positions is equivalent to multiplying by 4, and so on.

Related Links

@rpivo
rpivo / index.md
Last active September 15, 2021 14:48
Working With Session Objects in the Python Requests Library

Working With Session Objects in the Python Requests Library

Taken from the Python Requests docs:

The Session object allows you to persist certain parameters across requests.

s = requests.Session()

This can be useful for working with cookies (maybe tokens, too).

@rpivo
rpivo / index.md
Last active September 13, 2021 21:59
The `sed` Command

The sed Command

The sed manual describes sed as a "stream editor" (stream editor). It is capable of filtering text and even has regex support.

Examples

As an example, we can create a mock file called example.txt and add text to it.

example.txt

@rpivo
rpivo / index.md
Last active September 14, 2021 01:11
The `impl` Keyword in Rust

The impl Keyword in Rust

Rust doesn't have classes like other object-oriented languages. The impl (implementation) keyword in Rust acts kind of like the class keyword would.

Functions can be defined inside implementations (example taken from docs.rust-lang.org):

impl Example {
    fn boo() {
 println!("boo! Example::boo() was called!");
@rpivo
rpivo / index.md
Last active August 18, 2021 22:51
JavaScript Logger

JavaScript Logger

 function log(lg) {
   const argName = Object.keys({ ...lg }).shift();
   console.info(`${argName}: %c${lg[argName]}`, 'color:#3EC5FF');
 }

 function getFormattedDate() {
const date = new Date();
@rpivo
rpivo / index.md
Last active August 8, 2021 17:37
Using Localstack

Using Localstack

Localstack is a framework for testing AWS services.

These are some nuggets I've collected while working with Localstack.

Installing Localstack

pip install localstack