Skip to content

Instantly share code, notes, and snippets.

View rsutphin's full-sized avatar

Rhett Sutphin rsutphin

  • Human Practice, Inc.
  • Chicago, Illinois
View GitHub Profile
@rsutphin
rsutphin / git_revision_file.cap
Created February 17, 2014 16:16
Generates a cap2-like REVISION file when using cap3
require 'capistrano/git'
namespace :git do
after :create_release, :write_revision do
on roles :all do
with fetch(:git_environmental_variables) do
within repo_path do
execute :git, :log, '-1', '--format=%H', '>', release_path.join('REVISION')
end
end
end
@rsutphin
rsutphin / roar_rails_json_hal_require_oddity.sh
Last active August 29, 2015 14:05
Reproduce an error on require that happens with roar-rails but not roar alone
#!/bin/sh -xe
echo "=== Build test app ==="
# Happens with Rails 3.2.19 also
RAILS_VERSION=4.1.5
rm -rf some_app
rails _"$RAILS_VERSION"_ new some_app --skip-bundle --skip-spring
@rsutphin
rsutphin / application.js
Created December 5, 2014 21:44
Application serializer for an ember-cli / ember-pouch project to resolve ember-pouch #16
import Ember from 'ember';
/*globals EmberPouch*/
export default EmberPouch.Serializer.extend({
/**
* Copied from JSONSerializer to enable default serialization of the hasMany
* side of manyToOne relationships. It is not clear to me why this is not the
* default — it seems to make it impossible to ever load the many from the one —
* but there is plentiful evidence that it's not going to be changed:
*
@rsutphin
rsutphin / wait-for-models.js
Created December 16, 2014 16:17
Ember async test helper to wait for ember-data models to be committed
// Registers a temporary test waiter that will be released once there are
// no longer any pending records of the given types in the store. "pending" records
// are ones where isEmpty, isLoading, isReloading, or isSaving are true.
import Ember from 'ember';
export default Ember.Test.registerAsyncHelper('waitForModels', function (app, typeNames) {
// The context object is necessary because unregisterWaiter will unregister
// _all_ bare function waiters if any bare function waiter is unregistered.
// This appears to be due to a defect in Ember.compare (or maybe
require 'socket'
require 'webrick/httprequest'
require 'stringio'
# Super-primitive transparent, recording, single-threaded HTTP Proxy
class TransparentHttpProxy
attr_reader :port
def initialize(port, recorder)
@port = port
def visit(h, incr)
puts "Visiting #{h.inspect}"
visited_keys = []
begin
h.each_pair do |k, v|
visited_keys << k
h[incr.call(k)] = v
if h.size > 20 # arbitrary limit
raise "Infinite loop!"
end
# include at least one source and the rails gem
source :gemcutter
gem "rails", "~> 2.3.5", :require => nil
gem "sqlite3-ruby", :require => "sqlite3"
# Devise 1.0.2 is not a valid gem plugin for Rails, so use git until 1.0.3
# gem "devise", :git => "git://github.com/plataformatec/devise.git", :ref => "v1.0"
group :development do
# bundler requires these gems in development
gem "rails", "2.3.5"

Installed gems

$ gem list nokogiri

*** LOCAL GEMS ***

nokogiri (1.4.0, 1.3.3)

Gemfile

@rsutphin
rsutphin / rails23-bundler-template.rb
Created March 19, 2010 20:51
A rails 2.3 template which adds bundler 0.9.12 support to a new rails app
file 'config/preinitializer.rb', <<-PRE
# Use bundled gems
begin
require File.expand_path('../../.bundle/environment', __FILE__)
rescue LoadError
# This setup deliberately requires that the application be locked.
# For an alternative, see http://gist.github.com/302406#file_preinitializer.rb
if File.exist?(File.expand_path('../../Gemfile.lock', __FILE__))
raise "Application is locked but not installed. Run `bundle install` and then try again."
else