Skip to content

Instantly share code, notes, and snippets.

@emmanuel
emmanuel / pg-smart-tags-schema.json
Last active April 22, 2021 16:08 — forked from singingwolfboy/pg-smart-tags-schema.json
JSON Schema for Postgraphile v4 smart tags JSON files
{
"title": "JSONPgSmartTags",
"type": "object",
"properties": {
"version": {
"type": "number",
"minimum": 1
},
"config": {
"type": "object",
@emmanuel
emmanuel / .gitignore
Created October 18, 2011 23:50 — forked from FND/.gitignore
test case for eager loading of nested associations with DataMapper
Gemfile.lock
@emmanuel
emmanuel / validation_set.rb
Created August 15, 2011 23:32 — forked from mbj/validation_set.rb
dm-validations proposal for a better command query seperation

Traditional

resource = Resource.new attributes
resource.valid?                  # => true | false
resource.save                    # => true | false Will raise adapter errors in case of Inconsistency
resource.errors                  # => ErrorSet (cached) will not reflect adapter errors
resource.attribute=invalid_value
resource.errors                  # Same error Set as above, will not reflect attribute change
@emmanuel
emmanuel / gist:1132758
Created August 8, 2011 21:13 — forked from dkubb/gist:1130086
case with predicates
require 'rubygems'
require 'backports' # aliases Proc#=== to Proc#call
rs = (0..10000).to_a.sample(30)
rs.each do |r|
case
when r.zero? then puts "#{r} is zero"
when (r % 5).zero? then puts "#{r} is fiven"
when (r % 4).zero? then puts "#{r} is fourven"
@emmanuel
emmanuel / dm_query_graph.rb
Created July 31, 2011 06:17 — forked from dkubb/dm_query_graph.rb
Code spike to see if joins can be modelled using a DAG
require 'set'
require 'tsort'
module DataMapper
class Query
class Graph
include TSort
def initialize
@graph = Hash.new { |graph, target| graph[target] = Set.new }
@emmanuel
emmanuel / test.rb
Created July 31, 2011 06:16 — forked from dkubb/test.rb
UoW code spike
# NOTE: this is a code spike, and the following code will probably
# not make it into dm-core in it's current form. I wanted to see if it
# were possible to use a topographical sort to ensure parents were
# saved before children, before/after filters were fired in the correct
# order, and foreign keys set before children are saved, but after parents
# are saved.
# The hooks should fire in the following order:
# https://gist.github.com/6666d2818b14296a28ab
require "rubygems"
require "datamapper"
DataMapper.setup(:default, "sqlite::memory:")
DataMapper::Logger.new(STDOUT, :debug)
class Recipe
include DataMapper::Resource
property :id, Serial
@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
// 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;
});