• JSON Web Token basics

    A JSON Web Token (JWT) is an internet standard for representing claims securely between two parties. JWTs contain three parts: the *header*, the *payload*, and the *signature*. They are joined together by `.` to create a JWT like: `aaaaaa.bbbbb.ccccc`. Example JWT Decoded Header Payload Signature Encoded When to use a JWT? – Authorization – After…

  • React Component Intro

    React, a popular JavaScript library for building user interfaces, is known for its component-based architecture. A React component is essentially an independent, reusable piece of code that returns HTML to be rendered on the page. These components are the building blocks of React applications, enabling developers to create complex UIs from small, isolated pieces of…

  • Stimulus Intro

    Stimulus is the Rails team JavaScript framework which intends to provide an elegant and simple solution to enhancing HTML interactivity without reaching for the complexity of a full Single Page Application (SPA). It’s meant for developers looking to augment their normal Rails, server-rendered pages with just a bit of client-side JavaScript. Stimulus is used to…

  • Binstubs

    Binstubs, short for “binary stubs,” are small executable scripts that act as wrappers around Ruby executables or scripts. They are commonly used in Ruby projects managed with Bundler to provide a convenient way to execute commands without needing to prepend them with bundle exec. When you run `bundle install –binstubs` Bundler will create a bin…

  • Ruby Benchmark

    If you just want to see how fast a bit of code is you can use the Benchmark module which is part of the Ruby Standard Library. If you want to compare two or more bits of Ruby code that do the same thing and see how fast they are against each other then you…

  • Link_to and Link_to_unless

    Building a navigation bar in Rails is pretty easy. You simply write up something like: And you get a set of urls for your link that look like this: However if you are on the “Docs” page already then you dont’t really need the “Docs” link to be a link. It could just be text.…

  • Using Service Objects to extract business logic.

    The Rails defaults work really well. You start with really nice, clean models and controllers. You can view them all as one page of code and hold an idea of what they do in your head. Problem is that they keep getting bigger as you add features and eventually they balloon out of control. Giant…

  • Why do we bundle exec?

    A common question I get is why do we need to prepend a command with bundle exec? Running the command by itself seems to work most of the time so what is difference? We know that rake db:migrate (for example) is the command we want to run. We know that bundle install is how you…

  • Ruby Case statements from if/else

    Reading nested if statements making you sad? Case statements can be the answer. Refactoring your if statements can clear up complicated code and make spotting bugs much easier. Nested if statements often lead to complex and hard-to-read code. They can grow over time as new conditions are added, making it difficult to maintain and debug.…

  • Classes, Hashes, Structs and OpenStructs in Ruby

    Intro If I am looking to maximize the performance of a Ruby app what should I be using? Hashes, Structs, OpenStruct, or Classes? New Ruby programmers love hashes. I love hashes. They are very flexible and tempting to add in everywhere. Even when refactoring a slow part of the system in Kafka microservices so that…