Skip to content

Instantly share code, notes, and snippets.

View jeremyf's full-sized avatar

Jeremy Friesen jeremyf

View GitHub Profile
# This is a theoretical means of writing a command line tool for pushing jobs
# into Resque. This is what we've explored. It allows us to keep our workers
# and other models in the same repository.
require 'resque'
# In the worker application, the SomeWorker class is defined and has methods for
# performing the work. This
class SomeWorker
def initialize(pid)
### Is the ActiveRecord pattern the correct Pattern for Long Term preservation concerns
> Active Records are special forms of DTOs [Data Transfer Objects]. They are data structures with public variables; but they typically have navigational methods like *save* and *find*. Typically these Active Records are direct translations from database tables, or other data sources.
>
> Unfortunately we often find that developers try to treat these data structures as though they were objects by putting business rule methods in them.
> This is awkward because it creates a hybrid data structure and an object.
>
> The solution, of course, is to treat the Active Record as a data structure and to create separate objects that contain the business rules and that hide their internal data (which are probably just instance of the Active Record).
>
> -- Martin, Robert C. "Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin Series)" pp
@jeremyf
jeremyf / columns_to_markdown
Created August 28, 2014 02:24
Make a markdown table pretty by creating uniform column spacing
#!/usr/bin/env ruby -wU
# Takes your paste buffer and outputs a markdown table with pretty spacing
content = `pbpaste`.strip
def columnize(line)
line.sub(/\A\s*\|?(.*)\|?\Z/, '\1').split("|")
end
lines = content.split("\n")
column_count = columnize(lines.first).size
@jeremyf
jeremyf / columns_to_markdown
Created August 27, 2014 23:22
Apply pretty padding to markdown table
#!/usr/bin/env ruby -wU
content = `pbpaste`.strip
def columnize(line)
line.sub(/\A\|(.*)\|\s*\Z/, '\1').split("|")
end
lines = content.split("\n")
column_count = columnize(lines.first).size
@jeremyf
jeremyf / gist:c5fb5d9367a568b2b4b1
Created May 15, 2014 15:09
Spitballing an adjustment to UC's virus detection
class CurationConcern::GenericWorksController < CurationConcern::BaseController
before_filter :rip_out_viral_files, only: [:create, :update]
def rip_out_viral_files
files = attributes_for_actor(:files)
good_files = []
viral_files = []
files.each do |file|
if viral?(file)
viral_files << file
@jeremyf
jeremyf / spec_support.rb
Created April 25, 2014 17:20
Spitballing some spec_support for mixed in behaviors
# a-gem/lib/hydra_permlink/spec_support.rb
require 'rspec'
shared_examples 'a permalinked object' do |options|
let(:model) { described_class.new }
included_services = options.fetch(:services)
if included_services.include?(:doi)
it 'should permalink to a DOI'
end
@jeremyf
jeremyf / gist:10743933
Created April 15, 2014 16:01
Work around
def datastream_to_show
super
rescue Exception => e
if params[:datastream_id] == 'thumbnail'
redirect_to 'path/to/default thumbnail'
return false
else
raise e
end
end
Feature: Do not create profile pages for new contributors when works are submitted
# https://jira.duraspace.org/browse/HYDRASIR-275
Scenario Outline: Associate with contributor to a person
Given I am an authenticated user
And I am on the <action_name> work page
When I fill out the type ahead search for a contributor
And select a person
And submit a valid form
@jeremyf
jeremyf / soft_delete.rb
Created February 18, 2014 16:18
Possible solution to Soft Delete in Rubydora 1.7.x
require 'rubydora/repository'
require 'rubydora/rest_api_client'
require 'active_fedora/digital_object'
require 'active_fedora/base'
module Rubydora
class PerformedSoftDelete < RuntimeError
attr_reader :options
def initialize(method_name, pid, options)
@jeremyf
jeremyf / group_membership_spec.rb
Created February 18, 2014 16:08
A set of specs for defining how the amend group membership form will behave
describe GroupMembershipForm do
let(:group) { Group.new }
let(:group_id) { 'abc:123'}
let(:person) { Person.new }
let(:member_id) { 'abc:456'}
let(:params) {
{
# These are the parameters that are generated in the existing form.
"group_id" => group_id