Skip to content

Instantly share code, notes, and snippets.

@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 / 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)
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 / deploy.rb
Created October 10, 2011 13:31
Ingredients to monitor Resque with God automatically via Capistrano (on Ubuntu)
namespace :deploy do
desc "Hot-reload God configuration for the Resque worker"
task :reload_god_config do
sudo "god stop resque"
sudo "god load #{File.join(deploy_to, 'current', 'config', 'resque-' + rails_env + '.god')}"
sudo "god start resque"
end
end
# append to the bottom:
@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'
@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 / bash_contour.sh
Last active September 27, 2016 12:58
Stuff I usually need in ~/.bash_profile
set -o vi
eval `ssh-agent`
ssh-add ~/.ssh/id_rsa
export PS1="\w ★ "
export LANGUAGE="en"
export LANG="C"
export LC_MESSAGES="C"
@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 / 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 / irb.rb
Created February 21, 2013 11:55
How to shut up irb
# either irb --noecho, or
conf.echo = false