There are a lot of ways to do this, but I searched for the title of this post and got few results.

One solution is to write some custom middleware.

Here’s a great guide: https://lmiller1990.github.io/electic/posts/custom_middleware_in_rails_5.html

You can specify different behavior based on status codes:

  def call(env)
    @status, @headers, @body = @app.call(env)
    if @status == 400
      # do something here
    end
    [@status, @headers, @body]
  end

And you’ll need to add your middleware to the configs:

# config/environments/development.rb
config.middleware.insert_before ActionDispatch::ShowExceptions, MyMiddleware

Suppose you’re building a Rails app for Users who attend many Events, such that a User has_many :events. Now, suppose you want to query for all the Users who have attended an Event that occurred within the last week.

One simple way would be to fetch all the Events and, through those, grab all the Users that attended them, but this wouldn’t work well if we wanted to associate more complex filtering with Users, or use more complex joins.

When you’ve got a problem like that, this article by Richard Jones is phenomenal! I’ve needed to do this at two jobs and have a hard time dredging up this article, so I’m linking it here.

The gist is to use scenic to create and manage database views:

CREATE VIEW newest_events AS
  SELECT DISTINCT ON (user_id) *
  FROM events
  ORDER BY user_id, created_at DESC

My keycaps have improved!

After a lot of trial and error, I finally realized if you put more resin in the bottom of the two part mold, you’ll avoid the massive air bubbles. Now I can consistently make keycaps without gaping holes (and without a pressure pot).

Here are my “cucumber mint” and “watermelon” keys.

keycaps on keyboard

keyboard close up

 

Recently, we’ve been talking a lot about video games with our friends. It reminded me 11 years ago I made a game for the Nintendo DS Lite.

I don’t have any of the assets anymore except for these two screenshots:

title screen

game screen

It was neat to learn about all DS Lite hardware and thinking about processors and CPUs. Reminds me a little of Android development.

I’ve been watching the L2K tutorials on Youtube to learn to cast keycaps.

While the tutorials are fantastic, I had to watch several times to compile a list of materials. I’m starting from scratch so I needed to acquire everything.

For the Two-Part Silicone Mold

For the Resin Keys

  • Polyurethane resin (I accidentally got epoxy resin, but they have similar properties)
  • Resin dye (any solid/mica dye or a liquid dye)
  • Mold release (see above)
  • Sand paper (to polish the keycap bottom)
  • Pressure pot (I don’t have one but the videos strongly recommend this)

General supplies

  • Graduated syringes (you’ll need to mix 1:1 ratios for silicone and resin; catheter tips are better than Luer locks or needles)
  • Disposable containers (I’m using plastic egg cartons and other household plastic refuse)
  • Stirrers (any small stick will work)