Skip to content

Instantly share code, notes, and snippets.

View ernie's full-sized avatar

Ernie Miller ernie

View GitHub Profile

Keybase proof

I hereby claim:

  • I am ernie on github.
  • I am ernie (https://keybase.io/ernie) on keybase.
  • I have a public key whose fingerprint is DE33 68E0 9D43 082C 3145 78E8 4E8C 6B3F EC74 DCB2

To claim this, I am signing this object:

@ernie
ernie / repo.rb
Last active August 29, 2015 14:01
class PersonRepository < Norm::PostgreSQLRepository
def named(name)
select_records(select_statement.where(:name => name))
end
def select_statement
Norm::SQL.select.from('people')
end
@ernie
ernie / my_parser.rb
Created December 23, 2014 17:57
Experiments with non-HTML Kramdown Parser
require 'kramdown'
require 'kramdown/parser'
module Kramdown
module Parser
class MyParser < GFM
def initialize(source, options)
super
@span_parsers.delete(:span_html)
From f2bd8bd136b206c6ff48b8c2633e8ab8ca224eb1 Mon Sep 17 00:00:00 2001
From: Ernie Miller <ernie@metautonomo.us>
Date: Tue, 13 Apr 2010 10:45:44 -0400
Subject: [PATCH] New predicates, including Not (Unary), Any/All (Polyadic), and NotMatch/NotIn (Binary)
This patch adds support for some new types of predicates and
cleans up a few small things. Tests are included.
It adds a unary predicate, Not. Predicate#not will negate the predicate
on which it's called.
Autojoin sample results:
a = Article.includes(:comments).where(:comments => {:moderations => {:value => 1},:body => 'hey'}).autojoin
Article Load (0.4ms) SELECT "articles".* FROM "articles" INNER JOIN "comments" ON "comments"."article_id" = "articles"."id" INNER JOIN "moderations" ON "moderations"."comment_id" = "comments"."id" WHERE (("moderations"."value" = 1 AND "comments"."body" = 'hey'))
Comment Load (0.4ms) SELECT "comments".* FROM "comments" WHERE ("comments".article_id = 1)
a = Article.eager_load(:moderations).where(:comments => {:moderations => {:value => 1},:body => 'hey'}).autojoin.first
Article Load (0.3ms) SELECT DISTINCT "articles".id FROM "articles" LEFT OUTER JOIN "comments" ON "articles"."id" = "comments"."article_id" LEFT OUTER JOIN "moderations" ON "moderations"."comment_id" = "comments"."id" INNER JOIN "comments" "comments_articles" ON "comments_articles"."article_id" = "articles"."id" INNER JOIN "moderations" "moderations_comments" ON "moderations_comments"."comment_id"
ruby-1.9.2-head > params = {:search => {:created_at_gteq => 2.weeks.ago}}
=> {:search=>{:created_at_gteq=>Mon, 28 Jun 2010 11:46:34 EDT -04:00}}
ruby-1.9.2-head > @search = Article.search(params[:search])
=> #<MetaSearch::Builder:0x00000100ac2820 @relation=[], @base=Article(id: integer, title: string, body: text, created_at: datetime, updated_at: datetime, lookup_id: integer), @opts={}, @join_dependency=#<ActiveRecord::Associations::ClassMethods::JoinDependency:0x00000100ac25c8 @joins=[#<ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase:0x00000100ac25a0 @active_record=Article(id: integer, title: string, body: text, created_at: datetime, updated_at: datetime, lookup_id: integer), @cached_record={}, @table_joins=nil>], @associations=[], @reflections=[], @base_records_hash={}, @base_records_in_order=[], @table_aliases={"articles"=>1}>, @search_attributes={"created_at_greater_than_or_equal_to"=>Mon, 28 Jun 2010 11:46:34 EDT -04:00}>
ruby-1.9.2-head > @search.created_at_lteq ||= @search.creat
module ActionView
module Helpers
class FormBuilder
Check = Struct.new(:box, :label)
# Behaves almost exactly like the select method, but instead of generating a select tag,
# generates Checks. These consist of two attributes, +box+ and +label+,
# which are (unsurprisingly) the HTML for the check box and the label. Called without a block,
# this method will return an array of check boxes. Called with a block, it will yield each
# check box to your template.
ruby-1.9.2-head > a = Arel::Predicates::Inequality.new(1,1)
=> #<Arel::Predicates::Inequality:0x00000101a0b480 @operand=1, @operand2=1>
ruby-1.9.2-head > a.is_a?(Arel::Predicates::Equality)
=> true
ruby-1.9.2-head > Arel::Predicates::Equality === a
=> true
ruby-1.9.2-head > [a].grep(Arel::Predicates::Equality)
=> [#<Arel::Predicates::Inequality:0x00000101a0b480 @operand=1, @operand2=1>]
From 6cb5f1f85c8af1a37a6a27e6f69c0f41a84bbf2f Mon Sep 17 00:00:00 2001
From: Ernie Miller <ernie@metautonomo.us>
Date: Mon, 4 Oct 2010 13:35:38 -0400
Subject: [PATCH 1/2] Convert to model before calling model_name on a record in ActiveModel::Naming
---
activemodel/lib/active_model/naming.rb | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb
From 124de9bdb3109236af68d06052ce21a4522059e6 Mon Sep 17 00:00:00 2001
From: Ernie Miller <ernie@metautonomo.us>
Date: Wed, 27 Oct 2010 09:43:20 -0400
Subject: [PATCH 1/2] Refactor predication methods to be available to SqlLiterals as well.
---
lib/arel.rb | 1 +
lib/arel/attributes/attribute.rb | 175 +-------------------------------------
lib/arel/nodes/sql_literal.rb | 1 +
lib/arel/predications.rb | 177 ++++++++++++++++++++++++++++++++++++++