Skip to content

Instantly share code, notes, and snippets.

View RichOrElse's full-sized avatar

Ritchie Paul Buitre RichOrElse

View GitHub Profile
@sundbp
sundbp / injectionless_dci.rb
Created June 29, 2012 10:02
DCI in ruby without injection (using DSL) - MoneyTransfer example
# Buidling blocks to support injectionless DCI
require 'rubygems'
require 'active_support/core_ext/string/inflections'
#require 'pry'
module ContextAccessor
def context
Thread.current[:context]
end
end
@towry
towry / context.rb
Last active July 21, 2017 07:33
describe the DCI(Data, context, interaction) architecture in Ruby.
require_relative "customer"
require_relative "user"
# context bind role to object.
# by using the extend method in ruby.
# now the data object has some behaviors that get from the role class(Customer).
class Context
def initialize(user, book)
@customer, @book = user, book
@customer.extend(Customer)
@marksim
marksim / README.md
Created July 10, 2012 16:18
How to isolate mail dependency without integrating into data model?

I'm not sure how to remove the dependency on VerificationMailer without pushing it into the profile model and making the model suddenly care about how to mail verifications.

I WANT to remove it so I don't have any need to load up rails when running the tests, but also want to keep my models sensible and without a lot of knowledge of business logic.

Example usage:

profile = Profile.find(1)
profile.extend Verifier

profile.verify(email: 'myemail@example.com')

# In a context somewhere, we'd like to do this:
u = User.new
u.extend Passworded
# Unfortunately, this doesn't work:
module Passworded
include ActiveModel::Model # Can't do this because ActiveModel::Model wants to be included
# on classes, not modules.
@rapimo
rapimo / gist:3250341
Created August 3, 2012 18:44
count occurrences of array values in postgres using hstore
SELECT hstore(array_agg(v), array_agg(c::text)) FROM (
SELECT v, COUNT(*) as c ,1 as agg from unnest(ARRAY['foo','bar','baz','foo']) v GROUP BY v) t
GROUP BY agg
--> "bar"=>"1", "baz"=>"1", "foo"=>"2"
@ludyna
ludyna / dci_example.rb
Last active March 20, 2018 20:08
DCI (Data, Contexts, Interactions) paradigm example in Ruby
# DCI EXAMPLE IN RUBY (with some prototype elements)
# Blog post: https://www.ludyna.com/oleh/dci-example-in-ruby
#
# More info:
#
# Creator of MVC & DCI, Trygve Reenskaug: DCI: Re-thinking the foundations of
# object orientation and of programming
# http://vimeo.com/8235394
#
# James Coplien: Why DCI is the Right Architecture for Right Now
@jasoncodes
jasoncodes / create_item_children_count.rb
Created October 23, 2011 19:04
Create ActiveRecord models for database views
class CreateItemChildrenCountView < ActiveRecord::Migration
def self.up
execute <<-SQL
CREATE VIEW item_children_count AS
SELECT parent_id AS item_id, COUNT(*) as children_count
FROM items GROUP BY parent_id;
SQL
end
def self.down
@jodosha
jodosha / README.md
Created September 7, 2017 14:34
Mount Hanami inside Rails

1. Setup

rails new blog
cd blog
hanami new bookshelf
vim Gemfile # add `hanami`
bundle
vim bookshelf/config/environment.rb # See Note 1
@jcypret
jcypret / Gemfile
Last active October 7, 2021 13:59
Phone normalization in Rails
gem "phonelib"
@olivierlacan
olivierlacan / migrate_postgresql_database.md
Last active March 24, 2022 20:30
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X. See upgraded version of this guide: http://olivierlacan.com/posts/migrating-homebrew-postgres-to-a-new-version/

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important: