Skip to content

Instantly share code, notes, and snippets.

View nononoy's full-sized avatar

Slava Gruzdov nononoy

View GitHub Profile
@nononoy
nononoy / seeds.rb
Created November 11, 2015 08:25 — forked from seyhunak/seeds.rb
Rails - Import SQL file as seed
unless Rails.env.production?
connection = ActiveRecord::Base.connection
connection.tables.each do |table|
connection.execute("TRUNCATE #{table}") unless table == "schema_migrations"
end
sql = File.read('db/import.sql')
statements = sql.split(/;$/)
statements.pop
module BeforeRender
extend ActiveSupport::Concern
included do
define_callbacks :render
end
def render(*args, &block)
run_callbacks(:render) do
super
@nononoy
nononoy / routes.rake
Created March 3, 2016 08:48 — forked from oivoodoo/routes.rake
rake task for printing grape routes.
namespace :grape do
desc 'Print compiled grape routes'
task :routes => :environment do
API.routes.each do |route|
puts route
end
end
end
@nononoy
nononoy / ecdh.rb
Created March 21, 2016 15:36 — forked from sabril/ecdh.rb
#openssl
require 'openssl'
require 'base64'
require "digest"
include OpenSSL
def aes256_encrypt(key, data)
key = Digest::SHA256.digest(key) if(key.kind_of?(String) && 32 != key.bytesize)
aes = OpenSSL::Cipher.new('AES-256-CBC')
aes.encrypt
@nononoy
nononoy / ruby.md
Created March 27, 2016 17:20 — forked from ID25/ruby.md

Предыдущий: https://2ch.hk/pr/res/560026.html

RUBY_SHAPKA VERSION = 1.0.6

FAQ:

1. C чего мне начать, чтобы стать рубистом? Отличным началом будет Programming Ruby (The Pragmatic Programmers Guide), читать Eloquent Ruby и The Well Grounded Rubyist после прочтения первой толку особо не даст, одни и теже вещи, дальше читаем Ruby Way, затем познаем метапрограммирование с Metaprogramming Ruby. А дальше открываем Ruby cookbook 2015 года, Пишем свой код во время чтения.

Следующий уровень, продвинутые книги по руби:

@nononoy
nononoy / rspec_model_testing_template.rb
Created October 18, 2016 12:27 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@nononoy
nononoy / custom_submit_simple_form.md
Created November 18, 2016 13:46 — forked from maxivak/custom_submit_simple_form.md
Rails simple_form custom submit button. simple_form, bootstrap 3

Custom submit button in simple_form and bootstrap 3

Objective

It is easy to add wrappers for input components in simple_form, but it takes some time to modify rendering of buttons ("f.button").

We want to have this in our form:

= f.button :submit_cancel, 'Save'

@nononoy
nononoy / look_and_say.rb
Last active May 1, 2017 16:18
Numeric extension to get Look-and-say sequence number implementation. Ruby > 2.4.0
module SpecificNumeric
refine Numeric do
PRESET_ITERATIONS_COUNT = 5
def look_and_say
_deep_look_and_say(Array.new(1, self))
end
private
@nononoy
nononoy / capybara cheat sheet
Created April 5, 2017 18:16 — 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')
module EnumI18nHelper
def enum_options_for_select(class_name, enum)
class_name.send(enum.to_s.pluralize).map do |key, _|
[enum_i18n(class_name, enum, key), key]
end
end
def enum_t(model, enum)
enum_i18n(model.class, enum, model.send(enum))
end