Skip to content

Instantly share code, notes, and snippets.


Rhett Sutphin rsutphin

  • Human Practice, Inc.
  • Chicago, Illinois
View GitHub Profile
rsutphin / datagram_test.rb
Created November 30, 2015 18:30
Parallel processing in ruby with datagrams for bidirectional message passing
View datagram_test.rb
require 'socket'
require 'pp'
def start_child(n)
child_socket, parent_socket = Socket.pair(:UNIX, :DGRAM, 0)
maxlen = 1000
pid = fork do
rsutphin / Gemfile
Last active November 21, 2015 01:48
Demonstrating unexpected behavior in cancancan
View Gemfile
source ''
gem 'cancancan'
rsutphin / wait-for-models.js
Created December 16, 2014 16:17
Ember async test helper to wait for ember-data models to be committed
View wait-for-models.js
// 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 (or maybe
rsutphin / application.js
Created December 5, 2014 21:44
Application serializer for an ember-cli / ember-pouch project to resolve ember-pouch #16
View application.js
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 /
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
rm -rf some_app
rails _"$RAILS_VERSION"_ new some_app --skip-bundle --skip-spring
rsutphin / exceed_query_limit.rb
Created July 7, 2014 14:40
RSpec 3 matcher for ActiveRecord query count limits. Based on
View exceed_query_limit.rb
# Derived from Updated for RSpec 3.
RSpec::Matchers.define :exceed_query_limit do |expected|
match do |block|
query_count(&block) > expected
failure_message_when_negated do |actual|
"Expected to run maximum #{expected} queries, got #{@counter.query_count}"
rsutphin / git_revision_file.cap
Created February 17, 2014 16:16
Generates a cap2-like REVISION file when using cap3
View git_revision_file.cap
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')
rsutphin / tag_and_push_tag.cap
Last active April 18, 2018 13:08
A capistrano 3 task to tag the repo after every deploy
View tag_and_push_tag.cap
# Requires Capistrano 3.2 or later
namespace :deploy do
after :finishing, :tag_and_push_tag do
on roles(:app) do
within release_path do
set(:current_revision, capture(:cat, 'REVISION'))
# release path may be resolved already or not
resolved_release_path = capture(:pwd, "-P")
rsutphin / repro
Last active December 30, 2015 12:49
Problem with spring and rails engine projects
View repro
#!/bin/bash -ex
gem list spring
gem list rails
rm -rf quux
rails plugin new quux --mountable
cd quux
rsutphin /
Created December 4, 2013 23:07
Use linode's DNS API for dynamic DNS with curl from cron

Use Linode's DNS Manager API for one-line dynamic DNS

This can be useful for cron, for instance.


  • You are using Linode's DNS Manager to manage a zone for your domain
  • You have already created an A record for the name you want to make dynamic
  • You have an API key for Linode's API
  • curl and jsonpp (jsonpp is not necessary but makes the manual steps easier)