Skip to content

Instantly share code, notes, and snippets.

View tbilous's full-sized avatar

Taras Bilous tbilous

  • Varna, Bulgaria
View GitHub Profile
@tbilous
tbilous / capybara cheat sheet
Created July 16, 2016 10:43 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@tbilous
tbilous / rubocop_pre_commit_hook
Created October 11, 2016 17:22 — forked from palkan/rubocop_pre_commit_hook
Rubocop pre-commit hook
#!/usr/bin/env ruby
ADDED_OR_MODIFIED = /^\s*(A|AM|M)/.freeze
changed_files = `git status --porcelain`.split(/\n/)
unstaged_files = `git ls-files -m`.split(/\n/)
changed_files = changed_files.select { |f| f =~ ADDED_OR_MODIFIED }
changed_files = changed_files.map { |f| f.split(" ")[1] }
@tbilous
tbilous / Guardfile
Created October 11, 2016 17:22 — forked from palkan/Guardfile
Guardfile for Rails
# По умолчанию запускаем только необходимых для тестов наблюдателей,
# то есть всех, кроме server.
# Для запуска всех: bundle exec guard -g default
scope groups: ['specs']
group 'specs' do
# запускаем тесты и использованием Spring
guard :rspec, cmd: "bundle exec spring rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
@tbilous
tbilous / create.js.erb
Created October 31, 2016 22:24
remove nested form
var form = $('#new_answer'),
alert = form.find('#error_validation');
alert.remove();
<% if @answer.errors.any? %>
form.prepend('<%= j render 'layouts/shared/error_form', object: @answer %>');
<% else %>
$('#answersList').append('<%= j render @answer %>');
form.find('#answer_body').val('');
@tbilous
tbilous / monit
Last active March 13, 2018 13:38
### Nginx ###
check process nginx with pidfile /opt/nginx/logs/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if memory usage > 80% for 5 cycles then restart
if failed host 127.0.0.1 port 80 protocol http
then restart
if 3 restarts within 5 cycles then timeout
require 'open-uri'
require 'nokogiri'
require 'mechanize'
require 'json'
# example data
=begin
[{'id'=>'1505439',
'code'=>'XY',
'name'=>
onReady = ->
searchSelector = 'input.typeahead'
bloodhound = new Bloodhound(
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title'),
queryTokenizer: Bloodhound.tokenizers.whitespace
remote: "/en/autocomplete/index.json?q=%QUERY"
limit: 10)
bloodhound.initialize()
$(searchSelector).typeahead null,
class SearchesController < ApplicationController
before_action :load_search, except: [:create, :new ]
def index; end
def show ; end
def new
@search = Search.new
end
class Search < ApplicationRecord
# string :destination
# date :checkin
# date :checkout
# integer :adults
# integer :children
# integer :rooms
# string :locale
# string :currency
# string :state
ready = ->
current_locale = I18n.locale
dataContainer = $('#searchData')
paginationContainer = $('#pagination-data')
sortSearches = (data) ->
if data.status == 'ready'
data = data.results
if data