Skip to content

Instantly share code, notes, and snippets.

View esteedqueen's full-sized avatar
😼

Esther Olatunde esteedqueen

😼
View GitHub Profile
@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 / 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 / puma.md
Last active August 31, 2018 18:16
Puma gem install w/ ruby 2.0.0, rails 3.2 on MacOS 10.12

If you're installing puma version below 3.7 or 3.8, because puma requires openssl, you'll get the following error when you attempt to install the puma gem either directly or from a Gemfile:

Building native extensions.  This could take a while...
ERROR:  Error installing puma:
	ERROR: Failed to build gem native extension.

    current directory: /Users/esther/.rbenv/versions/2.3.0/gemsets/contagious/gems/puma-2.6.0/ext/puma_http11
/Users/esther/.rbenv/versions/2.3.0/bin/ruby -r ./siteconf20170830-2950-8i5exi.rb extconf.rb
creating Makefile
@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 / 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 / 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