Skip to content

Instantly share code, notes, and snippets.

View reggieb's full-sized avatar

Rob Nichols reggieb

View GitHub Profile
#!/bin/bash
# usage: $0 source_dir [source_dir] ...
# where source_dir args are directories containing git repositories
red="\033[00;31m"
green="\033[00;32m"
yellow="\033[00;33m"
blue="\033[00;34m"
purple="\033[00;35m"
@reggieb
reggieb / version_struct.rb
Last active August 29, 2015 14:08
Paper Trail: restoring associated objects with main object.
class VersionStruct
class << self
def build_from(version, args = {})
object = deserialize(version.object)
args[:changes] = deserialize(version.object_changes)
args[:version] = version
version_struct = new(object, args)
version_struct.mimic
end
@reggieb
reggieb / number_test.rb
Created November 21, 2014 10:16
Reusing minitest tests via their method names
class NumberTest < ActiveSupport::TestCase
def setup
@number = 4
end
def test_number_is_four
assert_equal 4, @number
end
@reggieb
reggieb / work_request.rb
Last active August 29, 2015 14:13
Rollback persisted finite machine: An example
class WorkRequest < ActiveRecord::Base
# Attributes include :state_history (text) and :state (string)
serialize :state_history, Array
after_find :restore_process
after_initialize :restore_process
def rollback_state_to_previous
@reggieb
reggieb / class_finder.rb
Last active August 29, 2015 14:27
Used in combination with FedoraMigrate to idenitfy target Model Class if not obvious from Object Content Model. https://github.com/projecthydra-labs/fedora-migrate
class ClassFinder
attr_reader :pid
def initialize(pid)
@pid = pid
end
def object
@object ||= self.class.source_objects.select{|x| x.pid =~ /#{pid}/}.first
end
@reggieb
reggieb / apache.god
Created October 9, 2015 14:03
God script to keep apache alive
APACHE_ROOT = 'path/to/apache'
def apache(location)
File.join APACHE_ROOT, location
end
def apachectl(command)
"#{apache 'bin/apachectl'} -k #{command}"
end
@reggieb
reggieb / split_collection_into_columns.html.erb
Last active December 9, 2015 21:08
Split a collection of items so that they can be displayed within two column divs
<% number_of_columns = 2 %>
<div class="columns">
<% @things.each_slice((@things.length / number_of_columns.to_f).ceil) do |column_of_things| %>
<div class ="column">
<% column_of_things.each do |thing| %>
<%= thing.title %>
<% end %>
</div>
<% end %>
</div>
@reggieb
reggieb / display_readme.rb
Created February 8, 2013 16:06
I'm getting tired of not being quite sure how my README.rdoc will appear when loaded onto github. By adding this to the root of my app, I can 'ruby display_readme.rb' to see the rendered README.rdoc at localhost:4567
require 'sinatra'
require 'rdoc/markup/to_html'
get '/' do
input_string = ""
parser = RDoc::Markup::ToHtml.new
File.open("README.rdoc", "r") do |file|
file.each_line{|l| input_string << l}
end
@reggieb
reggieb / overwrite_class.rb
Last active December 15, 2015 17:49
An example of how a class can be replaced with a modified version within a name space.
class Thing
def colour
'blue'
end
def who
self.class.to_s
end
def output(line)
@reggieb
reggieb / self_assessment.conf
Created June 7, 2013 08:59
A passenger apache directive, used on my development PC so that I can mimic the production environment and debug errors caused by the app being hosed in a sub-uri. For example, issues with redirects going to http root rather than app root.
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/rob/public_html
<Directory /home/rob/public_html>
Allow from all
</Directory>
RackBaseURI /self_assessment
<Directory /home/rob/web/select_assessment>