Skip to content

Instantly share code, notes, and snippets.


Filip Bartuzi Bartuz

View GitHub Profile
Bartuz / .Title
Created Jun 2, 2017 — forked from congjf/.Title
Using MongoDB in golang with mgo
View .Title
Using MongoDB in golang with mgo
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
Bartuz / validate_with_matcher.rb
Last active Nov 24, 2020 — forked from otaviomedeiros/validate_with_matcher.rb
RSpec matcher for validates_with
View validate_with_matcher.rb
# RSpec matcher for validates_with.
# Usage:
# describe User do
# it { should validate_with CustomValidator }
# end
RSpec::Matchers.define :validate_with do |expected_validator, options|
match do |subject|
@validator = subject.class.validators.find do |validator|
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
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.

its isn't core to RSpec. One the of the focuses of RSpec is on the documentation aspects of tests. Unfortunately, its often leads to documentation output that is essentially lies. Consider this spec:

User =, :email)

describe User do
  subject {"bob") }
  its(:name) { should == "bob" }
View .vimrc
if has("autocmd")
" remove trailing white spaces
autocmd BufWritePre * :%s/\s\+$//e
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')