Skip to content

Instantly share code, notes, and snippets.

@replaid
replaid / command to run
Created October 7, 2011 15:34
Dig domains in an input file
sh my-fancy-script.sh input.txt > log-file
@replaid
replaid / spec_helper.rb
Last active December 30, 2015 00:38
Instrumenting the spec run to catch test data leakage at the source. Use like this: bundle exec rspec --seed _(seed number here)_ file1 file2 file3 ...
...
def check_for_pollution
tables_with_records = []
all_tables = ActiveRecord::Base.connection.tables
all_tables.each do |table_name|
has_records = (ActiveRecord::Base.connection.select_value("select exists (select 1 from #{table_name} limit 1)") > 0)
tables_with_records << table_name if has_records
end
expected_tables_with_records = ['schema_migrations']
@replaid
replaid / fixture_validation_test.rb
Created August 5, 2014 21:22
Validating your Fixtures in Rails 4
# Adapted for Rails 4 from http://trevorturk.com/2008/09/20/validating-your-fixtures/
# I put this in test/models/. Trevor put his in test/integration/.
require 'test_helper'
class FixtureValidationTest < ActiveSupport::TestCase
test "fixtures should be valid" do
models = ActiveRecord::FixtureSet.all_loaded_fixtures.keys
models.each do |model|
@replaid
replaid / dump.rb
Created September 22, 2014 18:21
Save test data into tab-separated files.
ActiveRecord::Base.connection.tables.each do |table_name|
ActiveRecord::Base.connection.execute("select * from #{table_name} into outfile '/tmp/datadump-#{table_name}.outfile'")
end
@replaid
replaid / ddd-rails-tree.txt
Last active March 23, 2023 02:19
A Rails directory tree that expresses DDD layers and bounded contexts.
components/
my_bounded_context/
app/
presentation/ # This is called the "UI" layer in DDD literature, but it is also
# where things like JSON interfaces live -- any kind of presentation
# or handshake to anything outside. So "presentation" rather than "ui".
assets/
helpers/
mailers/
views/
@replaid
replaid / inject.rb
Last active August 26, 2015 22:26
ROM Relation setup difficulty
require 'domain'
require 'persist/rom'
require 'persist/users_relation'
rom = ROM.env
p rom
Domain::Repository::User.delegate = rom.relation(:users).as(:user)
@replaid
replaid / keybase.md
Created February 5, 2016 18:19
keybase.md

Keybase proof

I hereby claim:

  • I am replaid on github.
  • I am rep (https://keybase.io/rep) on keybase.
  • I have a public key ASCQqLi-yHok4PIouZjkILaJ5jUFRMrj__Ebwe-uaqpKJwo

To claim this, I am signing this object:

@replaid
replaid / restaurant_recommendation.adoc
Created March 31, 2016 20:00 — forked from jexp/restaurant_recommendation.adoc
Restaurant Recommendation GraphGist

Restaurant Recommendations

We want to demonstrate how easy it is to model a domain as a graph and answer questions in almost natural language.

Graph Based Search and Discovery is prominent a use-case for graph databases like Neo4j.

@replaid
replaid / flatten_enum.rb
Created October 22, 2016 21:09
Flatten arbitrarily nested collections.
class FlattenEnum
class << self
# Returns an enumerator that yields the non-enumerable items from within a
# nested enumerable, in depth-first order.
#
# Example:
#
# FlattenEnum.create([[1, 2, [3]], 4]).to_a
# #=> [1, 2, 3, 4]
@replaid
replaid / mixin_ancestors.rb
Last active December 17, 2016 03:42
Included Ruby modules go into the inheritance chain
irb(main):001:0> module Mixin; end
=> nil
irb(main):002:0> class A
irb(main):003:1> include Mixin
irb(main):004:1> end
=> A
irb(main):005:0> a = A.new
=> #<A:0x007fbaea8a89a8>
irb(main):006:0> a.is_a? Mixin
=> true