Skip to content

Instantly share code, notes, and snippets.

View deathbob's full-sized avatar

Bob Larrick deathbob

View GitHub Profile
@deathbob
deathbob / after_set_user
Created February 2, 2011 02:37
Hack for devise after_set_user on warden::manager
# config/initializers/anything.rb
Warden::Manager.after_set_user do |user, auth, opts|
puts "Hello"
debugger
puts "Hi"
end
# fire up server
require 'test_helper'
class Admin::ArticlesControllerTest < ActionController::TestCase
setup do
@article = articles(:one)
@typus_user = AdminUser.first
@request.session[:typus_user_id] = @typus_user.id
@request.env['HTTP_REFERER'] = '/admin/articles'
end
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
master>rails new yammy
[... nothing to see here ...]
master>cd yammy
master>rails g model Dummy name:string
invoke active_record
create db/migrate/20110114203601_create_dummies.rb
create app/models/dummy.rb
invoke test_unit
create test/unit/dummy_test.rb
create test/fixtures/dummies.yml
Loading development environment (Rails 3.0.3)
no such file to load -- wirble
ruby-1.8.7-p302 > c = Content.first
=> #<Content id: 2, title: "I win", body: nil, tipe: nil, dom_id: nil, position: nil, visible: nil, created_at: "2011-01-14 20:19:37", updated_at: "2011-01-14 20:19:37">
ruby-1.8.7-p302 > tom = c.to_yaml
=> "--- !ruby/object:Content \nattributes: \n position: \n tipe: \n created_at: 2011-01-14 20:19:37.813214\n title: I win\n body: \n dom_id: \n updated_at: 2011-01-14 20:19:37.813214\n id: 2\n visible: \nattributes_cache: {}\n\nchanged_attributes: {}\n\ndestroyed: false\nmarked_for_destruction: false\npersisted: true\npreviously_changed: {}\n\nreadonly: false\n"
ruby-1.8.7-p302 > YAML.load(tom)
NoMethodError: undefined method `keys' for nil:NilClass
from /Users/bob/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /Users/bob/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.3/lib/active_record/base.rb:1512:in `attribute_names
module ApplicationHelper
# In Rails 2 this worked as expected, if the user was admin the block would execute and show up in the view
# In Rails 3 it renders everything on the page up to here twice.
def admin &blk
yield if current_user.admin?
end
end
namespace :deploy do
# To avoid having to add a password for sudo, visudo and add
# deployusername ALL=(ALL) NOPASSWD: /etc/init.d/unicorn reload
task :start do
sudo "/etc/init.d/unicorn start"
end
task :stop do
sudo "/etc/init.d/unicorn stop"
ActionController::Dispatcher.middleware.use 'Route301', {:routes => [
{:when => /images.*\.jpg/, :send_to => '/images/default-image.jpg'},
]}
require File.join(File.dirname(__FILE__),'..','lib','rack','hapong')
require 'rack/cache'
# Test response when in development mode
# if Merb.environment == 'development'
# use Rack::Lint
# end
# handle OPTIONS / requests without invoking any handlers
use Rack::HAPong
require 'rubygems'
require 'socket'
gem 'twitter' # necessary if you have twitter4r installed as well as twitter
require 'twitter'
IP = "192.168.2.27"
PORT = 2000
tweets = []