Suggestions For Not Forgetting To Remove Unused Code

    I am working on a significant update/rewrite of part of KickoffLabs. I had a task to work through what we do in a Sidekiq worker. It was late on Friday when I got to this part of the code, and I decided to punt on it until Monday.

    Monday morning, I grab a cup of coffee and sit down to finish this section off and see a comment I missed (and had missed for a long time).

    Code Comment, Remove in August 2019

    Outside the screenshot, there is an if statement, ensuring this code was not executed in the last four years. Still, it was frustrating that we had missed removing it for so long.

    I figured ChatGPT would have a good solution to stay on top of this, but it mostly just tried to explain to me how to use comments. :)

    Next up, I asked on Twitter (and Ruby.Social):

    Any suggestions (other than search) to ensure code like this gets cleaned up?

    From there, I got a lot of good suggestions.

    Two Ruby gems looked interesting:

    If I had to choose, I would go with todo_or_die since it would cause a failure/notification locally. I would rather not wait until there was a pull request/etc.

    The rest of the suggestions included if statements and date checks. My favorite, and the one I will likely adopt going forward, is to wrap it in a test that fails after a specific date.

    From Minutes to Seconds

    I am tired of guessing the future of AI. What I am sure of, something routine like this used to take significantly longer than it does today.

    In the past:

    1. Google a bit; maybe find someone asking a similar question somewhere (hopefully, do not get distracted by something else).
    2. Goto the docs (which often took Google to find)
    3. Try and find something related to what you were doing.
    4. (Sometimes) Apply what you learn in step #3 to your problem.

    Now, we are back to a quick search, which is kind of like Google in the old days.

    Code showing how to update the payment method on a subscription in Braintree

    The Fall of the 10X Developer

    This piece by Justin Searls has been making the rounds for a week or so.

    The Fall of the 10X Developer

    My quick take: AI is leveling the developer playing field a bit. You still need to ask it proper questions to get good results. We have known for quite a while that colleges do not prepare you to be a good developer in the real world. AI won’t solve the preparation problem, but it will likely make new hires much more effective sooner.

    Still, like any other career, if you just mail it in, you will not truly grow.

    We must remember that today’s AI is much more pattern recognition than thinking. Maybe that will change, but for now, I still believe it is more assistive for most use cases than a replacement.

    Do you see RuboCop offenses after installing and configuring the Standard VS Code Extension?

    To fix this issue, you need to disable RubyLSP’s diagnostics:

    1
    2
    3
    
    rubyLsp.enabledFeatures": {
        "diagnostics": false
    }
    

    Hat Tip

    This is likely the best post gem install message I have seen (well, next to HTTParty). Well done Stanard team.

    A Helpful Standard Post Install Message

    GPT-Migrate

    If you’ve ever faced the pain of migrating a codebase to a new framework or language, this project is for you.

    We have a bunch of CoffeeScript that I would love to migrate. It is hard to justify the time because it works, but with the improvements made to modern JavaScript, I cannot imagine purposely writing more CoffeeScript at this point.

    Micro.blog Custom Footer For Local Development

    If you want to develop/customize your Micro.blog theme locally, you will likely encounter an issue with a missing file called custom_footer.html. My guess is this file is dynamically added to my Micro.blog at build time.

    To work around this, you can remove the use of {{ partial "custom_footer.html" . }} from your theme (either permanently or temporarily), or you can simply check that it exists first:

    1
    2
    3
    
    {{ if templates.Exists ( "partials/custom_footer.html" ) }}
      {{ partial "custom_footer.html" . }}
    {{ end }}
    

    Next.js to Ruby

    I have been working on converting something from Next.js to Ruby. The Next.js version is still more visually appealing to me, but the benefits of working in Ruby far supior to me long term.

    Before:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
        <Card as="article">
          <Card.Title href={`/articles/${article.slug}`}>
            {article.title}
          </Card.Title>
          <Card.Eyebrow as="time" dateTime={article.date} decorate>
            {formatDate(article.date)}
          </Card.Eyebrow>
          <Card.Description>{article.description}</Card.Description>
          <Card.Cta>Read article</Card.Cta>
        </Card>
    

    After:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    
        {%@ Shared::Card::Card as: :article do %}
          {%@ Shared::Card::Title as: :h2, href: article.relative_url do %}
            {{article.data.title}}
          {% end %}
          {%@ Shared::Card::Eyebrow as: :time, dateTime: article.data.date, decorate: true do %}
            {{article.data.date}}
          {% end %}
          {%@ Shared::Card::Description do %}
            {{article.data.description}}
          {% end %}
          {%@ Shared::Card::Cta do %}Read article{% end %}
        {% end %}
    

    TailwindCSS IntelliSense with Serbea

    I have been experimenting with Serbea templates with Bridgetown and was not able to get TailwindCSS IntelliSense to work.

    Serbea files using the file extension .serb, so my first attempt to configure it looked like this:

    1
    2
    3
    
    "tailwindCSS.includeLanguages": {
      "serb": "html"
    },
    

    However, what I needed to do was specify the file content type:

    1
    2
    3
    
    "tailwindCSS.includeLanguages": {
      "serbea": "html"
    },
    

    Lots of great little PostgreSQL date tricks by @robconery

    Using PostgreSQL to Handle Calendar Data Like a Freak - YouTube

    Finding and Fixing Files in Git with Mixed Case

    I cloned a repo with a couple of files that were duplicated because of case sensitivity. Git was nice enough to warn me about them, but I couldn’t remember which files where an issue.

    Two of them became a problem and were fixed, but I was sure there were more than two when I cloned the repro.

    I found this excellent script to highlight and fix the problem files: git-detect-case-change

    I didn’t realize Bullet Train was now open source (it looks like you have to pay to use Stripe, but that feels very fair).

    I have not dug too deeply into yet, so no opinion other than it is probably worth looking through it before you start your next project.

    Migrating from a Postgres Cluster to Distributed SQLite with LiteFS

    I love me some Postgres, but the SQLite with LiteFS (via @flydotio) just sounds fun.

    Steps to use solargraph for Rails projects in VS Code (WIP)

    This is quite handy. I am unsure how it would handle multiple versions of Ruby, so I skipped updating the shim location and instead just installed the gems in my main 2 Ruby versions.

    A nice quality-of-life improvement in Ruby 3.2 Enumerator::product

    How to validate the presence of a boolean field in a Rails model

    There is a subtle bug that happens when validating the presence of boolean fields in Rails. Ensuring adequate test coverage helps us find those issues before they hit production.

    Crontab.guru

    The quick and simple editor for cron schedule expressions

    I do not write crontabs often, but when I do, it is usually with Crontab.guru.

    Active Record enum form select

    I find myself using this on almost all of my rails projects. I am surprised something like this isn’t available out of the box yet.

    Finally made the autocomplete for IRB in Ruby 3.0 readable with my Dracula color scheme. All it took was changing the terminal’s definition of Cyan. Hopefully, this will be configurable in the future.

    Rails and Docker

    Docked

    Setting up Rails for the first time with all the dependencies necessary can be daunting for beginners. Docked Rails uses a Rails CLI Docker image to make it much easier, requiring only Docker to be installed.

    I have never been efficient with Docker in the past, but the brevity of this Docker file and knowing the hoops I had to jump through over the years with homebrew, rbenv, and more over the years is making me think it might be time to revisit a docker setup and work env.

    David Kimura posted a comment with a more elaborate setup, but this still feels much simpler than what I am doing today.

    RailsBytes

    There are many templates to jump-start a project and few options to add something to an existing project.

    Ruby on Rails templates allow you to add features to both old and new apps. Check out our repository of templates for adding everything from authentication to error monitoring to your apps.

    See: RailsBytes

    A Rubyist’s Introduction to Character Encoding, Unicode and UTF-8

    …learn how character encodings work and how they’re implemented in Ruby. By the end, you’ll be able to understand and fix these errors….

    Starting the explanation with Morse Code was a nice touch.

    Adding Paging Titles for Short Micro.blog Posts

    I noticed posts without titles do not have proper HTML Title tags on my new Micro.blog.

    Even as I type this, I kind of get it. How do you have a title without a title? 🤔

    Many services rely on a title element when building links, and seeing “ScottW’s Blog” (or whatever I eventually name this thing) looks silly.

    I checked the source for a couple other Micro.blog templates and found none of them did anything special to handle the missing title. Most looked something like this:

    1
    
    <title>{{ if not .IsHome }}{{ .Title }} - {{ end }}{{ site.Title }}</title>
    

    After some trial and error, I noticed the .Summary value for the default meta description tag and decided to use that. This is the first ‘code’ I have written in Hugo, so it might need some more tweaking in the future:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
      <title>
          {{ if .IsHome }}
            Home
          {{ else if .Title }}
            {{ .Title }}
          {{ else}}
            {{ .Summary }}}
          {{ end }}
          - {{ .Site.Title }}
      </title>
    

    CSS Loaders 100 sample loaders are all done with CSS. I continue to be amazed at what can be done with CSS, even with a personal goal to write as little CSS as possible for the rest of my life. 😄

    Rails Safety Mechanisms

    An overview of some of the ways Rails protects you from yourself.

Older Posts →