Skip to content

Instantly share code, notes, and snippets.

View michaelminter's full-sized avatar

Michael Minter michaelminter

View GitHub Profile
module Contents
class ExerciseWrapper < Contents::BaseWrapper
attribute :name, String
attribute :type
validate :name, presence: true
def to_fhir
{
one: :attribute_name,
@michaelminter
michaelminter / generate_token.rb
Created January 26, 2017 21:52
Generate random token on create
# app/models/model_name.rb
class ModelName < ActiveRecord::Base
include Tokenable
end
# app/models/concerns/tokenable.rb
module Tokenable
extend ActiveSupport::Concern
included do
@michaelminter
michaelminter / money_handling.rb
Created August 31, 2016 01:21
Interviewzen test: Assuming an infinite supply of coins (1,5,10,25 cent denominations), programmatically make change for $0.98 using the least amount of coins possible.
class MoneyHandling
def least_number_coins(amount_cents)
coins = [25, 10, 5, 1]
remaining = amount_cents
count = {}
coins.each do |coin|
if amount_cents > coin
remainder = (remaining / coin).floor
count[coin] = remainder
#!/usr/bin/env python2
import athenahealthapi
import datetime
import csv
# Set up
key = 'FILTERED'
secret = 'FILTERED'
version = 'FILTERED'
practice_id = 123
@michaelminter
michaelminter / with_time_zone.rb
Created March 21, 2016 14:50
Assigns time zone to local time zone. Then sets back.
# Assigns time zone to local time zone. Then sets back.
# @param [String] tz_name
# @example
# with_time_zone 'UTC' { something() }
def with_time_zone(tz_name)
prev_tz = ENV['TZ']
ENV['TZ'] = tz_name
yield
ensure
ENV['TZ'] = prev_tz
@michaelminter
michaelminter / subject_node.rb
Last active January 7, 2016 19:44
Ruby on Rails arel outer left join
problem = Problem.select('problems.*, COUNT(problem_questions.id) AS problem_question_count')
.joins(Problem.arel_table.join(ProblemProblemQuestion.arel_table, Arel::Nodes::OuterJoin).on(ProblemProblemQuestion.arel_table[:problem_id].eq(Problem.arel_table[:id])).join_sources)
.joins(ProblemProblemQuestion.arel_table.join(ProblemQuestion.arel_table, Arel::Nodes::OuterJoin).on(ProblemQuestion.arel_table[:id].eq(ProblemProblemQuestion.arel_table[:problem_question_id]).and(ProblemQuestion.arel_table[:public].eq(true))).join_sources)
SELECT `problems`.* FROM `problems` LEFT OUTER JOIN `subject_nodes` ON `subject_nodes`.`id` = `problems`.`subject_node_id` WHERE `problems`.`deleted` = 0 AND (`problems`.`problem_subject_id` = 74 AND `problems`.`public` = 1 AND `problems`.`problem_set_type` IN (1, 2, 4) AND 'IF(problems.problem_set_type=4 AND problems.subject_node_id IS NOT NULL, subject_nodes.parent_id, problems.id) IS NOT NULL')
WHERE IF(problems.problem_set_type=4 AND problems.subject_node_id IS NOT NULL, subject_nodes.parent_id, problems.id) IS NOT NULL
WHERE IF(problems.problem_set_type=4 AND problems.subject_node_id IS NOT NULL, subject_nodes.parent_id IS NOT NULL, '')
WHERE (CASE problems.problem_set_type=4 AND problems.subject_node_id IS NOT NULL THEN subject_nodes.parent_id IS NOT NULL)
@michaelminter
michaelminter / api_logger.rb
Last active June 17, 2019 04:01 — forked from dblock/api_logger.rb
Rails Grape API logger
class ApiLogger < Grape::Middleware::Base
def before
Rails.logger.info "[api] Requested: #{request_log_data.to_json}\n" +
"[api] #{response_log_data[:description]} #{response_log_data[:source_file]}:#{response_log_data[:source_line]}"
end
private
def request_log_data
@michaelminter
michaelminter / board.rb
Last active August 29, 2015 14:22
Boggle Solver Challenge
class Board
attr_accessor :board
# Establishes new Boggle board
#
# @return [Array] an array of 4 rows containing an array of 4 columns of letters
def initialize
@board = (0..3).map{ Array.new(4){ [*'a'..'z'].sample } }
@words = []
end

Keybase proof

I hereby claim:

  • I am michaelminter on github.
  • I am mothore (https://keybase.io/mothore) on keybase.
  • I have a public key whose fingerprint is 0942 D325 3CA7 C25D 4E4C C5D0 2253 37AC 24A2 5BD1

To claim this, I am signing this object: