Gem::Ext::BuildError: ERROR: Failed to build gem native extension for the JSON gem

The dreaded Gem::Ext::BuildError: ERROR: Failed to build gem native extension has been in existence since I started dabbling with higher versions of rails.

Fetching gem metadata from https://rubygems.org/...........
Fetching rake 11.2.2
Installing rake 11.2.2
Using i18n 0.7.0
Fetching json 1.8.3
Installing json 1.8.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
/Users/user/.rbenv/versions/2.4.1/bin/ruby -r ./siteconf20170619-29262-1b1jy13.rb extconf.rb
creating Makefile

Remove the Gemfile.lock file

Removing the Gemfile.lock file lets your bundler do its work and find the compatible versions for your gems. Run bundler and you’ll have a nice install and have a new Gemfile.lock file.

Bundle complete! 51 Gemfile dependencies, 177 gems now installed.

Voila!

 Git: Could not read from remote repository error

ERROR: Permission to user-coder/repo-name.git denied to your_username.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Permissions

Ask the repo owner if he has added you as a collaborator. If not, this is most likely your problem.

Invitations

A common error when collaborating with other users on Github. The most common way to fix this is to check for any invitations from the said repository. Accepting this invitation would ultimately fix your problem.

Zpmbif

 Javascript: Find an object by the value of a property

There are many reasons to look for objects by the value of one of its properties. Here’s a way:

const PLANS = [
  {
    id: 1,
    title: "Personal",
    billing_cycle: "Annual",
    amount: "$15",
    best_value: true,
    features: [
      "Lorem Ipsum sit amet dolor benefit here 1",
      "Lorem Ipsum sit amet dolor benefit here 2",
      "Lorem Ipsum sit amet dolor benefit here 3",
      "Lorem Ipsum sit amet dolor benefit here 4"
    ]
  },
  {
    id: 2,
    title: "Enterprise",
    billing_cycle: "Annual",
    amount: "$50",
    best_value: false,
    features: [
      "Lorem Ipsum sit amet dolor benefit here 1",
      "Lorem Ipsum sit amet dolor benefit here 2",
      "Lorem Ipsum sit amet dolor benefit here 3"
    ]
  }
];

ES6

let id ='1';
let selectedPlan = PLANS.find(plan => plan.id ===6);

UnderscoreJS

Option #1

var selectedPlan = _.findWhere(PLANS, {id: 6});

Option #2

var selectedPlan = _.find(PLANS, function (obj) {
  return obj.id === 6;
});

 Create Migrations for HStore, JSON and JSONB with Rails

JSONB, JSON and things like HSTORE are good for when you can’t use a normalized data model, such as when the data model changes rapidly and is user defined.

Of course, the main rule is that if you can model them relationally, you should. And if you can choose between the options, JSON, JSONB and HSTORE, the priority should be JSONB, JSON and then HSTORE.

Here’s a comprehensive resource on the matter: When to use unstructured datatypes in Postgres–Hstore vs. JSON vs. JSONB

In most cases JSONB is likely what you want when looking for a NoSQL, schema-less, datatype. Hstore and JSON can have their place as well but it’s less common. More broadly, JSONB isn’t always a fit in every data model. Where you can normalize there are benefits, but if you do have a schema that has a large number of optional columns (such as with event data) or the schema differs based on tenant id then JSONB can be a great fit. In general you want:

* JSONB – In most cases
* JSON – If you’re just processing logs, don’t often need to query, and use as more of an audit trail
* hstore – Can work fine for text based key-value looks, but in general JSONB can still work great here

Here’s a migration sample for Rails for JSONB:

class CreateAccountSubscriptions < ActiveRecord::Migration
  def change
    create_table :account_subscriptions do |t|
      t.date :start_date
      t.date :renewal_date
      t.decimal :amount,precision: 10, scale: 2, default: 0
      t.string :billing_cycle
      t.string :name
      t.json :details
      t.string :payment_type
    end
  end
end
### Migration...
== 20180405011531 CreateAccountSubscriptions: migrating =======================
-- create_table(:account_subscriptions)
   -> 0.0408s
== 20180405011531 CreateAccountSubscriptions: migrated (0.0409s) ==============

Here’s a migration sample for Rails for JSON:

class CreateAccountSubscriptions < ActiveRecord::Migration
  def change
    create_table :account_subscriptions do |t|
      t.date :start_date
      t.date :renewal_date
      t.decimal :amount,precision: 10, scale: 2, default: 0
      t.string :billing_cycle
      t.string :name
      t.jsonb :details
      t.string :payment_type
    end
  end
end
### Migration...
== 20180405011531 CreateAccountSubscriptions: migrating =======================
-- create_table(:account_subscriptions)
   -> 0.0420s
== 20180405011531 CreateAccountSubscriptions: migrated (0.0421s) ==============

Here’s a migration sample for Rails for HSTORE:

class CreateAccountSubscriptions < ActiveRecord::Migration
  def change
    enable_extension 'hstore' unless extension_enabled?('hstore')
    create_table :account_subscriptions do |t|
      t.date :start_date
      t.date :renewal_date
      t.decimal :amount,precision: 10, scale: 2, default: 0
      t.string :billing_cycle
      t.string :name
      t.hstore :details
      t.string :payment_type
    end
  end
end
### Migration...
-- extension_enabled?("hstore")
   -> 0.1217s
-- enable_extension("hstore")
   -> 0.3896s
-- create_table(:account_subscriptions)
   -> 0.0880s
== 20180405011531 CreateAccountSubscriptions: migrated (0.5996s) ==============