Skip to content

Instantly share code, notes, and snippets.

// Shared Experience textarea blocker
$('#experience textarea#experience_body').bind('keypress', function(){
$('a').attr('rel', 'blocked');
});
// Be alert! The world needs more Lerts.
$('a[rel="blocked"]').click(function(){
alert('Sorry, This is just a demo!');
return false;
});
@emmanuel
emmanuel / param.js
Created October 13, 2009 06:17 — forked from quirkey/param.js
Rails-style nested attribute serialization in jQuery
$.extend({
param: function( a, nest_in ) {
var s = [ ];
// check for nest
if (typeof nest_in == 'undefined') nest_in = false;
function nested(key) {
if (nest_in)
return nest_in + '[' + key + ']';
else
class Parent
include DataMapper::Resource
def self.default_repository_name
:parent_repo
end
property :id, Serial
has n, :children, :model => "StiBase"
@emmanuel
emmanuel / snippet.rb
Created May 27, 2011 00:59
Resources created via OneToMany::Collection#new work, but not if conditions are applied
require 'rubygems'
# puts ENV["GEM_HOME"]
require 'ruby-debug'
require 'datamapper'
DataMapper::Logger.new(STDOUT)
DataMapper.setup(:default, "sqlite::memory:")
class Page
include DataMapper::Resource
@emmanuel
emmanuel / file.sql
Created June 2, 2011 07:54
Closure Table operations SQL fragments
-- Retrieve descendants
-- ====================
-- retrieve descendants of #4
SELECT c.*
FROM Comments AS c
JOIN TreePaths AS t ON c.comment_id = t.descendant
WHERE t.ancestor = 4;
-- Retrieve ancestors
@emmanuel
emmanuel / test.rb
Created June 2, 2011 22:26
DataMapper: an opportunity for optimization: don't need to retrieve existing join resources when replacing them
require "rubygems"
require "datamapper"
DataMapper::Logger.new($stdout, :default)
DataMapper.setup(:default, "sqlite::memory:")
class Source
include DataMapper::Resource
property :id, Serial
@emmanuel
emmanuel / file.rb
Created June 9, 2011 17:56
DataMapper: order results by a property on a ManyToMany relationship
DataMapper::Logger.new($stdout, :default)
DataMapper.setup(:default, "sqlite::memory:")
class Author
include DataMapper::Resource
property :id, Serial
property :email, String
has n, :posts
@emmanuel
emmanuel / snippet.rb
Created July 1, 2011 06:30
Proposal for decoupling dm-validations from Resource internals
# TODO: shouldn't Validations use `before :save` to intercept the save call?
# (for DataMapper::Resource instances, not validated plain Ruby objects)
#
# Admittedly, it may not be possible to support as 'clean' of an interface
# from the caller's perspective (ie., being able to specify the validation
# context with an arg to the #save/#update methods vs in some other manner).
#
# However, changing the method signature of #save and #update is problematic.
# Also, I'm not sure how often an explicit validation context is used,
# and on that basis I question whether the interface should be designed for
begin
begin
raise "test"
rescue Exception => e
puts "Rescuing #{e.inspect}"
end
ensure
puts "Ensuring #{e.inspect}"
raise e if e
end
require "rubygems"
require "datamapper"
DataMapper.setup(:default, "sqlite::memory:")
DataMapper::Logger.new(STDOUT, :debug)
class Recipe
include DataMapper::Resource
property :id, Serial