Skip to content

Instantly share code, notes, and snippets.

@thorncp
thorncp / README.md
Last active March 23, 2020 23:28
ActiveRecord without Rails (the models live in a Rails app)

ActiveRecord without Rails

I wanted to load models from a Rails app in a background worker. First attempt was to require_relative "../config/environment", which brings in the whole app. This works fine, but is quite slow.

I get easily annoyed and frustrated with slow software, so I wanted to find a way to load the models I needed, without pulling in the whole app. The approach here is where I landed.

# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do

Keybase proof

I hereby claim:

  • I am thorncp on github.
  • I am thorncp (https://keybase.io/thorncp) on keybase.
  • I have a public key whose fingerprint is D988 C232 5340 A36D 977D FE62 9A27 85BE 8F75 D72B

To claim this, I am signing this object:

diff --git a/app/controllers/competitions_controller.rb b/app/controllers/competitions_controller.rb
index 90109a3..75b5f0d 100644
--- a/app/controllers/competitions_controller.rb
+++ b/app/controllers/competitions_controller.rb
@@ -25,7 +25,10 @@ class CompetitionsController < ApplicationController
team_participations = calculator.team_participations
member_participations = calculator.member_participations
- @brackets = Hash[@competition.brackets.by_lower_limit.map { |bracket|
+ brackets_to_score = @competition.brackets.by_lower_limit.to_a
@thorncp
thorncp / Rakefile
Last active December 24, 2015 17:09
Rake dependency on task in global namespace
task :test do
puts "run tests"
end
namespace :build do
task :dev do
puts "build dev"
end
task :test do
@thorncp
thorncp / gist:5962258
Created July 9, 2013 23:35
git-merge: fast forward vs no fast forward
after fast forward merge
git merge feature-branch
. feature commit - master/feature-branch/HEAD
. feature commit
. feature commit
. master commit
. master commit
$ jobs
[1] - suspended mvim -v
[2] + suspended mvim -v derp.sql
$ fg 1
fg: job not found: 1