Skip to content

Instantly share code, notes, and snippets.

View dividedharmony's full-sized avatar

David Harmon dividedharmony

View GitHub Profile
@dividedharmony
dividedharmony / null_object.rb
Created September 21, 2018 17:48
An abstract class to represent null objects
# frozen_string_literal: true
class NullObject
class << self
SOFT_DEFAULTS = {
array: [],
hash: {},
null: nil
null_object: NullObject
}.freeze
@dividedharmony
dividedharmony / list-cloudfront-distributions.rb
Created April 26, 2017 15:34
A Shell Script for listing the Domain names of your CloudFront Distributions and their Origins
#!/usr/bin/env ruby
require 'json'
#######
#
# Classes to help execution
#
#######
@dividedharmony
dividedharmony / perfect_mind.rb
Created December 7, 2016 14:06
PerfectMind is a Brainf**k compiler in Ruby
##
# Instructions from https://www.codewars.com/kata/my-smallest-code-interpreter-aka-brainf-star-star-k/train/ruby
#
# Inspired from real-world Brainf**k, we want to create an interpreter of that
# language which will support the following instructions
# (the machine memory or 'data' should behave like a potentially infinite array of bytes, initialized to 0):
#
# > increment the data pointer (to point to the next cell to the right).
# < decrement the data pointer (to point to the next cell to the left).
# + increment (increase by one, truncate overflow: 255 + 1 = 0) the byte at the data pointer.
@dividedharmony
dividedharmony / EgyptianFraction.rb
Last active November 30, 2016 13:54
Solve Egyptian Fractions using Fibonacci's Greedy Algorithm
class EgyptianFraction
class ImproperFraction < StandardError; end
attr_reader :converted_fractions, :original_rational, :current_rational
def initialize(numerator, denominator)
raise ImproperFraction if numerator > denominator
@converted_fractions = []
@original_rational = Rational(numerator, denominator)
@current_rational = original_rational
@dividedharmony
dividedharmony / keybase.md
Created November 14, 2016 20:08
Keybase Verify

Keybase proof

I hereby claim:

  • I am dividedharmony on github.
  • I am dharmon202 (https://keybase.io/dharmon202) on keybase.
  • I have a public key ASAaa0jrLVCaEzdWXmBKp1qbh9jKEjCFQFrtFgz51DHOiAo

To claim this, I am signing this object: