Feed powered byStream Blue Logo Copy 5Created with Sketch.
Avatar of Jerome Dalbert

Jerome Dalbert

Backend Engineer at StackShare

Decision about Visual Studio Code, Atom, Vim, Sublime Text, TextEditor

Avatar of jeromedalbert
Backend Engineer at StackShare ·
Visual Studio CodeVisual Studio Code
AtomAtom
VimVim
Sublime TextSublime Text
#TextEditor

I liked Sublime Text for its speed, simplicity and keyboard shortcuts which synergize well when working on scripting languages like Ruby and JavaScript. I extended the editor with custom Python scripts that improved keyboard navigability such as autofocusing the sidebar when no files are open, or changing tab closing behavior.

But customization can only get you so far, and there were little things that I still had to use the mouse for, such as scrolling, repositioning lines on the screen, selecting the line number of a failing test stack trace from a separate plugin pane, etc. After 3 years of wearily moving my arm and hand to perform the same repetitive tasks, I decided to switch to Vim for 3 reasons:

  • your fingers literally don’t ever need to leave the keyboard home row (I had to remap the escape key though)
  • it is a reliable tool that has been around for more than 30 years and will still be around for the next 30 years
  • I wanted to "look like a hacker" by doing everything inside my terminal and by becoming a better Unix citizen

The learning curve is very steep and it took me a year to master it, but investing time to be truly comfortable with my #TextEditor was more than worth it. To me, Vim comes close to being the perfect editor and I probably won’t need to switch ever again. It feels good to ignore new editors that come out every few years, like Atom and Visual Studio Code.

7 upvotes·3.3K views

Decision at StackShare about Ruby, StackDecisionsLaunch, ID

Avatar of jeromedalbert
Backend Engineer at StackShare ·
RubyRuby
#StackDecisionsLaunch
#ID

For stack decisions, I needed a non-sequential ID format to prevent users from guessing other IDs. My options were:

  • UUIDs v4 that look like this: 496a52cd-49ba-4424-99d9-344e44803cb1
  • Hashids that look like this: xpAYDx0m
  • Flake IDs whose Mastodon Ruby implementation looks like this: 101151084044583231

I eventually chose flake IDs, because IMO they are better-looking and easier to type.

Although they are meant for distributed systems at scale (think Twitter), for my feature I only cared about how nice they looked. As a bonus, because the first few bits are time-based, they "feel" like good old incremental IDs. #StackDecisionsLaunch

6 upvotes·2 comments·3.5K views

Decision about Git, Heroku, Rails, PersonalStack, ProjectGenerator, Productivity

Avatar of jeromedalbert
Backend Engineer at StackShare ·
GitGit
HerokuHeroku
RailsRails
#PersonalStack
#ProjectGenerator
#Productivity

Rails is great because "all the decisions are made for you", right? But I wouldn't be writing this decision if this were truly the case. ;-)

rails new and boilerplate generators are nice, but you still have to spend some time adding your favorite gems, tools, formatting files to your standards, removing unused functionality, and configuring deploys. Only after all of this can you truly begin to code.

That’s why I made a shell script (yeah, Rails generators are overkill) that creates a new app from a boilerplate app I preconfigured. Everyone has different tastes and levels of seniority, so I am not sharing this app to the public. Just know that it has different Git branches that my shell script can choose: master (default config), devise, forms, worker, etc. It comes bundled with the tools listed in my personal stack.

All I have to do is run the script, follow the README, and 2 minutes later my app is running a hello world page on Heroku! I cannot stress how powerful it is to have a professional-grade application ready and deployed in 2 minutes. It feels like I’m cheating the system. These superpowers have proved invaluable for personal projects, hackathons and professional projects alike.

Productivity ProjectGenerator PersonalStack

5 upvotes·1 comment·4K views

Decision at Gratify Commerce about AWS Elastic Beanstalk, Heroku, Rails, PaaS

