Skip to content

Instantly share code, notes, and snippets.

View nononoy's full-sized avatar

Slava Gruzdov nononoy

View GitHub Profile
@nononoy
nononoy / delete_mails_imap.rb
Created March 12, 2019 15:12 — forked from mirrec/delete_mails_imap.rb
how to delete email from mailbox with ruby and imap
require "net/imap"
imap = Net::IMAP.new("imap.domain.sk")
imap.login("info@domain.sk", "HESLO")
imap.select("inbox")
# search for emails that you want to delete
bad_messages = imap.search(["FROM", "from@gmail.com"])
puts "#{bad_messages.count} messages will be deleted"
upstream backend {
server 127.0.0.1:3000;
}
server {
listen 80;
access_log /var/log/nginx/yoursite.access.log;
error_log /var/log/nginx/yoursite.error.log;
@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')
@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 / 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 / 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 / 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 / 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
module BeforeRender
extend ActiveSupport::Concern
included do
define_callbacks :render
end
def render(*args, &block)
run_callbacks(:render) do
super
@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