Skip to content

Instantly share code, notes, and snippets.


Filip Bartuzi Bartuz

View GitHub Profile
Bartuz / bench.rb
Created Jan 25, 2016 — forked from paneq/bench.rb
cost of using exceptions for control flow compared to one SQL statement (ruby 2.1.4, rails 4.1.7, sqlite) for . Development mode executed in rails console.
View bench.rb
require 'benchmark'
ActiveRecord::Base.logger = nil
Benchmark.bmbm do |bench|"SQL query") do
1000.times { Whatever.count }
end"exception hit") do
Bartuz /
Created Dec 9, 2015 — forked from da4nik/
Change standart rails confirm dialog to custom
Set custom options:
= link_to talk, method: :delete, class: 'icon-close', data: {confirm: "Вы действительно хотите удалить всю переписку с данным пользователем?", confirm_options: {title: 'Удалить все сообщения', yes: 'Да', no: 'Нифига'}}, remote: true
or standart rails way
= link_to talk, method: :delete, class: 'icon-close', data: {confirm: "Вы действительно хотите удалить всю переписку с данным пользователем?"}, remote: true
View z2.rb
class BinaryTree
attr_accessor :root
def initialize
@root =
def insert(letter, path)
node = root
path.each_char do |direction|
View checkout_controller.rb
def checkout
cart =, params)
redirect_to cart_path, notice: t('.success')
redirect_to cart_path, notice: t('.failure', reason: cart.error_message)
Bartuz / Plea.markdown
Created Nov 11, 2015 — forked from justinko/Plea.markdown
Am I doing it wrong?
View Plea.markdown

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this:

Bartuz /
Created Nov 9, 2015 — forked from JunichiIto/
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
Bartuz / application_controller_spec.rb
Created Oct 23, 2015
before/after filters/actions rspec testing. Credits to:
View application_controller_spec.rb
# spec/controllers/application_controller_spec.rb
require 'spec_helper'
describe ApplicationController do
describe 'class' do
it { has_before_filters(:authenticate_user) }
View capybara cheat sheet
=Clicking links and buttons=
click_link('Link Text')
click('Link Text') # Click either a link or a button
click('Button Value')
View global-hook
1. Enable git templates:
git config --global init.templatedir '~/.git-templates'
This tells git to copy everything in ~/.git-templates to your per-project .git/ directory when you run git init
2. Create a directory to hold the global hooks:
mkdir -p ~/.git-templates/hooks
3. Write your hooks in ~/.git-templates/hooks
4. Make sure the hook is executable.
Bartuz / file.rb
Created Sep 19, 2014
Ruby: Compare 2 hashes
View file.rb
class Hash
def diff(other)
(self.keys + other.keys).uniq.inject({}) do |memo, key|
unless self[key] == other[key]
if self[key].kind_of?(Hash) && other[key].kind_of?(Hash)
memo[key] = self[key].diff(other[key])
memo[key] = [self[key], other[key]]