Skip to content

Instantly share code, notes, and snippets.

View shkrt's full-sized avatar

Ruslan Gafurov shkrt

View GitHub Profile
@shkrt
shkrt / rails-jsonb-queries
Created June 9, 2020 17:26 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@shkrt
shkrt / arel_cheatsheet_on_steroids.md
Created February 8, 2020 10:58 — forked from ProGM/arel_cheatsheet_on_steroids.md
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@shkrt
shkrt / toc.md
Created October 13, 2017 15:57 — forked from matugm/toc.md
Table Of Contents

Ruby Deep Dive - Table Of Contents

  • Using Pry to Learn Ruby
    • The Power of Pry
    • Where did this method come from?
    • Debugging using Pry
  • Understanding Exceptions
    • What are Exceptions and Why They Happen
    • Understanding Stack Traces
  • Using Exceptions
def match_host(issue_url)
Matchers::GitHost.(issue_url) do |m|
m.success(:github) { |issue_data| Services::GithubIssueRequester.(issue_data) }
m.success(:gitlab) { |issue_data| Services::GitlabIssueRequester.(issue_data) }
m.failure do
error('invalid url')
INVALID_URL_ERROR
end
end
end
def match_host(issue_url)
Container['matchers.git_host'].(issue_url) do |m|
m.success(:github) { |issue_data| Container['services.github_issue_requester'].(issue_data) }
m.success(:gitlab) { |issue_data| Container['services.gitlab_issue_requester'].(issue_data) }
m.failure do
error('invalid url')
INVALID_URL_ERROR
end
end
end
@shkrt
shkrt / README.md
Last active September 30, 2017 06:49

This temporary workaround is helpful, when test-kitchen is unable to connect to centos vm box via ssh with following error messages:

Waiting for SSH service on 127.0.0.1:2222, retrying in 3 seconds
Waiting for SSH service on 127.0.0.1:2222, retrying in 3 seconds
Waiting for SSH service on 127.0.0.1:2222, retrying in 3 seconds
Waiting for SSH service on 127.0.0.1:2222, retrying in 3 seconds

For kitchen create to work properly, one should create Vagrantfile.rb (extension is mandatory here) anywhere, and specify the path to this file in .kitchen.yml. The only content of this custom Vagrantfile is insert_key setting, because it's not being parsed properly by test-kitchen, when provided in .kitchen.yml.