Skip to content

Instantly share code, notes, and snippets.

View jeremyf's full-sized avatar

Jeremy Friesen jeremyf

View GitHub Profile
# A simulation for various dice rolling mechanisms
# For more information on how it was used. http://takeonrules.com/2015/09/10/running-a-fifth-edition-character-funnel/
#
# $ ruby random_stat_methods.rb
#
# I use `ruby random_stat_methods.rb | pbcopy` then paste that into a Google Spreadsheet to generate a chart.
class Simulation
def initialize
@scenarios = {}
@jeremyf
jeremyf / .gitconfig
Created September 10, 2015 20:20
A git config with lots of things going on
# Sample gitconfig
#
[hub]
protocol = https
[user]
name = Jeremy Friesen
email = jeremy.n.friesen@gmail.com
[credential]
helper = osxkeychain
[github]
DEFAULT_POWER = 10
def exponent(integer, power: DEFAULT_POWER, **keywords)
integer ** power
end
puts exponent(10, power: 2)
puts exponent(10)
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
@jeremyf
jeremyf / sipity-erd.dot
Created May 14, 2015 18:08
Sipity Permission ERD
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

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 / dependency_injection_for_sipity.rb
Created May 6, 2015 18:42
Dependency Injection for Sipity
class Etd::Mapper
def initialize(work:, repository: default_repository)
self.work = work
self.repository = repository
end
def call
# do things
end
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
#!/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."
@jeremyf
jeremyf / hydra-works.rb
Created November 6, 2014 22:20
Rudimentary prototype of the proposed Hydra::Works.
# 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