Skip to content

Instantly share code, notes, and snippets.

View mpugach's full-sized avatar

Maksym Pugach mpugach

View GitHub Profile
@mpugach
mpugach / protips.js
Last active August 29, 2015 14:23 — forked from nolanlawson/protips.js
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@mpugach
mpugach / helper.rb
Created May 12, 2015 12:55
rails3-jquery-autocomplete test helper
def choose_autocomplete_result(item_text, input_selector = 'input[data-autocomplete]')
page.execute_script %{ $('#{input_selector}').trigger("focus") }
page.execute_script %{ $('#{input_selector}').trigger("keydown") }
item_selector = "ul.ui-autocomplete li.ui-menu-item:contains('#{item_text}')"
expect(page).to have_selector('ul.ui-autocomplete li.ui-menu-item', text: item_text)
page.execute_script %{ $("#{item_selector}").trigger("mouseenter").trigger("click"); }
end
// create an index with an analyzer "myindex"
curl -X PUT localhost:9200/myindex -d '
{
"settings" : {`
"index":{
"number_of_replicas":0,
"number_of_shards":1,
"analysis":{
"analyzer":{
"first":{
@mpugach
mpugach / debug.rb
Last active January 26, 2017 14:01
Noticeable Rails debug message
# Thanks to http://stackoverflow.com/a/927275/1041467
def debug_msg(msg, title = 'DEBUG')
Rails.logger.debug "\e[5;1;34m#{title}:\e[0m #{msg}"
end
@mpugach
mpugach / puma.rb
Last active August 29, 2015 14:12 — forked from catsby/puma.rb
preload_app!
min_threads = Integer(ENV['MIN_THREADS'] || 0)
max_threads = Integer(ENV['MAX_THREADS'] || 5)
threads min_threads, max_threads
workers Integer(ENV['WORKER_COUNT'] || 3 )
on_worker_boot do
ActiveSupport.on_load(:active_record) do
@mpugach
mpugach / application_controller.rb
Created November 1, 2014 15:34
Rails basic auth
class ApplicationController < ActionController::Base
before_filter :enable_http_auth, if: :use_http_auth?
private
def use_http_auth?
Rails.env.production?
end
def enable_http_auth

Capybara

save_and_open_page

Matchers

have_button(locator)
uk:
errors:
messages:
expired: "прострочено, створіть новий"
not_found: "не знайдено"
already_confirmed: "вже було підтверджено, спробуйте увійти"
not_locked: "не було заблоковано"
not_saved:
one: "Виникла помилка, через яку неможливо зберегти зміни:"
other: "Виникли помилки (загалом - %{count}), через які неможливо зберегти зміни:"
def screenshot
require 'capybara/util/save_and_open_page'
now = Time.now
p = "/#{now.strftime('%Y-%m-%d-%H-%M-%S')}-#{rand}"
Capybara.save_page body, "#{p}.html"
path = Rails.root.join("#{Capybara.save_and_open_page_path}" "#{p}.png").to_s
page.driver.render path
Launchy.open path
end
class CreateRoles < ActiveRecord::Migration
def change
create_table :roles do |t|
t.string :activities, array: true, length: 30, using: 'gin', default: '{}'
t.timestamps
end
end
end
##