Skip to content

Instantly share code, notes, and snippets.

View shilovk's full-sized avatar

Kᴏɴsᴛᴀɴᴛɪɴ Sʜɪʟᴏᴠ shilovk

View GitHub Profile
@shilovk
shilovk / _pay_form.erb.html
Created February 25, 2016 15:39 — forked from vol4ok/_pay_form.erb.html
rails + robokassa example
<form action="<%= @pay_desc['mrh_url'] %>" method="post">
<input type=hidden name=MrchLogin value="<%= @pay_desc['mrh_login'] %>">
<input type=hidden name=OutSum value="<%= @pay_desc['out_summ'] %>">
<input type=hidden name=InvId value="<%= @pay_desc['inv_id'] %>">
<input type=hidden name=Desc value="<%= @pay_desc['inv_desc'] %>">
<input type=hidden name=SignatureValue value="<%= @pay_desc['crc'] %>">
<input type=hidden name=Shp_item value="<%= @pay_desc['shp_item'] %>">
<input type=hidden name=IncCurrLabel value="<%= @pay_desc['in_curr'] %>">
<input type=hidden name=Culture value="<%= @pay_desc['culture'] %>">
<input type=submit value='Оплатить'>
class ApplicationController < ActionController::Base
...
#Problem:
#In rails 3.0.1+ it is no longer possible to do this anymore;
# rescue_from ActionController::RoutingError, :with => :render_not_found
#
#The ActionController::RoutingError thrown is not caught by rescue_from.
#The alternative is to to set a catch-all route to catch all unmatched routes and send them to a method which renders an error
#As in http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution
@shilovk
shilovk / routes.rb
Created February 19, 2016 19:03 — forked from kryzhovnik/routes.rb
Интеграция Яндекс.Кассы с Rails
# config/routes.rb
YandexKassaIntegration::Application.routes.draw do
# ...
scope '/yandex_kassa' do
controller 'yandex_kassa', constraints: { subdomain: 'ssl' } do
post :check
post :aviso
get :success
get :fail
@shilovk
shilovk / Hash Keys to Symbols.rb
Created November 7, 2019 12:18 — forked from Integralist/Hash Keys to Symbols.rb
Convert Ruby Hash keys into symbols
hash = { 'foo' => 'bar' }
# Version 1
hash = Hash[hash.map { |k, v| [k.to_sym, v] }]
# Version 2
hash = hash.reduce({}) do |memo, (k, v)|
memo.tap { |m| m[k.to_sym] = v }
end
@shilovk
shilovk / vowels
Created November 20, 2019 17:57 — forked from davidbella/vowels
Ruby: All about finding vowels
def is_vowel_elsif(letter)
if letter == "a"
true
elsif letter == "e"
true
elsif letter == "i"
true
elsif letter == "o"
true
elsif letter == "u"

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

@shilovk
shilovk / capybara cheat sheet
Created April 8, 2020 20:12 — 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')
@shilovk
shilovk / add_lvhme.sh
Created April 23, 2020 12:53 — forked from mdespuits/add_lvhme.sh
Add lvh.me to Mac OS X hosts file
#!/bin/bash
main() {
if [[ $(has_lvh_me) == 1 ]]; then
echo 'lvh.me is already specified in your hosts file'
else
add_lvh_me
echo 'lvh.me was added to your hosts file!'
fi
flush_dns_cache
# frozen_string_literal: true
require 'rails_helper'
RSpec.configure do |config|
config.use_transactional_fixtures = false
# DatabaseCleaner settings
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
#!/usr/bin/env bash
# run this script from your home folder
# sudo bash
curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.12.tgz
tar -zxvf mongodb-linux-x86_64-2.6.12.tgz
cp mongodb-linux-x86_64-2.6.12/bin/* /usr/local/bin
groupadd mongodb
useradd --system --no-create-home -g mongodb mongodb