Skip to content

Instantly share code, notes, and snippets.

View reggieb's full-sized avatar

Rob Nichols reggieb

View GitHub Profile
@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 / 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 / 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 / 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 / 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
#!/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 / hostess.rb
Created November 11, 2013 08:52
geminabox hostess. Version at point where rolled back to just proxy bundler actions.
require 'sinatra/base'
require 'httpclient'
module Geminabox
class Hostess < Sinatra::Base
%w[/specs.4.8.gz
/latest_specs.4.8.gz
/prerelease_specs.4.8.gz
@reggieb
reggieb / google_contact_list
Last active December 25, 2015 16:48
Get a user's google contacts using their valid access token (so they only need to authenticate once)
require "net/http"
require "rexml/document"
class GoogleContactList
attr_reader :token
attr_accessor :response
class << self
def cache
@reggieb
reggieb / JQuery version
Created July 15, 2013 08:20
Display the current JQuery version within a rails view
jQuery <span id='jquery_version'></span>
<%= javascript_tag do %>
var jQueryVersion = jQuery.fn.jquery;
$('#jquery_version').html(jQueryVersion);
<% end %>
@reggieb
reggieb / curl_typhoeus_config_issue
Created July 1, 2013 08:15
I think I have something miss-configured in my curl setup and it is causing errors when loading typhoeus
require 'typhoeus'
LoadError: Could not open library 'libcurl': libcurl: cannot open shared object file: No such file or directory.
Could not open library 'libcurl.so': /lib/i386-linux-gnu/libssl.so.1.0.0: symbol CRYPTO_memcmp, version OPENSSL_1.0.0 not defined in file libcrypto.so.1.0.0 with link time reference
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/ffi-1.1.5/lib/ffi/library.rb:121:in `block in ffi_lib'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/ffi-1.1.5/lib/ffi/library.rb:88:in `map'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/ffi-1.1.5/lib/ffi/library.rb:88:in `ffi_lib'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/typhoeus-0.4.2/lib/typhoeus/curl.rb:405:in `<module:Curl>'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/typhoeus-0.4.2/lib/typhoeus/curl.rb:6:in `<module:Typhoeus>'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/typhoeus-0.4.2/lib/typhoeus/curl.rb:5:in