Skip to content

Instantly share code, notes, and snippets.

View esteedqueen's full-sized avatar
😼

Esther Olatunde esteedqueen

😼
View GitHub Profile
@esteedqueen
esteedqueen / migrate_postgresql_database.md
Created March 28, 2017 23:52 — forked from olivierlacan/migrate_postgresql_database.md
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important:

@esteedqueen
esteedqueen / postgres error
Created April 11, 2017 04:05
Postgres could not connect to server error after shutdown or restart of MacOS
# could not connect to server: No such file or directory
# Is the server running locally and accepting
# connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Just run this command on the terminal
rm /usr/local/var/postgres/postmaster.pid
@esteedqueen
esteedqueen / scope_for_has_many_relationships.rb
Last active April 16, 2017 00:36
TIL - add scope for has_many relationships by the model's specific attribute(s); not just by the standard rails model_id attribute
# add scope (with one or more attributes) for has_many relationships
# This is great for polyphomism when you want different models to be able to have subscriptions; so that you don't just attach only one model to subscriptions
# Reference: http://edgeguides.rubyonrails.org/association_basics.html#scopes-for-has-many
class Question < ActiveRecord::Base
has_many :subscriptions, -> { where "type = 'Question'" }, :foreign_key => "subscribed_item_id"
end

Background jobs in rails applications make our development lives easier.

We rely on them for a lot of things - common use cases include sending emails, push notifications, processing 3rd party API interactions, transactions and long-running requests that tie up server resources.

In a typical production app, there's a possibility of processing hundreds of jobs per second under normal circumstances and thousands depending on the number of users and campaign going on.

I've been using Resque for a while but recently made a switch to Sidekiq on a few apps. I initially wanted to write about the switch but I soon realized that the knowledge of introducing Sidekiq to a new project is important and the post became really long so I decided to split it. In this post, I'm going to show you how to use Sidekiq for your background jobs on a new rails app. And in part 2, I'll write about switching from an existing app on Resque to Sidekiq.

Why S

@esteedqueen
esteedqueen / multiple_heroku_accounts.md
Last active May 16, 2017 09:06
Managing keys for pushing to multiple heroku accounts

I had a challenge with pushing to another heroku account from my command line...

These are the steps I took to fix the error (redacted) below:

 !  Your account xxx@gmail.com does not have access to xx-heroku-app.
 !
 !  SSH Key Fingerprint: xx:xx:xx...

fatal: Could not read from remote repository.
@esteedqueen
esteedqueen / check_version_conflict.md
Created May 21, 2017 07:46
How I fixed `check_version_conflict` error in rails multiple versions

I have multiple verstions of rails and ruby gems on my machine and I ran into the error below when I tried to run any rails command such as rails -v, rails new new_app, etc.

.../ruby/2.3.0/rubygems/specification.rb:2274:in `check_version_conflict': can't activate activesupport-5.1.0, already activated activesupport-5.0.1 (Gem::LoadError)

Here's how I fixed it.

The version conflict points to ActiveSupport so I ran the command below to check the different versions of activesupport on my machine:

@esteedqueen
esteedqueen / print_page_capybara.md
Created August 12, 2017 23:04
TIL - Logging the page content in capybara

This is useful for when debugging your tests.

Option 1:

puts page.body

Option 2:

save_and_open_page
@esteedqueen
esteedqueen / jq.md
Last active September 21, 2017 16:36
TIL - introducing jq

Today I learnt about jq - "a lightweight and flexible command-line JSON processor".

One of the use cases is pretty-printing JSON response on the terminal.

It essentially makes JSON data more readable on your terminal. If you work with a lot of JSON data on your terminal, you need to install jq.

Before jq:

$ curl localhost:3001/api/food?q=hash+browns
@esteedqueen
esteedqueen / rails_console_docker.md
Last active July 5, 2018 13:54
Access Rails console in a docker container

To access the rails console in a docker container, run:

docker-compose run web rails console
@esteedqueen
esteedqueen / address_in_use_error.md
Created July 31, 2018 00:53
How to handle address already in use error

You attempted to start up a server, only to be confronted with the following error:

Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)

What do you do?

  1. Figure out what service is using that address port.