Skip to content

Instantly share code, notes, and snippets.

View adamrobbie's full-sized avatar

Adam Robbie adamrobbie

View GitHub Profile
@adamrobbie
adamrobbie / stockpair
Created October 8, 2021 15:30
Interview question solution
defmodule Test do
@moduledoc """
Documentation for `Test`.
"""
@spec find_stack_pair(any) :: Integer
def find_stack_pair(list) do
list
|> pairwise()
|> IO.inspect(label: "after pairing")
|> calculate()
@adamrobbie
adamrobbie / Gemfile
Created November 13, 2012 15:28
Rails Endless pagination
gem 'will_paginate'
### Keybase proof
I hereby claim:
* I am adamrobbie on github.
* I am adamrobbie (https://keybase.io/adamrobbie) on keybase.
* I have a public key ASDXwfa1LGkjFtp9MtsGYrFK9mn9YqJoHiN12Al8gJd8UAo
To claim this, I am signing this object:
@adamrobbie
adamrobbie / havershine.ex
Created March 31, 2016 19:51
Geodistance (havenshine function) in elixir
defmodule Havershine do
def distance(lng1, lat1, lng2, lat2) do
[rLng1, rLat1, rLng2, rLat2] = for deg <- [lng1, lat1, lng2, lat2], do: deg2rad(deg)
dLon = rLng2 - rLng1
dLat = rLat2 - rLat1
a = :math.pow(:math.sin(dLat/2), 2) + :math.cos(rLat1) * :math.cos(rLat2) * :math.pow(:math.sin(dLon/2), 2)
c = 2 * :math.asin(:math.sqrt(a))
@adamrobbie
adamrobbie / gist:f821f3c95e4a3185c4c2
Created January 10, 2016 05:21
HRFlow discussion
My current understanding of the process..
- 1 upload excell
- 2 hrflow creates form collector and a set or participant flows
- 3 form collector sends emails to participants with a link to the appropriate HRFORM
- upon completion of the partiicpant form, HRForms uses the completionURL to let us know
- if they have a spouse (unsure from the weird payload how this is deteremined, marriage status etc), we should send an email
to the spouse with another HRForm url
- upon that completion we'll recieve another post to our submitform endpoint and fetch the data again and send the event along to the
participant form.
- eventually we want the participant fsm to complete with a signed boolean, unsure when this is determined as from the code this is assumed to happen
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require File.dirname(__FILE__) + '/blueprints'
require 'faker'
require 'rails/test_help'
require 'minitest/autorun'
require 'minitest/pride'
class MiniTest::Unit::TestCase
include MiniTest::ActiveRecordAssertions
module MiniTest
module Assertions
module ActiveRecord
# assert_association User, :has_many, :editables, :polymorphic => true
#
def assert_association(clazz, association, associate, options={})
reflected_assoc = clazz.reflect_on_association(associate)
@adamrobbie
adamrobbie / string_to_bool.rb
Created January 18, 2013 15:17
Adds a to_bool method to Ruby's primitive String class, to convert to a boolean.
class String
def to_bool
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end
end
@adamrobbie
adamrobbie / gist:4235157
Created December 7, 2012 18:09
Heroku Secondary DB connection
# config/application.rb
module MyApp
class Application < Rails::Application
... other configs
config.secondary_database_url = ENV['SECONDARY_DB_URL']
end
end
We may want to override this in development / test
@adamrobbie
adamrobbie / application.rb
Created November 15, 2012 11:57
ActionMailer hook to intercept all outgoing development email
# Place me in config/application.rb or in your development file
if Rails.env.development?
class Hook
def self.delivering_email(message)
message.to = "\"#{message.to.first}\" <my@email.com>"
message.cc = nil if !message.cc.nil?
message.bcc = nil if !message.bcc.nil?
end
end