Nicer printing of Rails models

I like my models to be printed nicely, to make the class of the model as well as the id and other data available, so, when they end up in a log or console, I can now exactly what it is. I’ve been doing this since before Rails 3 and since Rails projects now have an ApplicationRecord class, it’s even easier.

On my global parent for all model classes, ApplicationRecord I add this:

def to_s(extra = nil)
  if extra
    extra = ":#{extra}"
  end
  "#<#{self.class.name}:#{id}#{extra}>"
end

That makes all records automatically print as:

<ModelName:id>

For example:

<User:123>

which makes the record findable.

But also, allows the sub-classes to add a bit of extra information without having to re-specify the whole format. For example, for the User class, it might be:

  def to_s
    super(email)
  end

so that when the user gets printed, it ends up being:

<User:123:sam@example.com>

which I found helps a lot with quickly debugging issues, in production as well as development environments.

Editing Rails 6.0 credentials on Windows

Rails 6 shipped with a very nice feature to keep encrypted credentials on the repo but separate them by environment, so you can have the credentials for development, staging and production, encrypted with different keys, that you keep safe at different levels.

For example, you might give the development key to all developers, but the production keys are kept very secret and only accessible to a small set of devops people.

You edit these credentials by running:

bundle exec rails credentials:edit --environment development

for the development credentials, or

bundle exec rails credentials:edit --environment production

for production ones. You get the idea.

When you run it, if the credentials don’t exist, it generates a key. If they exist, you need to have the keys. After decrypting, it runs your default editor and on Windows, this is the error I was getting:

No $EDITOR to open file in. Assign one like this:

EDITOR="mate --wait" bin/rails credentials:edit

For editors that fork and exit immediately, it's important to pass a wait flag,
otherwise the credentials will be saved immediately with no chance to edit.

It took me a surprisingly long time to figure out how to set the editor on Windows, so, for me and others, I’m documenting it in this post:

$env:EDITOR="notepad"

After that, running the credentials:edit command works and opens Notepad. Not the best editor by far, but for this quick changes, it works. Oh, and I’m using Powershell. I haven’t run cmd in ages.

Talk to each other, you are missing out

For the past few weeks I’ve been talking to entrepreneurs, trying to help with their problems. I’ve heard both of these statements repeated a few times:

Marketing is easy, but coding is impossible.

Marketeers

and

Building a thing is fun, but then I have no idea how to market it.

Coders

It’s frustrating to hear both this things at the same time. Even within each of the communities, inside Indie Hackers, Microconf, TWiST, we seem to have subgroups of techies and non-techies that talk among themselves but not to one another and they are both wondering where the other ones are.

Please: start talking to one another, you need those connections, your idea need those connections.

If you are either a marketer or a coder and want the other one to join your team as a non-paid co-founder you are asking them to make an investment. A huge investment in terms of personal wealth. A person might be able to start 10 startups in their life, so, you are asking them for 1 tenth of their resources. Act accordingly. Put the effort, show traction, show results. I see people put more effort into talking to an investor that will invest only 1% of their resources.

The second thing a lot of us should do, and this include me, is not focus so much on our own ideas and try to work on other people’s ideas. Build someone else’s thing, market someone else’s thing. Don’t chase one idea, chase the outcome of a successful startup and accept that it might not be your idea.

If you are a developer, know this: whatever idea you come up with, it’s an idea that another developer is likely to have, and likely to implement to compete with you. That’s why there’s so much out there in terms of Twitter clones, issue trackers, cryptocurrencies thingies, etc. A non-coder idea has the value of less competition. A CRM for a niche you’ve never heard of might be the best SaaS ever!

If you are a marketer, know this: even in a crowded space, you can make a difference because there are a lot of companies out there that have a great product and are struggling with marketing. I often find a market need, like, “Private teachers need booking systems” and in my market research I find that the perfect booking system exists and nobody is using it. Lending your superpowers to a developer that’s charging ahead with building yet-another-whatever might be the best SaaS ever!

The Voyager 1 museum

Voyager 1 is, as of now, 22 billion kilometers away from home. One day, we’ll be a space-faring species and we’ll have Voyager 1 in a museum. It’ll be trivial for us to go and reach Voyager but we won’t retrieve it. What’s wonderful about Voyager 1 is not only the amazing science and engineering that we can see on the metal, plastics, cables, circuits, panels, batteries, etc. What’s amazing is it’s vector: direction and speed.

We’ll build a museum around Voyager 1 for people to visit and see it travel. The museum will have to be built very carefully, bringing materials from all directions at the same time, in a balanced way, to avoid affecting Voyager’s trip. Even the visitors will have to be controlled to avoid affecting it.

We’ll marvel at what once was the man-made object furthest away from earth, from home, from the cradle back when all of mankind lived there. Billions of minds will visit it and marvel through the millennia. The museum will act as beacon for commerce and science to stay away of its path… until that day.

One day, Voyager 1’s path will intersect with something else. It might be a planet, an asteroid, a star, a black hole. The odds are astronomical you might think, but so is, well, space and time.

That day unrecognizable humanity will gather to decide what to do. We’ll be mature enough to not need that piece of metal somewhere safe and instead we’ll say good bye.

Part of humanity will gather around, for weeks, maybe even months. We’ll have a festival in space about the 20th century, about how fucked it was, marveling at how close humanity came to self destruction and still produced Voyager 1. We’ll watch movies, attend concerts, both old and new. And eventually, the museum we’ll retreat and so we’ll we. We’ll all watch is silence as a relic of our infancy reaches the end of its life, as it collides and disintegrates. We’ll celebrate it, we’ll mourn it.