Avatar of jeromedalbert
Backend Engineer at StackShare ·
AWS Elastic BeanstalkAWS Elastic Beanstalk
HerokuHeroku
RailsRails
#PaaS

When creating the web infrastructure for our start-up, I wanted to host our app on a PaaS to get started quickly.

A very popular one for Rails is Heroku, which I love for free hobby side projects, but never used professionally. On the other hand, I was very familiar with the AWS ecosystem, and since I was going to use some of its services anyways, I thought: why not go all in on it?

It turns out that Amazon offers a PaaS called AWS Elastic Beanstalk, which is basically like an “AWS Heroku”. It even comes with a similar command-line utility, called "eb”. While edge-case Rails problems are not as well documented as with Heroku, it was very satisfying to manage all our cloud services under the same AWS account. There are auto-scaling options for web and worker instances, which is a nice touch. Overall, it was reliable, and I would recommend it to anyone planning on heavily using AWS.

5 upvotes·2.8K views

Decision about Rails, PostgreSQL, DataTypes, Lookups

Avatar of jeromedalbert
Backend Engineer at StackShare ·
RailsRails
PostgreSQLPostgreSQL
#DataTypes
#Lookups

Does your PostgreSQL-backed Rails app deal with slugs, emails or usernames? Do you find yourself littering your code with things like Model.where('lower(slug) = ?', slug.downcase)?

Postgres strings are case-sensitive, but you often want to look these fields up regardless of case. So you use downcase/lower everywhere... You may refactor this inconvenience in dedicated methods like find_by_slug, but all too often your team will forget about it and use find_by(slug:, leading to inevitable bugs.

What if I told you that you could delegate all this dirty work to Postgres, thanks to the case-insensitive citext type? You can change your column type to citext like so:

class ChangeSlugsToCitext < ActiveRecord::Migration
  def change
    enable_extension('citext')
    change_column :blah, :slug, :citext
  end
end

Now, you can use find_by(slug: as you are used to, and Postgres will internally call lower on the two compared values. Problem solved!

#Lookups #DataTypes

5 upvotes·3 comments·2.6K views

Decision at StackShare about PostgreSQL, Redis, StackDecisionsLaunch, Leaderboards

Avatar of jeromedalbert
Backend Engineer at StackShare ·
PostgreSQLPostgreSQL
RedisRedis
#StackDecisionsLaunch
#Leaderboards

I needed to implement the "Top Contributors" feature of StackShare, that gets updated whenever someone posts a decision. I hesitated between 2 solutions for data storage:

  1. Store real time updates in a Redis sorted set. It's like having a big in-memory hash, but in Redis.

    • Pros: Best for pure real time feedback. Also, Redis sorted sets are cool!
    • Cons: Web devs may not be familiar with Redis sorted sets. Also, we still have to query our traditional DB to enrich Redis results.
  2. Add a cached_score column for the PostgreSQL records shown in the leaderboard. This column is recalculated in our app whenever a record is updated. Make that column indexable for sorting, sort the records by descending order, and voilà, you have leaderboards. Cache the result for X seconds to keep DB queries low while still keeping a more or less "real time" feel.

    • Pros: Web devs are more familiar with traditional DB sorting code.
    • Cons: Every X seconds, you still have to do a DB sort on a big table.

We ended up choosing solution 2 with PostgreSQL for a couple reasons. 1) We currently don't treat Redis as persistent storage and don't have redundancy in place, so data could disappear. 2) Up-to-the-second real time updates weren't mandatory. #Leaderboards #StackDecisionsLaunch

3 upvotes·3.2K views

Decision at StackShare about Rails, Ruby, Markdown, StackDecisionsLaunch

Avatar of jeromedalbert
Backend Engineer at StackShare ·
RailsRails
RubyRuby
MarkdownMarkdown
#StackDecisionsLaunch

I needed to make stack decisions accept a subset of Markdown, similarly to sites like Reddit or Stack Overflow.

