Skip to content

Instantly share code, notes, and snippets.

@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
@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
@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
$ jobs
[1] - suspended mvim -v
[2] + suspended mvim -v derp.sql
$ fg 1
fg: job not found: 1
@thorncp
thorncp / bios_controller.rb
Created August 17, 2012 02:15
Outrageous Ruby metaprogramming ಠ_ಠ. Also, quite fun
require "dependency_loader"
class BiosController < ApplicationController
extend DependencyLoader(:person)
def new
@bio = @person.bios.build
end
# ...
INITIAL SCOPE OF WORK FOR RESOURCE DATA, INC January 27 2011
RDI SCOPE OF WORK – WORKING TOGETHER & PHASE 1 OF MARKETING ARCHIVE
WORKING TOGETHER - 8 hours
1. Cover the following topics and decide upon standards
a. Git
- workflow
b. Testing frameworks
c. Rails template
- a skeleton app template, to be reused on the other apps?
@thorncp
thorncp / derp_controller.rb
Created June 1, 2011 21:41
See about getting this (or similar) into rubot
class DerpController < VariableController
controller_variable :derp_con
command :con, :protected => true do
if message.text.empty?
reply derp_con
else
self.derp_con = message.text
end
end
$ gem update --system
Updating rubygems-update
Successfully installed rubygems-update-1.7.0
Installing RubyGems 1.7.0
<internal:lib/rubygems/custom_require>:32:in `rescue in require': undefined method `try_activate' for Gem:Module (NoMethodError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from d:/Ruby192/lib/ruby/gems/1.9.1/gems/rubygems-update-1.7.0/lib/rubygems.rb:31:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from setup.rb:24:in `<main>'
class Derp < Rubot::WebResource
get :chuck, 'http://4q.cc/index.php?pid=fact&person=chuck' do |doc|
if fact = doc.css("#factbox").first
fact.text.strip
else
"fail"
end
end
end