Skip to content

Instantly share code, notes, and snippets.

View esteedqueen's full-sized avatar
😼

Esther Olatunde esteedqueen

😼
View GitHub Profile

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 / 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
@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 / 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 / MyDBHandler.java
Last active December 13, 2016 12:57
working with sqliteopenhelper
public class MyDBHandler extends SQLiteOpenHelper {
// ...existing methods...
public static class StudentDetailCursor extends SQLiteCursor {
/** The query for this cursor */
private static final String QUERY =
"SELECT _id, _studentname, _phone, _address, lat, lng, zom FROM students ";
/** Cursor constructor */
private StudentDetailCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
@esteedqueen
esteedqueen / .rbenv-gemsets
Last active December 13, 2016 12:30
Rspec TDD intro
tdd
@esteedqueen
esteedqueen / rbenv-howto.md
Created November 8, 2016 16:39 — forked from MicahElliott/rbenv-howto.md
Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.

TL;DR Demo

# Ensure system is in ship-shape.

aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev

@esteedqueen
esteedqueen / migration-error.md
Created November 8, 2016 15:03 — forked from nruth/migration-error.md
rails migration pg_dump: invalid option -- 'i'

If you start to see something like this, e.g. on Heroku since they installed the postgres 9.5 client libraries on their dynos

/usr/lib/postgresql/9.5/bin/pg_dump: invalid option -- 'i'
Try "pg_dump --help" for more information.
rake aborted!
Error dumping database
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/tasks/postgresql_database_tasks.rb:55:in `structure_dump'
@esteedqueen
esteedqueen / osx-homebrew-setup.md
Created November 8, 2016 14:57 — forked from sr75/osx-homebrew-setup.md
Mac Yosemite OSX - Homebrew (RVM/MySQL/Redis) setup

Mac Homebrew (RVM/MySQL/Redis) setup

Follow the steps below to setup a local development environment:

XQuartz

Recommended to download latest XQuartz

iTerm2

@esteedqueen
esteedqueen / show.html.erb
Created June 6, 2016 11:55 — forked from davidphasson/show.html.erb
ERB and the case statement
# Doesn't work
<p>
<% case @request.author_hosted %>
<% when "yes" %>
The school <b>has</b> hosted an author before.
<% when "no" %>
The school <b>has not</b> hosted an author before.
<% end %>
</p>