Skip to content

Instantly share code, notes, and snippets.

Jeremy Friesen jeremyf

Block or report user

Report or block jeremyf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jeremyf
jeremyf / columns_to_markdown
Created Aug 28, 2014
Make a markdown table pretty by creating uniform column spacing
View columns_to_markdown
#!/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
View Rough Draft Blog Post
### 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
View some_worker.rb
# 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)
@jeremyf
jeremyf / hydra-works.rb
Created Nov 6, 2014
Rudimentary prototype of the proposed Hydra::Works.
View hydra-works.rb
# Rudimentary prototype of the proposed Hydra::Works.
#
# The idea is to use modules to define the interface of our data-structures.
# This is following the [Lotus Philosophy](https://github.com/lotus/docs/blob/master/philosophy.md)
module Hydra::Works
module Work
def initialize
@files = []
@members = []
end
View fantasy-demographic.rb
#!/usr/bin/env ruby -wU
if ARGV[0] =~ /-h/i
$stdout.puts "Generates a fantasy demographic of workers by population size."
$stdout.puts ''
$stdout.puts "./#{File.basename(__FILE__)} 2000"
$stdout.puts ''
$stdout.puts "Derived from Fantasy Demographics by Robert S Conley, 2010."
$stdout.puts "Released under the Creative Commons License Attribution 3.0 Unported."
$stdout.puts "You can share, remix, as long you give proper Attribution."
View attempt.rb
require 'rails_helper'
describe 'MultiValueInput', type: :input do
class Foo
extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations
def persisted?; false; end
attr_accessor :bar
@jeremyf
jeremyf / dependency_injection_for_sipity.rb
Created May 6, 2015
Dependency Injection for Sipity
View dependency_injection_for_sipity.rb
class Etd::Mapper
def initialize(work:, repository: default_repository)
self.work = work
self.repository = repository
end
def call
# do things
end
View clean-code-data-structure-vs-oo.md

Advice regarding mixing data structures and OO.

Procedural vs. OO

Procedural code (code using data structures) makes it easy to add new functions without changing the existing data structures. OO code, on the other hand, makes it easy to add new classes without changing existing functions.

The compliment is also true:

Procedural code makes it hard to add new data structures because all the functions must change.

@jeremyf
jeremyf / sipity-erd.dot
Created May 14, 2015
Sipity Permission ERD
View sipity-erd.dot
digraph models_diagram {
graph[overlap=false, splines=true]
"Sipity::Models::Collaborator" [shape=Mrecord, label="{Sipity::Models::Collaborator|id :integer\lwork_id :string\lsequence :integer\lname :string\lrole :string\lcreated_at :datetime\lupdated_at :datetime\lnetid :string\lemail :string\lresponsible_for_review :boolean\l}"]
"Sipity::Models::Group" [shape=Mrecord, label="{Sipity::Models::Group|id :integer\lname :string\lcreated_at :datetime\lupdated_at :datetime\l}"]
"Sipity::Models::GroupMembership" [shape=Mrecord, label="{Sipity::Models::GroupMembership|id :integer\luser_id :integer\lgroup_id :integer\lmembership_role :string\lcreated_at :datetime\lupdated_at :datetime\l}"]
"Sipity::Models::Processing::Actor" [shape=Mrecord, label="{Sipity::Models::Processing::Actor|id :integer\lproxy_for_id :string\lproxy_for_type :string\lname_of_proxy :string\lcreated_at :datetime\lupdated_at :datetime\l}"]
"Sipity::Models::Processing::Comment" [shape=Mrecord, label="{Sipity::Models::Processing::Comment|id :in
View comparable_simple_delegator.rb
module Sipity
module Decorators
# Provides a convenience wrapper of an object to assist in equality testing.
# This is key as it relates to PowerConverter and how it is used.
class ComparableSimpleDelegator < SimpleDelegator
class_attribute :base_class, instance_writer: false
def initialize(object, localization_assistant: default_localization_assistant)
super(object)
self.localization_assistant = localization_assistant
You can’t perform that action at this time.