TIL about the attention economy

As a UX designer, the product you create will constantly compete for users’ attention. If users are paying attention to one thing, like a notification on their mobile phone, it means they’re ignoring something else, so users have to be selective about how they spend time! This battle over users’ attention is referred to as the attention economy.

The term attention economy originated with psychologist and Nobel Laureate Herbert A. Simon, who believed that there are limits on what humans can think about and do at one time. Many scientists believe that humans aren’t very good multitaskers; technology should help users, not distract them. The more distracted a person is, the less likely they are to complete a task well.

Learned by aldo-mosqueda on Jun 14, 2021

973983 adforcodereview v3 0211021 c02 021121

Set and preserve cookies on and Axios API call

I was using Axios to test an API created in Rails, trying to set up cookies for a User Authentication process. After attempting to get the information back i realize that the cookie was not persistent, due to the lack of one parameter... withCredentials: true So if you want your session to store cookies in the client side and have them available remember to pass it to the call import axios from import axios from 'axios' axios.post(API_SERVER + '/login', { email, password }, { withCredentials: true }) Otherwise the cookie would not be saved.

Learned by fabian-alcala on Jun 10, 2021

The Mehrabian rule

Today I learn the Mehrabian 7-38-55 rule. The rule states that: 7% of meaning is communicated through spoken word 38% through tone of voice, and 55 % through body language.

It was developed by psychology professor Albert Mehrabian at the University of California, Los Angeles.

So... it is always a good idea to keep our cameras on at every meeting ;)

Learned by aldo-mosqueda on May 28, 2021

Other errors when installing Capybara Webkit Gem - M1 Mac Big Sur

Well, it turns out that installing capybara-webkit gem can give you different problems, in my case I had to install

capybara-webkit -v '1.15.1'.

You need to install QT as a dependecy.

The latest versions of QT including 5.6 returns the following message:

QtWebKit is no longer included with Qt 5.6

I followed one of our guides here, however it appears that QT version 5.5 was removed.

cd $( brew --prefix )/Homebrew/Library/Taps/homebrew/homebrew-core
git checkout 9ba3d6ef8891e5c15dbdc9333f857b13711d4e97 Formula/qt@5.5.rb
brew install qt@5.5

curl: (22) The requested URL returned error: 404
Error: Failed to download resource "qt@5.5_bottle_manifest"
Download failed: https://ghcr.io/v2/homebrew/core/qt/5.5/manifests/5.5.1_1

I also tried through binary installer but I got the following error:

Error creating SSL context

I finally succeeded, installing an older version

brew tap cartr/qt4
brew install qt@4
brew install qt-webkit@2.3
gem install capybara-webkit -v '1.15.1'

Building native extensions. This could take a while...
Successfully installed capybara-webkit-1.15.1
1 gem installed

Learned by jennifer-ledezma on May 26, 2021

973983 adforcodereview v3 0211021 c02 021121

while on a Capybara / Cucumber test execution How to save and open the page as snapshot in a browser for inspection

While debugging a cucumber test (within an specific step for an specific scenario) with a binding.pry I wanted to see the html as it is with inputs and outputs of data at the moment (and because I usually run tests with Capybara headless option), I realized the existance of:


it Saves a snapshot of the page and open it in a browser for inspection


Note: ^ be sure to have the gem 'launchy' within test env so that it works

Learned by victor-delarocha on May 12, 2021

Fixing the Capybara Webkit Gem installation - QtWebKit is no longer included with Qt 5.6 error on M1 Mac with Big Sur

If you installed any version above 5.6 make sure you uninstall all those versions, for instance:

MacBook-Air:myproject heridev$ brew uninstall qt
Uninstalling /usr/local/Cellar/qt/6.0.3_2... (8,233 files, 158.7MB)
MacBook-Air:myproject heridev$ brew uninstall qt@5
Uninstalling /usr/local/Cellar/qt@5/5.15.2... (10,688 files, 367.9MB)

Then we need to install the 5.5 version (old version):

cd $( brew --prefix )/Homebrew/Library/Taps/homebrew/homebrew-core
git checkout 9ba3d6ef8891e5c15dbdc9333f857b13711d4e97 Formula/qt@5.5.rb
// this will install the qt from shopify/shopify
brew install qt@5.5

And make sure you add the qt PATH in my case:

echo 'export PATH="/usr/local/opt/qt@5.5/bin:$PATH"' >> /Users/heridev/.bash_profile
source ~/.bash_profile

