Skip to content

Instantly share code, notes, and snippets.

View markoa's full-sized avatar

Marko Anastasov markoa

View GitHub Profile
@markoa
markoa / application_controller.rb
Created March 5, 2012 09:16
Log every exception when in Cucumber
class ApplicationController < ActionController::Base
rescue_from Exception do |exception|
logger.error exception.backtrace.join("\n")
head 500
end
end
@markoa
markoa / user.rb
Created February 22, 2012 12:19 — forked from darkofabijan/user.rb
class User < ActiveRecord::Base
def find_form(id)
company.forms.find(id)
end
end
@markoa
markoa / gist:1596632
Created January 11, 2012 20:37
what to paste in application controller when cucumber doesn't tell you what failed in the view
class ApplicationController < ActionController::Base
rescue_from 'Exception' do |exception|
logger.info exception
logger.info exception.backtrace.join("\n")
render :head => 500
end
end
@markoa
markoa / rake-spec-aborted.txt
Created November 24, 2011 20:31
random rake spec disaster
rake aborted!
ruby /home/marko/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -S rspec ./spec/helpers/sessions_helper_spec.rb ./spec/helpers/users_helper_spec.rb
<<other spec files>> failed
/home/marko/devel/foo/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/rake_task.rb:149:in `block (2 levels) in initialize'
/home/marko/devel/foo/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1112:in `verbose'
/home/marko/devel/foo/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/rake_task.rb:139:in `block in initialize'
/home/marko/devel/foo/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/home/marko/devel/foo/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'
/home/marko/devel/foo/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/home/marko/devel/foo/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
module ApplicationHelper
# In your layout: <body <%= render_page_data %>>
#
def render_page_data
@page_data_attributes.html_safe if @page_data_attributes.present?
end
# Appends a hash of data attributes to the body element. For example:
#
@markoa
markoa / ruby19-hash.rb
Created September 16, 2011 09:55
ruby 1.9 hash syntax
def do_it(options = {})
puts options.inspect
end
# new syntax:
do_it(user_type: :vip)
# => {:user_type=>:vip}
# old syntax
do_it(:user_type => :vip)
@markoa
markoa / omniauth_callbacks_controller.rb
Created August 17, 2011 14:45
Saving LinkedIn OAuth data in a callback action (Rails controller, Devise, Omniauth).
# in your routes.rb:
# devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
#
# and view:
# link_to("Connect to LinkedIn", user_omniauth_authorize_path(:linked_in))
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def linkedin
omniauth_hash = env["omniauth.auth"]
@markoa
markoa / linkedin_factory.rb
Created August 17, 2011 14:50
Sample wrapper around linkedin gem to support varying user credentials.
# See https://gist.github.com/1151655 for a tip how to save access token and secret in an omniauth callback.
class LinkedinFactory
API_KEY = "123"
SECRET_KEY = "456"
def self.authorize_user(user)
token = user.linkedin_connection.token
secret = user.linkedin_connection.secret
@markoa
markoa / iptables.up.rules
Created May 13, 2011 10:28
Slicehost recommended iptables setup
*filter
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
@markoa
markoa / capistrano-with-bundler-deploy.rb
Created March 15, 2011 11:18
The snippet for config/deploy.rb to use Bundler.
# use this in a after "deploy:update_code" block
namespace :bundler do
task :create_symlink, :roles => :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
task :bundle_new_release, :roles => :app do