I used the redcarpet Ruby gem for parsing, and Rails' sanitize helper made it very easy to only allow certain tags: links, bold, italics, lists, code blocks, paragraphs.

Problem solved! #StackDecisionsLaunch

3 upvotes·2.9K views

Decision at Gratify Commerce about Amazon SQS, Ruby, Sidekiq, AWS Elastic Beanstalk, Rails, delayed_job, BackgroundProcessing

Avatar of jeromedalbert
Backend Engineer at StackShare ·
Amazon SQSAmazon SQS
RubyRuby
SidekiqSidekiq
AWS Elastic BeanstalkAWS Elastic Beanstalk
RailsRails
delayed_jobdelayed_job
#BackgroundProcessing

delayed_job is a great Rails background job library for new projects, as it only uses what you already have: a relational database. We happily used it during the company’s first two years.

But it started to falter as our web and database transactions significantly grew. Our app interacted with users via SMS texts sent inside background jobs. Because the delayed_job daemon ran every couple seconds, this meant that users often waited several long seconds before getting text replies, which was not acceptable. Moreover, job processing was done inside AWS Elastic Beanstalk web instances, which were already under stress and not meant to handle jobs.

We needed a fast background job system that could process jobs in near real-time and integrate well with AWS. Sidekiq is a fast and popular Ruby background job library, but it does not leverage the Elastic Beanstalk worker architecture, and you have to maintain a Redis instance.

We ended up choosing active-elastic-job, which seamlessly integrates with worker instances and Amazon SQS. SQS is a fast queue and you don’t need to worry about infrastructure or scaling, as AWS handles it for you.

We noticed significant performance gains immediately after making the switch.

#BackgroundProcessing

3 upvotes·2.9K views

Decision about Ruby, Rails, PostgreSQL, DataTypes, Hacking

Avatar of jeromedalbert
Backend Engineer at StackShare ·
RubyRuby
RailsRails
PostgreSQLPostgreSQL
#DataTypes
#Hacking

Sometimes I need a quick way to store a list of things, without new PostgreSQL tables and Rails associations. I just want to add a field to an existing table and call it a day. This is useful for simple features, or when the future is uncertain.

For example, you could store T-shirt sizes in a 'S,M,L,XL' string, but then you'd have to join/split when storing/reading. What if I told you that you could delegate all this dirty work to Postgres?

You can store a ['S','M','L','XL'] array with the Postgres array type:

add_column :products, :sizes, :string, array: true, default: []

When reading the value from the DB, Rails will present it to you as a Ruby array. Nice!

And if you want to store hashes like [{ 'size': 'S', 'color': 'Red' }, { 'size': 'M', 'color': 'Green' }], Postgres' jsonb type has you covered too:

add_column :products, :sizes, :jsonb, default: []

Happy #Hacking!

#DataTypes

2 upvotes·791 views

Decision about Insomnia REST Client, GraphiQL, GraphQL, Api, REST

Avatar of jeromedalbert
Backend Engineer at StackShare ·
Insomnia REST ClientInsomnia REST Client
GraphiQLGraphiQL
GraphQLGraphQL
#Api
#REST

Postman is a nice desktop #REST #API client that allows you to save requests for later use. But it does not really support GraphQL, which I use everyday at work. So it was time to look for something else.

GraphiQL is a nice toy that has a desktop client, but you cannot save requests in any organized way. Most other clients I tried were either sluggish, didn't save requests, or didn't support cookies. Lack of cookie support is a no-no for work because we use session-based authentication in our internal API.

Then I stumbled upon Insomnia REST Client, and it clicked! Cookies work, GraphQL support is pretty good, UI looks nice and goes straight to the point. The only thing it lacks is a schema explorer, but I can always use GraphiQL if I ever need one, which is almost never.

Overall, I am very happy with it, and would recommend it to anyone seriously working with GraphQL. Insomnia is a godsend!

1 upvote·2.5K views