Now, you should be able to install the capybara webkit gem without any problems

Learned by heriberto-perez on May 5, 2021

973983 adforcodereview v3 0211021 c02 021121

User Stories

As a [UX Designer] I want to [embrace Agile] so that [I can make my projects user-centered]

TIL that User Stories were originated as part of the Agile and SCRUM development methodologies. A tool so simple yet so powerful, it is a great design method that enhances collaboration.

Read the entire article: https://bit.ly/3tkB3RE

Learned by aldo-mosqueda on May 5, 2021

Control email deliveries in Rails with a custom Interceptor

You can easily tell Rails to control email delivering with a custom mailer interceptor, all you need to do is to implement the class method delivering_email:

class DeliverOrNotEmailInterceptor
  def self.delivering_email(email)
    mail.perform_deliveries = !email.to.end_with?('special-domain.com')

# config/initializer/email_interceptors.rb

Learned by Edwin Cruz on May 4, 2021

973983 adforcodereview v3 0211021 c02 021121

Safe access for nested key values in a Hash - dig method

If you are using Ruby 2.3.0 or above

Now instead of doing this:

result.try(:[], 'avatar').try(:[], 'model').try(:[], 'raw_attributes').try(:[], 'signup_state')
# or
result && result['avatar'] && result['avatar']['model'] && result['avatar']['model']['raw_attributes'] && result['avatar']['model']['raw_attributes']['signup_state']

Now you can easily do the same with dig:

result.dig('avatar', 'model', 'raw_attributes', 'signup_state')

Learned by heriberto-perez on Apr 28, 2021

973983 adforcodereview v3 0211021 c02 021121

How to add an image to a gist

1.- Create a gist

2.- Clone your gist:

# make sure to replace `<hash>` with your gist's hash
git clone https://gist.github.com/<hash>.git # with https
git clone git@gist.github.com:<hash>.git     # or with ssh

3.- Open it & move your image

cd <hash>
mv ~/Desktop/image.jpg ~/Projects/gist/image.jpg

4.- Add your image to your gist's repository:

git add image.jpg

5.- Commit the image:

git commit -m "Add image"

6.- Update gist:

git push origin master


Learned by Victor Velazquez on Apr 22, 2021

How to understand the SQL behind an ActiveRecord Query

Quick example, to see and understand better how an ActiveRecord query using scopes or methods in the model works at the SQL level and how to run it, all in the same example

Ruby version

Let say you have a database with users and you have some scopes to filter by non-demo, active, and completed providers with a specific Role (CanCanCan behind the scenes) :


Let's look into the SQL version:

If we run this command

irb(main):007:0> User.providers.real.active.completed.to_sql

We would get this:

=> "SELECT \"users\".* FROM \"users\" INNER JOIN \"users_roles\" ON \"users_roles\".\"user_id\" = \"users\".\"id\" INNER JOIN \"roles\" ON \"roles\".\"id\" = \"users_roles\".\"role_id\" WHERE (roles.name = 'Provider') AND \"users\".\"demo_account\" = 'f' AND (\"users\".\"organization_id\" NOT IN (SELECT \"organizations\".\"id\" FROM \"organizations\" WHERE \"organizations\".\"demo_account\" = 't' ORDER BY \"organizations\".\"name\" ASC)) AND \"users\".\"is_active\" = 't' AND \"users\".\"signup_state\" = 'Completed'"

Then we just need to replace the invalid characters such as \ and translate that into a SQL version like this:

