Skip to content

Instantly share code, notes, and snippets.

Avatar

Rhett Sutphin rsutphin

View GitHub Profile
@rsutphin
rsutphin / datagram_test.rb
Created Nov 30, 2015
Parallel processing in ruby with datagrams for bidirectional message passing
View datagram_test.rb
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 Nov 21, 2015
Demonstrating unexpected behavior in cancancan
View Gemfile
source 'https://rubygems.org'
gem 'cancancan'
@rsutphin
rsutphin / wait-for-models.js
Created Dec 16, 2014
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 Ember.compare (or maybe
@rsutphin
rsutphin / application.js
Created Dec 5, 2014
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
rsutphin / roar_rails_json_hal_require_oddity.sh
Last active Aug 29, 2015
Reproduce an error on require that happens with roar-rails but not roar alone
View roar_rails_json_hal_require_oddity.sh
#!/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 Jul 7, 2014
RSpec 3 matcher for ActiveRecord query count limits. Based on http://stackoverflow.com/a/13423584/153896.
View exceed_query_limit.rb
# 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 Feb 17, 2014
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')
end
end
end
@rsutphin
rsutphin / tag_and_push_tag.cap
Last active Apr 18, 2018
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
rsutphin / repro
Last active Dec 30, 2015
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
rsutphin / linode_dyndns.md
Created Dec 4, 2013
Use linode's DNS API for dynamic DNS with curl from cron
View linode_dyndns.md

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)
You can’t perform that action at this time.