-
Linked headings in your BridgetownRB site
BridgetownRB is a powerful and flexible “progressive site generator” written in Ruby. I use it to publish this blog. One feature that I wanted to support with my blog is having headings that provide a quick anchor link to that section of the page. In this post, I want to walk you through the simple steps to add this feature to a Bridgetown site.
Continue reading … -
Branch-specific databases
This is the first in a collection of posts where I want to highlight ways we can enhance our Ruby on Rails applications. Specifically, in this first series, I want to dig into the ways that we can take advantage of and empower using SQLite as the database engine for our Rails applications. In this inaugural post, let’s dig into how using SQLite as our database engine opens up powerful new possibilities for our local development workflow; specifically, allowing us to have and use branch-specific databases.
Continue reading … -
Generating Hex-ULIDs in Ruby
In the previous post, we explored how to generate a base16-encoded ULIDs with only native SQLite functions. In the end, we built an expression that will generate hex-ULIDs for us:
SELECT PRINTF('%012X', CAST(ROUND((JULIANDAY('now') - 2440587.5)*86400000) AS INTEGER)) | HEX(RANDOMBLOB(10)) AS qulid;This expression will return a 32 character string like
0184E14B9D33DF0EA40E00D20FC31406
, which encodes a 48 bit timestamp and an 80 bit random portion, producing a 128 bit blob just like ULIDs and UUIDs. The string is composed of an 12 character base16-encoded timestamp and a 20 character random portion.But what if we need to generate a hex-ULID in Ruby?
Continue reading … -
SQLite Hex-ULIDs
Identifiers are an essential aspect of any database schema design. There are various approaches with their various pros and cons. There are likewise various database engines. Today, I want to explore generating universally unique, sortable identifiers in SQLite.
Continue reading … -
Handling variables
The third in a series of posts laying out the process, step by step, of building an interpreter in Ruby for working with propositional logic. In this post, we expand the interpreter to work with variable expressions in classical propositional logic, like
Continue reading …~p & q
. Since we are dealing with variable expressions and not fixed expressions (like~T & F
), we need to be able to output full truth tables, and not simply resolve the final boolean output. -
Slideover Bootstrap Modals
Sometimes we don’t want a modal floating in the center of the viewport; sometimes, we want a full-height modal that slides into frame. Luckily, we can write a bit of CSS to extend the Bootstrap
Continue reading …modal
component to support slideover modals. -
Rails Forms and Request Parameters
Sometimes in our Rails applications we need to build forms that represent state stored in URL query parameters that is independent of any persisted object in our backend datastore, like in the case of a search form. In this post I offer a simple, flexible, generic helper for doing just that.
Continue reading … -
Flattening Nested Hashes in Ruby
Sometimes, especially when working with external data, you will be handed a thickly nested blob of JSON, represented in Ruby as a nested hash. I have found in my experience that processing this data is often simpler when we can work with a flat hash instead, collapsing the key paths into a simple array key. And so, I wrote a function that does just this – it flattens a nested hash into a flat hash.
Continue reading … -
Expecting Exceptions in Ruby
Sometimes in Ruby code, having to use the
Continue reading …begin ... rescue .. end
construction to capture and deal with exceptions can feel overly burdensome. I recently found myself in such a situation and wrote a small function to make my code read a bit more elegantly. -
Safely Accessing Values from Nested Hashes (again)
Implementing a companion method to
Continue reading …Hash#dig
that always returns a value and never throws an error and allows for a default return value.