WITH real_providers AS
  ( SELECT users.* FROM users
    INNER JOIN users_roles ON users_roles.user_id = users.id
    INNER JOIN roles ON roles.id = users_roles.role_id
    WHERE (roles.name = 'Provider') AND users.demo_account = 'f'
      AND (users.organization_id NOT IN (
        SELECT organizations.id FROM organizations WHERE organizations.demo_account = 't' ORDER BY organizations.name ASC)
      AND users.is_active = 't' AND users.signup_state = 'Completed')
select real_providers.id, real_providers.name from real_providers

In order to run it in the Rails console for example:

report_results = ActiveRecord::Base.connection.execute(SUMMARY_PROVIDERS_REPORT_SQL)

That will give you the id and name of all those valid providers

Learned by heriberto-perez on Apr 21, 2021

973983 adforcodereview v3 0211021 c02 021121

:is() pseudo-class - CSS

When we apply the same style to multiple selectors on CSS we use to do something like this:

.section-header h1,
.section-header span,
.section-header .heading {
  line-height: 1.2;
.navigation li,
.navigation p {
  padding: 5px 10px;

With :is() we can write our CSS in a shorter way.

.section-header :is(h1, span, .heading) {
  line-height: 1.2;
.navigation :is(li, p) {
  padding: 5px 10px;

Learned by carlos-pineda on Apr 19, 2021

973983 adforcodereview v3 0211021 c02 021121

Notes on getting my M1 Rails + Foreman environment working

I expect this to evolve quickly and different things seem to be working for different people. In the meantime, hope to avoid a few rabbit holes for others.

  1. rvm worked for ruby 3.0.0 but not 2.6.6 (which is what I needed). cflags workarounds made it so ruby could get installed but gems with native extensions like grpc could not compile correctly. Tried asdf before trying rbenv and it worked, so I stuck with asdf.
  2. Had to prepend every brew installation (including brew itself) with arch -x86_64 brew install ....
  3. After installing asdf, I installed bundler as usual. No arch -x86_64 or anything. Same for bundle install afterwards.
  4. This DriftingRuby episode helped a lot.

I don't think the following were necessary but this is what I did because installing things with brew was getting hairy:

  1. Use Postgres.app to keep PostgreSQL running in the background, deleted it from my Procfile. Naturally, I have to start Postgres manually before I start Foreman.
  2. Downloaded ElasticSearch binaries and put the path in my Procfile. Essentially /Users/jose/dependencies/elasticsearch/elasticsearch-#.#.#/bin/elasticsearch

Learned by jose-farias on Apr 9, 2021

973983 adforcodereview v3 0211021 c02 021121

Using Gem::Dependency class manually to ensure version matching

I needed to add a mechanism to ensure that some actions of a controller were available only for specific versions, and I thought it was super similar of what Gemfile does, so I started to look how to use Gem::Dependency to solve this, and turns out it was super easy:

class Controller
  def feeds_one
    check_for_version_support('>= 1.0', '< 3')

    render json: SomeData.all

  def feeds_two
    check_for_version_support('= 1.0')

    render json: SomeData.all

  def feeds_three
    check_for_version_support('>= 2.1')

    render json: SomeData.all


  def check_for_version_support(*specification)
    checker = Gem::Dependency.new(action_name, specification)

    return if checker.match?(action_name, params[:version])

    raise VersionNotSupported, "Version not upported"

Learned by Edwin Cruz on Apr 7, 2021

P.A.R.A. Method

P.A.R.A. stands for Projects — Areas — Resources — Archives

A Project is “a series of tasks linked to a goal, with a deadline.”

An Area of responsibility is “a sphere of activity with a standard to be maintained over time.”

A Resource is “a topic or theme of ongoing interest.”

Archives include “inactive items from the other three categories.”

This Method has captured my attention and has been an exceptional tool for assign our projects, tasks, and resources.

Learned by juan-castillo on Apr 6, 2021

973983 adforcodereview v3 0211021 c02 021121

use bundle open gemname

You can take a peek at a locally installed gem's code very easily in ruby mine.
If you are using another IDE it would require a few extra steps:
First, set BUNDLER_EDITOR in ~/.bashrc or ~/.zshrc (or whatever shell you are using)
export BUNDLER_EDITOR="code"
(code to use VS code)
Then, simply run $ bundle open gemname and voilá! Look at whatever gem you want

Learned by Eduardo Gutiérrez on Apr 6, 2021

973983 adforcodereview v3 0211021 c02 021121

Ruby 2.7 introduced numbered parameters for blocks

Since Ruby 2.7, it is possible to use numbered parameters in blocks additionally to named parameters.

This is an example of a block with named parameters:

my_array.each { |element| element.do_something }

And this is the same line with numbered parameters:

my_array.each { _1.do_something }

This works with multiple parameters too:

# named parameters
my_hash.each_pair { |key, value| puts "#{key}: #{value}" }

# numered parameters
my_hash.each_pair { puts "#{_1}: #{_2}" }

Learned by kevin-perez on Mar 30, 2021

973983 adforcodereview v3 0211021 c02 021121

Browsers' IndexedDB are shared across domain

I was working on a major refactor for a PWA which basically changed the DB schema by reducing the amount of versions, nothing outstanding. BUT, I didn't change the DB name.

I was puzzled why whenever accessing the previous version I had to delete the data to have the app load correctly, then I realized that despite the PWA being located at different URL paths, both versions were using the same IndexedDB because of the same domain policy.

Learned by juan-guajardo on Mar 19, 2021

Using Upsert with Rails

Some DBMS support natively something that behaves like update or insert, Rails recently added the method Upsert that can take advantage of this method.

It is useful to update information that do not need to run validations, meaning, in a super performant way, here's an example:

# We usually do this:
activity = current_user.activity
if activity 
  activity.update(last_seen_at: Time.current)
  current_user.activity.create(last_seen_at: Time.current)

But if you see, it does not need to run any validation, it just needs to update last_seen_at if exists or create a new one, it performs two queries: one to instanciate the activity object and a second one that performs the real update/insert statement.

That can be replaced with the following code and it will perform just a single query and it will take care to either create the record or update an existing one

Activity.upsert({ last_seen_at: Time.current, user_id: current_user.id}, unique_by: :user_id)

To make this really work, considering you use Postgresql, you have to add a unique index on user_id and modify default value on created_at and updated_at in a migration like this:

query = <<-SQL
  ALTER TABLE #{Activity.table_name}

Learned by Edwin Cruz on Mar 19, 2021

973983 adforcodereview v3 0211021 c02 021121

What is your car color?

Did you know that your car color can say a lot about how you want to be perceived by other people? Here is a list of some colors and their own meanings.

White: This color evokes freshness, cleanness, youth, and modernity.

Black: This is the most popular color in luxury vehicles. Black can be described as a sexy, powerful, and mysterious color.

Silver: This color is linked to a sense of innovation and modernity, that is why a lot of high tech products go for silver.

Red: This is a bold color, if your car is red this might mean you want to show an image of power, action, and confidence.

Blue: Blue is often described as the color of stability and safety. If your car is blue this might mean you are a trustworthy person.

Yellow: If you drive a yellow car might mean that you are a happy person or maybe a person who likes to take risks.

Gray: If you have a gray car this could mean you are a person who does not want to stand out, and prefers something a bit more ¨subtle¨ instead.

Learned by omar-miranda on Mar 19, 2021

Better usage of Rails logger

Logging usefull data is a hard task, but there's one specific method that helps to improve the experience of logging actual useful information: tagged. It adds extra tags to the log message making it easy to debug:

Rails.logger.tagged('Super App') do
  Rails.logger.info('Log Message')

This will result in somethin like this:

[Super App] Log Message

If you can see, it prepends usefull information, you could add personalized data to trace logs, for example:

class ApplicationController << ActionController::Base
  around_action :add_logger_tags

  def add_logger_tags
    Rails.logger.tagged(logging_tags) do

  def logging_tags
      "Request Id: #{request.id}",
      "Session Id: #{session.id}",
      current_user && "User id: #{current_user.id}"

And you will have super nice logs to read

Learned by Edwin Cruz on Mar 18, 2021

973983 adforcodereview v3 0211021 c02 021121

Creating an infinite loop in Ruby

If you need to iterate over a collection that its size is unknown, you can create an infinite loops in ruby easily, but if you need an index, then there's this option:

(1..).each do |page|
  results = ExternalService.get('/endpoint', page: page)
  parsed = JSON.parse(response.body)
  break if parsed['data'].empty?


Learned by Edwin Cruz on Mar 16, 2021

How to use my local browser and get access to the server on Circle CI with port-forwarding

This helped me to debug a failing test, that was only happening on the CircleCI Server.

How to do it?

  1. Go to Details Job Page on the Circle CI app and re-run the job as Rerun Job with SSH. image

  2. You should be able to find an additional step called Enable SSH, just expand it to see a command similar to this ssh -p 64625 ubuntu@ but with minor differences (the port number and IP address will be different). Copy the command into your terminal.

  3. Paste it and append this -L 3000:localhost:4000. With this, every request happening on the port 4000 (CircleCI server) will be forwarded to my local computer in the port 3000, so my local browser can reach the CircleCI server directly.

    $ ssh -p 64625 ubuntu@ -L 3000:localhost:4000

  4. Lastly, change of directory, go to your application folder and serve your app in port 4000.

    $ cd my-app-directory && <command to serve your app>

    In this example, I ran yarn run dev which runs a server on the port 4000.

  5. Go to the browser and visit the localhost:3000.

Learned by rogelio-alatorre on Mar 12, 2021

973983 adforcodereview v3 0211021 c02 021121
973983 adforcodereview v3 0211021 c02 021121

Is it possible to render a "sidecar" partial for a ViewComponent?

Let's say I have

class MyComponent < ViewComponent::Base

and 2 view files in


In my_component.html.erb, I want to be able to do:

render "some_partial"

But without a special configuration, that looks under the views directory for said partial. I don't want to extract that partial to its own component, nor do I want it floating by itself in the view directory.

The first step is to tell Rails it can look for templates in the view components directory

class ApplicationController < ActionController::Base
  append_view_path "#{Rails.root}/app/components"

Keep in mind that view contexts are based on the currently executing controller, so <%= render :some_partial %> in a PostsController (even within a ViewComponent class) will look for a partial in a subdirectory /posts or /application.

To make sure Rails finds your partial, use an absolute path when you render it:

<%= render "/my_component/some_partial" %>

Hat tip to Roli in the StimulusReflex discord

Learned by obie-fernandez on Mar 10, 2021

More about randomness

If you want to generate random but predictable sequences of numbers, then the rand command and the srand are not enough, you have to use a trick to save the state of the variable. Fibers are primitives for implementing light weight cooperative concurrency in Ruby. Basically they are a means of creating code blocks that can be paused and resumed, much like threads. The main difference is that they are never preempted and that the scheduling must be done by the programmer and not the VM.

require 'rspec'

#i = pseudo_random 10
#p i.resume => 37
#p i.resume => 12
#p i.resume => 72
def pseudo_random num
  srand 1

  fiber = Fiber.new do
    num.times do
      Fiber.yield rand 100

describe 'Pseudo Random number generator' do
  it 'creates the same sequence of random numbers' do
    random_sequence = pseudo_random 3
    expect(random_sequence.resume).to eq(37)
    expect(random_sequence.resume).to eq(12)
    expect(random_sequence.resume).to eq(72)

Learned by enrique-meza on Mar 10, 2021

973983 adforcodereview v3 0211021 c02 021121

Quasi-Random numbers in Ruby

I was interested in random sequence because I was in need to test the Montecarlo Method for getting Pi digits.

One method to estimate the value of π (3.141592…) is by using a Monte Carlo method. This method consists of drawing on a canvas a square with an inner circle. We then generate a large number of random points within the square and count how many fall in the enclosed circle. Pi

So, if you need a random sequence, you can use Sobol for quasi-random numbers.

require 'gsl'

q = GSL::QRng.alloc(GSL::QRng::SOBOL, 2)
v = GSL::Vector.alloc(2)
for i in 0..1024 do
  printf("%.5f %.5f\n", v[0], v[1])

Learned by enrique-meza on Mar 10, 2021

Updating ActiveRecord models without loading an instance using Postgresql

There're sometimes that we need to update an ActiveRecord Model but it is not necesary to load an instance, the normal flow would be the following:

profile = UserProfile.find_by(user_id: id)
profile.update(last_seen_at: Time.now)

The problem with this is that we load a useless instance of UserProfile, it is not needed, in a high traffic sites, an extra select query can count a lot, but luckly, Rails has addressed this with upsert command:

UserProfile.upsert({ last_seen_at: Time.now, user_id: id }, unique_by: :user_id)

This will use native Postgresql upsert command to update a record if it exists or insert a new one and no select will be performed, everything in a single query instead of two.

To make it really work, you need to modify your created_at and updated_at columns to have default current_timestamp

Learned by Edwin Cruz on Mar 10, 2021

973983 adforcodereview v3 0211021 c02 021121

NIX node manager

Use n, an extremely simple Node version manager that can be installed via npm.

Say you want Node.js v12.10.0 to build Ghost template.

npm install -g n   # Install n globally
n 12.10.0          # Install and use v12.10.0
n                            # Output versions installed
n latest                     # Install or activate the latest node release
n stable                     # Install or activate the latest stable node release
n <version>                  # Install node <version>
n use <version> [args ...]   # Execute node <version> with [args ...]
n bin <version>              # Output bin path for <version>
n rm <version ...>           # Remove the given version(s)
n --latest                   # Output the latest node version available
n --stable                   # Output the latest stable node version available
n ls                         # Output the versions of node available

Learned by Victor Velazquez on Mar 10, 2021

973983 adforcodereview v3 0211021 c02 021121
973983 adforcodereview v3 0211021 c02 021121

Using Rails to migrate columns from JSON to JSONB in Postgresql

Postgres offers data type json to store any structure easily, but one dissadvantage is that filtering by properties stored in the json column are super slow, one simple fix before refactoring the whole implementation is to migrate the column to be jsonb, since it is stored in binary form, it supports indexes, a easy and safe way to do it is as follows:

class ModifyJSONDataDataType < ActiveRecord::Migration[6.0]
  def up
    add_column :table_name, :data_jsonb, :jsonb, default: '{}'

    # Copy data from old column to the new one
    TableName.update_all('data_jsonb = data::jsonb')

    # Rename columns instead of modify their type, it's way faster
    rename_column :table_name, :data, :data_json
    rename_column :table_name, :data_jsonb, :data

  def down
    safety_assured do
      rename_column :table_name, :data, :data_jsonb
      rename_column :table_name, :data_json, :data

Then, using another migration(due the ability to disable transactions), add an index to it

class AddIndexToDataInTableName < ActiveRecord::Migration[6.0]

  def change
    add_index :table_name, :data, name: "data_index", using: :gin, algorithm: :concurrently

    # You can even add indexes to virtual properties:
    # add_index :table_name, "((data->'country')::text)", :name => "data_country_index", using: 'gin', algorithm: :concurrently

Learned by Edwin Cruz on Mar 8, 2021

973983 adforcodereview v3 0211021 c02 021121

The slice_when method in Ruby

Creates an enumerator for each chunked elements. The beginnings of chunks are defined by the block.

This method splits each chunk using adjacent elements, elt_before, and elt_after, in the receiver enumerator. This method split chunks between elt_before and elt_after where the block returns true.

The block is called the length of the receiver enumerator minus one.

The result enumerator yields the chunked elements as an array. So each method can be called as follows:

enum.slice_when { |elt_before, elt_after| bool }.each { |ary| ... }

For example:

Return adjacent elements from this array [1, 2, 3, 5, 6, 9, 10] in chunked elements as an array.

[1, 2, 3, 5, 6, 9, 10].slice_when {|i, j| i+1 != j }.to_a
=> [[1, 2, 3], [5, 6], [9, 10]]

Learned by Victor Velazquez on Mar 5, 2021

The each_cons method in Ruby

Iterates the given block for each array of consecutive <n> elements. If no block is given, returns an enumerator.

irb(main):001:0> [1,2,3,4].each_cons(2).to_a
=> [[1, 2], [2, 3], [3, 4]]

irb(main):002:0> [1, 2, 3, 5, 6, 9, 10].each_cons(2).to_a
=> [[1, 2], [2, 3], [3, 5], [5, 6], [6, 9], [9, 10]]

Print any two adjacent words in a given text:

def print_adjacent_words(phrase)
   phrase.split.each_cons(2) do |words|
     puts adjacent_word = words.join(" ")
irb(main):025:0> print_adjacent_words("Hello Darkness my old friend")
Hello Darkness
Darkness my
my old
old friend
=> nil

Learned by Victor Velazquez on Mar 5, 2021

973983 adforcodereview v3 0211021 c02 021121

Optional Chaining Operator (?) and Nullish Coalescing Operator (??)

Optional Chaining Operator(?) (**)

//Car object
const car = {
  attributes: {
   year: 2021,
   model: "Ferrari"

Before in javascript to validate that the attributes of an object exist, it was necessary to use the And operator (&&) to validate if the attributes of the object existed.

See the following example:

if (car && car.attributes && car.attributes.model) {
  console.log('Exist',  car.attributes.model)
} else {
  console.log('Do not exist')

# => "Exist Ferrari"

Now with Optional Chaining Operator (?) We can validate if the property exit will return undefined if the property attributes or model doesn’t exist.

if (car?.attributes?.model) {
  console.log('Exist',  car.attributes.model)
} else {
  console.log('Do not exist')

# => "Exist Ferrari"

Nullish Coalescing Operator(??) (**)

//Car object
const car = {
  attributes: {
   year: 2021,
   model: "Ferrari"

If we want to get the car model then we would like below:

# => "Ferrari"

Now the new car object does not have the model property, so we get an undefined value

//Car object
const car = {
  attributes: {
   year: 2021,
# => "undefined"

To avoid the undefined value the OR (| |) operator can be used, It will now return the value BMW because the property model is undefined. But what if the name property is empty like below example

console.log(car.attributes.model | | "BMW" );
# => "BMW"

Now the problem is when the property model exists but has an empty, undefined or null value we will get the BMW value and this is not right.

//Car object
const car = {
  attributes: {
   year: 2021,
   model: ""
console.log(car.attributes.model | | "BMW" );
# => "BMW"

The solution for this problem is to use the Nullish Coalescing Operator (??), Which will print the result as an empty string.

console.log(car.attributes.model ?? "BMW" );
# => ""

Learned by leyaim-jimenez on Mar 4, 2021

Ruby Double star (**)

def hello(a, *b, **c)
  return a, b, c

a is a regular parameter. *b will take all the parameters passed after the first one and put them in an array. **c will take any parameter given in the format key: value at the end of the method call.

See the following examples:

One parameter

# => [1, [], {}]

More than one parameter

hello(1, 2, 3, 4)
# => [1, [2, 3, 4], {}]

More than one parameter + hash-style parameters

hello(1, 2, 3, 4, a: 1, b: 2)
# => [1, [2, 3, 4], {:a=>1, :b=>2}]

Learned by Victor Velazquez on Mar 4, 2021

973983 adforcodereview v3 0211021 c02 021121


If the interpretation of messages in an oral face-to-face conversation is too subjective —even with clear tones of voice and body language— imagine when communicating through a screen! We have to be assertive AF!   I believe that to be assertive through texts messages we need to consider WRITING RULES such as spelling (correct use of punctuation marks, accents, and capital letters), syntax (the way in which words and the groups they form are combined to express meanings, as well as the relationships established between all these units), and semantics (the meaning and changes in the meaning of words and expressions).   To the point> Semantically speaking, it is important to consider that there are two divisions in this area: denotation and connotation.   The denotation: This is the original or formally accepted expression of the word, this is the word that is formally found in encyclopedic dictionaries and is universally accepted.   Connotation: Connotation is the alternate or secondary form in which a word is used, such as is the case with the word donkey, which in denotative form implies the equine type animal, and in the connotative form the dumb man or person.   Get it? So, we have to be super conscious of the meaning and power of the words we choose when having written conversations. Is like: the connotation of the words OCUPO and NECESITO could be similar, but the correct thing to say, because of the denotation of the words, is NECESITO QUE ME AYUDES ME ACORREGIR ESTE CODIGO.   It is better that way so we don't misunderstand things. And if so, nothing better than talking to eliminate misunderstandings, right? Talking-communicating is the best way to understand each other, the best way to organize ourselves.   It is good to be sincere and direct. But, we must try to be assertive. And, in my opinion, there is a fine line between being assertive, sincere, or direct > and rude. To be assertive the message must get through to the receiver correctly, otherwise, it's not.


Learned by graciela-virgen on Mar 3, 2021

973983 adforcodereview v3 0211021 c02 021121
973983 adforcodereview v3 0211021 c02 021121

Optional Chaining in JavaScript

The Optional Chaining Operator ? allows you to read the value of a property located deep within an object without having to validate each property in the object. It works in a similar way than the chaining operator ., except that instead of causing an error if a reference is nullish, the expression will return a value of undefined.

A common way to validate properties was to do something like this:

const player = {
  stats: {
    stamina: 40

let stamina
if (player && player.stats) {
  stamina = player.stats.stamina

This was done because calling player.stats.stamina directly could led into an error being thrown if stats didn't exists, and sometimes even the execution would stop.

Using the Optional Chaining Operator, we could do something like this:

const player = {
  stats: {
    stamina: 40

const stamina = player.stats?.stamina

The result is shorter and simpler, and in case stats didn't exists the value would be undefined, without an error being thrown.

Learned by ricardo-santoyo on Mar 1, 2021

973983 adforcodereview v3 0211021 c02 021121

Remove Rails model's fields without crashing on production

If you are experiencing problems after removing an attribute from a Rails model it is probably because ActiveRecord has cached that field, it is something normal is intended to help to improve performance on production environments but when removing a field may cause errors because Rails is training to read/writer a column that doesn't exist anymore, so for Rails 5 and newest we have the ignore_columns setting to fix this issue, simply add it to your model something like:

class MyModel < ApplicationRecord
  self.ignore_columns = %w[field_to_ignore]

And you are good to go! if you want to be warned or remind to your team you would like to consider using the strong migrations gem https://github.com/ankane/strong_migrations

Learned by ozmar-ugarte on Mar 1, 2021