Skip to content

Instantly share code, notes, and snippets.

@movstox
movstox / rails-jsonb-queries
Created June 24, 2019 12:54 — 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")
@movstox
movstox / bootstrap-memo.md
Created June 5, 2018 07:54 — forked from yalab/bootstrap-memo.md
rails5 + webpacker + bootstrap
$ echo 'gem "webpacker"' >> Gemfile
$ bundle install
$ rails webpacker:install
$ yarn add [email protected] jquery popper.js
diff --git a/config/webpack/environment.js b/config/webpack/environment.js
index d16d9af..86bf1a7 100644
@movstox
movstox / standalone-capybara.rb
Created April 6, 2018 09:00 — forked from nikhgupta/standalone-capybara.rb
Standalone Capybara Test
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'
module MyCapybaraTest
class Test
@movstox
movstox / wiki_airport_lookup.rb
Last active November 3, 2019 22:39
lookup airport by code via wikipedia
require 'rubygems'
require 'nokogiri'
require 'open-uri'
def find_airport_info(lookup_iata_code)
page = Nokogiri::HTML(open("https://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_#{lookup_iata_code[0]}"))
page.yield_self { |page| page.search('.wikitable tr:contains("%s")' % lookup_iata_code)[0] }.yield_self do |row|
airport_name_row = row.children[5]
airport_info = {
name: airport_name_row&.text,
@movstox
movstox / config.yml
Created January 28, 2018 15:30 — forked from henrypoydar/config.yml
Rails 5.1 CircleCI 2.0 Configuration
version: 2
jobs:
build:
environment:
working_directory: ~/circleci-myapp
docker:
- image: circleci/ruby:2.4.2-node-browsers
environment:
CC_TEST_REPORTER_ID: XXXYYY
RAILS_ENV: test
@movstox
movstox / gist:d5894395c471dda2a05ba8f16b9228c8
Created November 30, 2017 08:48 — forked from ndbroadbent/gist:7575592
SCM Breeze git aliases
GFORCE => git add -A && git commit --amend -C HEAD && git push -f
c => git_index
cbg => git rev-parse --verify HEAD | simple_clipboard
g => git
ga => git_add_shortcuts
gaa => git add -A
gap => git add -p
gash => git stash
gasha => git stash apply
gashl => git stash list
@movstox
movstox / retryable.rb
Last active November 1, 2019 22:39
catch Exception and retry x times
def with_catch_and_retry(*exceptions_to_catch, times, &block)
block.call
rescue *exceptions_to_catch => e
(times -= 1).zero? ? raise(e) : retry
end
context = 'nice'
with_catch_and_retry(Exception, RuntimeError, 3) {
p "123: #{context}"
raise 'something'
## Ryanair.com FE Developer Tests
Choose 1 of the following web apps below, build it and submit it to [email protected] with the subject "Developer Test Web App". ZIP files or public Github URLs will be accepted.
Provide any build commands or runtime requirements (webserver required, extra packages, environment variables) in an INSTALLATION.txt file at the root of the project. The goal is to have the application as easily deployable as possible.
You may use a responsive framework (Foundation, Bootstrap) if you like, but customising the CSS (or SASS) will get you extra kudos. You must use AngularJS as the Javascript framework.
### Cheap flight finder
@movstox
movstox / gist:7945c996ec6fcff0fe8209b08ee0c5f7
Created July 19, 2016 10:43 — forked from fastjames/gist:2725983
Patch to get content_for working with action caching and fragment caching in Rails 3.1
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?
@movstox
movstox / rails content_for caching
Created July 19, 2016 10:39 — forked from stackng/rails content_for caching
make action and fragment caching of rails3 compatible with content_for
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?