Skip to content

Instantly share code, notes, and snippets.

View jaylevitt's full-sized avatar

Jay Levitt jaylevitt

View GitHub Profile
ragtime% script/cucumber --verbose features
Ruby files required:
* features/support/env.rb
* features/support/paths.rb
* features/step_definitions/webrat_steps.rb
* features/step_definitions/site_steps.rb
Features:
* features/hello_world.feature
require 'hpricot'
require 'hpricot_patches'
module HPBehaviorRenderTestHelper
def hp_setup(input, url = nil)
setup_behavior(url)
@output = HPBehaviorRenderTestHelper::DocumentOutput.new(@behavior.render_text(input))
end
# returns the inner content of
bc.. class MyBehaviorTest < Test::Unit::TestCase
test_helper :hp_behavior_render
hp_setup('<r:mytag label="test123"/>')
assert_equal tag('title'), "test123"
end
@jaylevitt
jaylevitt / gist:1167806
Created August 24, 2011 11:09
Icky way to do request-response async handling in RAILS
class SurveyController
# GET
def show
ss = SurveyState.new(params[:survey])
ss.next_question_group do |question|
render :partial => 'question', :object => question
end
session[:survey_state] = ss.id
@jaylevitt
jaylevitt / gist:1204842
Created September 8, 2011 21:41
Valium 0.3.0 empty? backtrace
activerecord (3.0.9) lib/active_record/associations/association_proxy.rb:216:in `method_missing'
valium (0.3.0) lib/valium.rb:96:in `value_of'
activerecord (3.0.9) lib/active_record/autosave_association.rb:337:in `save_has_one_association'
activerecord (3.0.9) lib/active_record/autosave_association.rb:169:in `block in add_autosave_association_callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:431:in `_run_save_callbacks'
activerecord (3.0.9) lib/active_record/callbacks.rb:273:in `create_or_update'
activerecord (3.0.9) lib/active_record/persistence.rb:40:in `save'
activerecord (3.0.9) lib/active_record/validations.rb:43:in `save'
activerecord (3.0.9) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (3.0.9) lib/active_record/transactions.rb:240:in `block (2 levels) in save'
@jaylevitt
jaylevitt / gdb output
Created October 3, 2011 15:59
rb_thread_frame make fails - first attempt
ruby-1.9.2-head-nframe (ruby_1_9_2…)% gdb miniruby
GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ... done
(gdb) run ./tool/mkconfig.rb
@jaylevitt
jaylevitt / mkmf.log
Created October 4, 2011 02:32
crash report
Process: postgres [97937]
Path: /usr/local/Cellar/postgresql/9.0.4/bin/postgres
Identifier: postgres
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: postgres [97545]
Date/Time: 2011-10-03 22:30:49.183 -0400
OS Version: Mac OS X 10.6.8 (10K549)
Report Version: 6
@jaylevitt
jaylevitt / mkmf.log under 1.9.2
Created October 4, 2011 02:39
can't create plruby language
% psql rails_dev
psql (9.0.4)
Type "help" for help.
rails_dev=#
rails_dev=# create function plruby_call_handler() returns language_handler
rails_dev-# as '/Users/jay/.rvm/gems/ruby-1.9.2-p290/bundler/gems/postgresql-plruby-5902376a8af1/src/plruby.bundle'
rails_dev-# language 'C';
ERROR: could not load library "/Users/jay/.rvm/gems/ruby-1.9.2-p290/bundler/gems/postgresql-plruby-5902376a8af1/src/plruby.bundle": dlopen(/Users/jay/.rvm/gems/ruby-1.9.2-p290/bundler/gems/postgresql-plruby-5902376a8af1/src/plruby.bundle, 10): Symbol not found: _Init_stack
Referenced from: /Users/jay/.rvm/gems/ruby-1.9.2-p290/bundler/gems/postgresql-plruby-5902376a8af1/src/plruby.bundle
@jaylevitt
jaylevitt / snippet.sql
Created October 5, 2011 12:42
ERROR: structure of query does not match function result type
create or replace function similarity(my_user_id int)
returns table(user_id int, similarity float) as $$
begin
return query select similarity(my_user_id, 'default=>1'::hstore);
end;
$$ language plpgsql stable strict;
create or replace function similarity(my_user_id int, weightings hstore)
returns table(user_id int, similarity float) as $$
begin
join demographics on users.id = demographics.user_id
where users.id = $1),