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 August 2, 2021 04:04
The Key Process Patterns From *Specification by Example*

The Key Process Patterns From Specification by Example

In Specification by Example, Gojko Adzic describes a kind of behavior-driven development that makes documentation the central point from which everything else extends. In the book, he outlines key process patterns that organizations can follow to establish business goals, define scope, polish requirements, and write effective, evolving documentation along the way.

Gojko shares these process patterns as happening "just in time" and occurring cyclically rather than as a kind of waterfall pattern. This process workflow should happen when the team is "ready for more work". This allows these key process patterns to comfortably function within Agile sprints.

Gojko appears to mention these patterns not as a strict rubric, but more as process patterns that other successful teams have generally implemented in their own way.

Below is the key process pattern outline as specified by Gojko. This flowchart is an approximation

@rpivo
rpivo / index.md
Last active July 13, 2021 23:59
Different Ways to Call a Node Function From the Command Line

Different Ways to Call a Node Function From the Command Line

Separate Initializer in Its Own File

Pros:

  • Main logic file can contain a variety of different functions/processes that don't have to pertain to the function that's being run.
  • Function can easily be called from other scripts, but also directly from the command line.

Cons:

  • Requires extra file.
@rpivo
rpivo / index.md
Last active July 11, 2021 13:00
Iterating Through Each Letter of a String in Rust

Iterating Through Each Letter of a String in Rust

The String method chars() returns an iterator containing each character of the original string.

fn main() {
    let s = "hello";
    let c = s.chars();
    for x in c { println!("{}", x); }
}
@rpivo
rpivo / index.md
Last active July 10, 2021 13:35
Ownership & Borrowing in Rust

Ownership & Borrowing in Rust

Rust doesn't have traditional garbage collection, but instead has other mechanisms to free up memory as quickly and safely as possible.

One mechanism Rust uses to free up memory is called ownership. This happens when a complex type such as a Vec is used in a different scope than it was declared, which results in the new scope taking "ownership" of the variable.

For simpler types, ownership does not come into play. The below code is completely valid.

fn main() {
@rpivo
rpivo / index.md
Last active July 9, 2021 22:54
Bundling Source Code With Deno's Built-in Bundler

Bundling Source Code With Deno's Built-in Bundler

deno bundle followed by the entry file will create a bundle.

$ deno bundle src/main.ts

The above will output the result to standard out rather than a file.

@rpivo
rpivo / index.md
Last active July 9, 2021 18:36
Using Macros in Rust

Using Macros in Rust

Rust has certain abstractions called macros that are kind of like hooks in React (except that they don't necessarily have anything to do with state). Essentially, they abstract away other Rust code.

A macro is appended with an exclamation point !.

The println! code we use to print to the screen is a macro, as is vec!. They abstract away other code and allow us to write more simplified, clean code.

fn main() {
@rpivo
rpivo / index.md
Last active July 8, 2021 21:00
Using Closures in Rust

Using Closures in Rust

In Rust, inner functions don't automatically have access to outer-scope variables. However, we can create closures using the || {} syntax, which will have access to outer-scope variables.

fn main() {
    let s = "hello";

    let c = || {
 println!("{}", s);
@rpivo
rpivo / index.md
Last active July 7, 2021 23:18
Bringing Types Into Scope With the `Use` Keyword in Rust

Bringing Types Into Scope With the Use Keyword in Rust

Using ES modules in JavaScript, you would import something into a module like so:

import thing from "stuff";

We can achieve similar behavior with Rust types using the use keyword. In the example below, we're importing io from std.

@rpivo
rpivo / index.md
Created July 7, 2021 22:51
Initializing a Cargo Repo in a Preexisting Directory

Initializing a Cargo Repo in a Preexisting Directory

cargo init
@rpivo
rpivo / index.md
Last active July 8, 2021 20:45
Using `std::println` in Rust

Using std::println in Rust

Rust's std::println is similar to loggers in other languages.

fn main() {
    println!("Hello, world!"); // Hello, world!
}