Michael Anhari

Blog

Getting to know your Rails dbconsole (PostgreSQL)

Let's go over a few commands that are helpful when poking around in the Postgres console
databasespostgreSqlrails

Goodbye webpack?

A few backend frameworks are looking to replace webpack with something less heavy-handed, Rails included.
elixirjavaScriptphoenixrailsruby

Adding counter caches to existing models in Rails

Counting the amount of records that exist is a very common task for your database. Rails has a built-in mechanism for caching this value to reduce the number of round trips.
databasespostgreSqlrailsruby

Ensuring a column is unique for an entity in Rails

Sometimes you want to validate that a column is a unique for a given relationship and not across the entire table.
databasespostgreSqlrails

How to use acronyms in the classes of your Rails application

Acronyms are strange to implement in Ruby, but are easy to manage in Rails when leveraging ActiveSupport.
railsruby

Using namespaces to organize your Rails code base

Sometimes you want to namespace areas of your application to group related code together, and Rails has support for this baked in.
architecturerailsruby

Grabbing the last result in common Rails debuggers

Sometimes you want to access the value returned by the last command you wrote into a Ruby REPL. There’s a trick for that.
ruby

Using i18n to customize submit button text in Rails

The Rails submit form helper populates the button's text by using a humanized/readable version of the model's class name. Sometimes that isn't idea, but i18n has our backs.
i18nrails

Why I no longer define ActiveRecord scopes with class methods

ActiveRecord scopes can be defined using the scope method or class methods on your model using the self keyword, but there is an important difference between the two.
rails

Using dbconsole to index and test Rails query performance on the fly

Rails ships with a command for loading up the REPL for your database that can be useful for testing out the effectiveness of adding indexes to lower query response times.
databasesperformancepostgreSqlrails

Two features of Ruby that helped me demystify Rails

Rails has been said to have "too much magic". I think a lot of that can be attributed to two of its syntax decisions.
railsruby

Returning an empty result set from ActiveRecord that doesn't break method chaining

Rails 4 added the null object pattern to ActiveRecord relations. Let's see how we can leverage it to avoid no method errors down the stacktrace.
databasesrails

Adding custom data types to your Postgres database in Rails

Postgres allows you to create a custom column type with its own constraints. Let’s try implementing one in Rails.
databasespostgreSqlrails

Wrapping business logic in ActiveRecord transactions

Creating records in a loop is easy with ActiveRecord, but how do we handle rolling back changes when something goes awry?
databasespostgreSqlrails

Why does ActiveRecord store empty strings?

I recently realized a puzzling behavior of ActiveRecord.
databasespostgreSqlrails

Creating related records with ActiveRecord

Setting foreign keys manually is fine, but ActiveRecord gives us another way.
railsruby

RESTful routes for all the things

Rails allows you to define custom routes as you see fit, but what happens to the architecture of our application if we try to limit ourselves to using RESTful actions in our controllers?
architecturerailsrest

Copy text to a user’s clipboard using Stimulus.js

A copy to clipboard button can really make the lives of your users a bit easier. Let’s build one using Stimulus.js.
javaScript

Restart your Rails server with less ceremony

Tired of stopping and starting your Rails server? Rails has a command for that!
devToolsrails

Squashing N+1 queries in Rails

One of the drawbacks of using an ORM like ActiveRecord is unknowingly building a query that splits into thousands in your views.
databasesrails

Configuring Ruby REPLs

Sometimes you want to push something from your Rails console to your clipboard. Let’s configure your Ruby consoles globally to make it easy.
devToolsruby

Configuring your rails new command with a railsrc file

The rails new command ships with a lot of flags to tweak Rails to fit your needs. If you find yourself using the same flags consistently, you might want to make them added by default.
devToolsrails

Guaranteeing unique values for a database column in Rails

ActiveRecord provides a unique validation, but is it enough?
databasesrailsruby

Breaking the space-time continuum in your test suite with Timecop

Where we’re going, we don’t need roads. Sometimes you need to time travel or freeze time altogether in the world of your test suite. Let’s do it with Timecop.
devOpsrailsrubytesting

Coulda, woulda, shoulda-matchers

Test the stuff you’re constantly doing in Rails without all of the hassle.
railstesting

Generating randomized test data in Rails with Faker

Faker is a lighthearted library that pairs well with FactoryBot to generating fake data.
railsrubytesting

Rails test objects up and running with FactoryBot

Let's talk about how to spin up objects and database records for our tests using factory_bot_rails from thoughtbot.
railsrubytesting

Manage programming runtime versions with FZF and asdf

Manage versions for multiple programming languages in a sane way using a powerful combo of two CLI tools.
clidevTools

Migrating or rolling back a specific migration in Rails

Sometimes you just need to target a single database migration in Rails. Let's talk about how to do so.
databasesrails

Use italics in any VS Code theme

A quick guide to making any VS Code theme appear like a theme with an "Operator" variant.
vsCode

MIT 6-3

An unofficial guide for "enrolling" in MIT's Computer Science and Engineering using their free online courses.
computerScience

VS Code boot tasks

A quick walkthrough of setting up a boot task in VS Code to kick off your project's processes.
devToolsrailsvsCode

Saving your VS Code settings on GitHub

Setup an easy system for making your VS Code settings transferrable to a new machine.
devToolsgitvsCode

Test-Driven Development (TDD) with Rails 5: Model Testing

This is the third post of a three part series that covers using test-driven development in Rails 5.
railsrubytesting

Test-Driven Development (TDD) with Rails 5: Integration Testing

This is the second post of a three part series that covers using test-driven development in Rails 5.
railstesting

Test-Driven Development (TDD) with Rails 5: System Testing

This is the first post of a three part series that covers using test-driven development in Rails 5.
railstesting

Python-backed Vim super snippets with UltiSnips

Let's walk through building some crazy powerful vim snippets using python and UltiSnips.
devToolspythonvim

vim-stargazer: fuzzy find and open your starred repositories from Vim

Introducing a vim plugin that allows you to fetch, fuzzy find, and open your starred repositories on GitHub.
rubyvim

Blogging with Vim

Blogging in vim sounds painful (borderline sadistic) at first, but it can be configured to be a very pleasant experience.
vim

Formatting text to a desired width in vim

Formatting lines in vim to wrap at your preferred text width.
vim

Vimming around in Firefox with Vimperator

[Vimperator has sadly been deprecated] Using vimperator to navigate Firefox with your keyboard.
devToolsvim

Searching for answers in open source on GitHub

A quick tip on how to search open source code for examples to learn from.
git