Skip to content

Instantly share code, notes, and snippets.

View olegnikitashin's full-sized avatar

Oleg Nikitashin olegnikitashin

  • Adjust
  • Berlin, Germany
View GitHub Profile
@olegnikitashin
olegnikitashin / user.rb
Created November 12, 2018 14:19 — forked from harlow/user.rb
Extract a validator in Rails. Zip code validation.
# app/models/user.rb
class User < ActiveRecord::Base
validates :zip_code, presence: true, zip_code: true
end
@olegnikitashin
olegnikitashin / rails-jsonb-queries
Created October 8, 2018 15:28 — 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")
@olegnikitashin
olegnikitashin / signer.rb
Created September 18, 2018 11:31 — forked from oestrich/signer.rb
Signing Google Cloud Storage URLs
private_key = "..."
client_email = "..."
bucket = "..."
path = "..."
full_path = "/#{bucket}/#{path}"
expiration = 5.minutes.from_now.to_i
signature_string = [
"GET",
@olegnikitashin
olegnikitashin / readme.md
Created August 24, 2018 11:19 — forked from maxivak/readme.md
Integrating Gem/Engine and Main Rails App
Rails Singleton Model
Taken from:
http://stackoverflow.com/questions/399447/how-to-implement-a-singleton-model/12463209#12463209
@olegnikitashin
olegnikitashin / subdomains.rb
Created July 11, 2018 11:32 — forked from andersonfreitas/subdomains.rb
Support for Rspec / Capybara subdomain integration testing
# Support for Rspec / Capybara subdomain integration testing
# Make sure this file is required by spec_helper.rb
#
# Sample subdomain test:
# it "should test subdomain" do
# switch_to_subdomain("mysubdomain")
# visit root_path
# end
DEFAULT_HOST = "lvh.me"
@olegnikitashin
olegnikitashin / Gemfile
Created June 15, 2018 13:06 — forked from ctalkington/Gemfile
Nginx, Sinatra, and Puma.
source :rubygems
gem "puma"
gem "sinatra"
@olegnikitashin
olegnikitashin / docker-cleanup-resources.md
Created March 11, 2018 14:36 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

require 'benchmark/ips'
def concat_string a, b
a + b
end
def interpolate_string a, b
"#{a}#{b}"
end