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 / datagram_test.rb
Created November 30, 2015 18:30
Parallel processing in ruby with datagrams for bidirectional message passing
require 'socket'
require 'pp'
END_COMMUNICATION = "\0"
def start_child(n)
child_socket, parent_socket = Socket.pair(:UNIX, :DGRAM, 0)
maxlen = 1000
pid = fork do
@rsutphin
rsutphin / Gemfile
Last active November 21, 2015 01:48
Demonstrating unexpected behavior in cancancan
source 'https://rubygems.org'
gem 'cancancan'
@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
@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 / 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 / exceed_query_limit.rb
Created July 7, 2014 14:40
RSpec 3 matcher for ActiveRecord query count limits. Based on http://stackoverflow.com/a/13423584/153896.
# Derived from http://stackoverflow.com/a/13423584/153896. Updated for RSpec 3.
RSpec::Matchers.define :exceed_query_limit do |expected|
supports_block_expectations
match do |block|
query_count(&block) > expected
end
failure_message_when_negated do |actual|
"Expected to run maximum #{expected} queries, got #{@counter.query_count}"
@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 / tag_and_push_tag.cap
Last active April 18, 2018 13:08
A capistrano 3 task to tag the repo after every deploy
# 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
rsutphin / repro
Last active December 30, 2015 12:49
Problem with spring and rails engine projects
#!/bin/bash -ex
gem list spring
gem list rails
rm -rf quux
rails plugin new quux --mountable
cd quux
@rsutphin
rsutphin / linode_dyndns.md
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.

Prereqs

  • 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)