Skip to content

Instantly share code, notes, and snippets.

View shilovk's full-sized avatar

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

View GitHub Profile
@shilovk
shilovk / boot.rb
Last active August 29, 2015 14:24
Change default_options for Rails::Server
# Override default options for server command
# This example changes default development host to 0.0.0.0
require 'rails/commands/server'
module Rails
class Server
new_defaults = Module.new do
def default_options
default_host = Rails.env == 'development' ? '0.0.0.0' : '127.0.0.1'
@import "bootstrap-sprockets";
@import "bootstrap";
@font-face {
font-family: 'Glyphicons Halflings';
src: url(asset_path('glyphicons-halflings-regular.eot'));
src: url(asset_path('glyphicons-halflings-regular.eot?#iefix')) format('embedded-opentype'), url(asset_path('glyphicons-halflings-regular.woff')) format('woff'), url(asset_path('glyphicons-halflings-regular.ttf')) format('truetype'), url(asset_path('glyphicons-halflings-regular.svg#glyphicons_halflingsregular')) format('svg');
}
@shilovk
shilovk / clear_ram.sh
Created August 23, 2015 09:13
sh and nginx
#!/bin/sh
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
#https://github.com/logrusorgru/any/blob/master/redis_onlines_db_size/test.rb
require 'redis'
require 'benchmark'
# perfomance
require 'hiredis'
# `driver: :hiredis` for perfomance, `path: ""` too
$r = Redis.new driver: :hiredis, path: "/tmp/redis.sock"
# coding: utf-8
#https://github.com/logrusorgru/any/blob/master/redis_piplened_vs_ex/test.rb
require 'redis'
require 'benchmark'
# db: 0, driver: по-умолчанию, соединение: локальная петля, но(!)
# нам нужа производительность - чтобы не ждать результатов теста долго, поэтому
# кстати вот это: `driver: :hiredis, path: "/tmp/redis.sock"`
# увеличивает производительность чуть меньше чем в два раза
@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 / _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 / 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"