Skip to content

Instantly share code, notes, and snippets.

View anlek's full-sized avatar
💬
Writing code...

Andrew Kalek anlek

💬
Writing code...
View GitHub Profile
def nav_link(name, path, options={})
options[:class] = append_class(options[:class], "#{"active" if active_path?(path)}")
options[:role] ||= "menuitem"
link_to name, path, options
end
def active_path?(path)
request.path == path
end
@anlek
anlek / Node.js
Created June 8, 2015 23:03
Stress Testing Simple apps. Node VS Sinatra (On a macbook pro 15" Mid 2012)
ab -k -c 10 -n 100 http://localhost:1337/
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software:
Server Hostname: localhost
@anlek
anlek / application.css.scss
Last active August 29, 2015 14:22
Adding Bootstrap to Rails 3+
//MAKE SURE YOU RENAME THE FILE TO application.css.scss (adding .scss)
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
u = User.find(4)
=> #<User id: 4, .... >
u.save!
ActiveRecord::RecordInvalid: Validation failed: Path has already been taken
from /home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/associations.rb:109:in `create_record'
from /home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/associations.rb:94:in `create!'
from /home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-4.0.3/lib/active_record/associations/builder/singular_association.rb:27:in `create_namespace!'
from /home/git/gitlab/app/observers/user_observer.rb:14:in `after_save'
from /home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/rails-observers-0.1.2/lib/rails/observers/active_model/observing.rb:352:in `update'
@anlek
anlek / my_test_spec.rb
Created March 28, 2014 01:43
How to run tests as if CanCan was loaded into the system.
before(:all) do
module CanCan; end
end
# ... test as if CanCan exists
after(:all) do
Object.send(:remove_const, :CanCan)
end
@anlek
anlek / hash_ext.rb
Last active December 24, 2015 17:18
Mocha expects without casting
#Only include this during your tests, no need in Development or production.
class Hash
def stringify
inject({}){|memo,(k,v)| memo[k.to_s] = v.to_s; memo}
end
end
@anlek
anlek / gist:6346921
Created August 26, 2013 21:34
Can't install carrierwave-mongoid due to a dependency on Mongoid 3.0.1 but the gemspec file says otherwise.
Bundle install/update:
Bundler could not find compatible versions for gem "mongoid":
In Gemfile:
carrierwave-mongoid (~> 0.6.2) ruby depends on
mongoid (~> 3.0.1) ruby
mongoid (4.0.0)
https://rubygems.org/gems/carrierwave-mongoid says:
upstream proxy_parador.com_staging {
server 10.144.144.144;
}
server {
listen 80;
server_name parador.paradorstaging.com;
access_log /var/log/nginx/log/parador.com_staging.access.log;
error_log /var/log/nginx/log/parador.com_staging.error.log;
@anlek
anlek / gist:4090871
Created November 16, 2012 21:00
Issue with Roadie
ArgumentError (invalid byte sequence in US-ASCII):
vendor/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/core_ext/object/blank.rb:105:in `=~'
vendor/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/core_ext/object/blank.rb:105:in `!~'
vendor/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/core_ext/object/blank.rb:105:in `blank?'
vendor/ruby/1.9.1/gems/mail-2.4.4/lib/mail/body.rb:36:in `initialize'
vendor/ruby/1.9.1/gems/mail-2.4.4/lib/mail/message.rb:1909:in `new'
vendor/ruby/1.9.1/gems/mail-2.4.4/lib/mail/message.rb:1909:in `process_body_raw'
vendor/ruby/1.9.1/gems/mail-2.4.4/lib/mail/message.rb:1155:in `body'
vendor/ruby/1.9.1/gems/mail-2.4.4/lib/mail/message.rb:1514:in `parts'
@anlek
anlek / gist:3699797
Created September 11, 2012 16:53
Output of cucumber features (for mongify)
{21:20}[1.9.3-p194]~/code/rails_apps/mongify:master ✓ ➭ cucumber features
Feature: Mongify can be controlled using command-line options
In order to change Mongify's default behaviour
As a user
I want to supply options on the command line
Scenario: returns non-zero status on bad options # features/options.feature:6
When I run mongify --no-such-option # features/step_definitions/mongify_steps.rb:1
Then the exit status indicates an error # features/step_definitions/mongify_steps.rb:26
And it reports the error "Error: invalid option: --no-such-option" # features/step_definitions/mongify_steps.rb:30