Skip to content

Instantly share code, notes, and snippets.

View Bartuz's full-sized avatar
⛑️

Filip Bartuzi Bartuz

⛑️
View GitHub Profile
@Bartuz
Bartuz / .Title
Created June 2, 2017 07:16 — forked from congjf/.Title
Using MongoDB in golang with mgo
Using MongoDB in golang with mgo
@Bartuz
Bartuz / bench.rb
Created January 25, 2016 10:43 — 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 rails-refactoring.com . Development mode executed in rails console.
require 'benchmark'
ActiveRecord::Base.logger = nil
Benchmark.bmbm do |bench|
bench.report("SQL query") do
1000.times { Whatever.count }
end
bench.report("exception hit") do
@Bartuz
Bartuz / rails_confirm.js.coffee
Created December 9, 2015 09:28 — forked from da4nik/rails_confirm.js.coffee
Change standart rails confirm dialog to custom
Call:
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
Bartuz / validate_with_matcher.rb
Last active August 17, 2023 14:15 — forked from otaviomedeiros/validate_with_matcher.rb
RSpec matcher for validates_with
# RSpec matcher for validates_with.
# https://gist.github.com/2032846
# 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
Bartuz / Plea.markdown
Created November 11, 2015 09:52 — forked from justinko/Plea.markdown
Am I doing it wrong?

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
Bartuz / alias_matchers.md
Created November 9, 2015 11:29 — forked from JunichiIto/alias_matchers.md
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
Bartuz / global-hook
Last active August 29, 2015 14:06 — forked from proapi/gitconfig
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 = Struct.new(:name, :email)

describe User do
  subject { User.new("bob") }
  its(:name) { should == "bob" }
end
@Bartuz
Bartuz / .vimrc
Last active August 29, 2015 14:06 — forked from jandudulski/.vimrc
if has("autocmd")
" remove trailing white spaces
autocmd BufWritePre * :%s/\s\+$//e
endif
=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')