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()
### 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
@adamrobbie
adamrobbie / run_length.ex
Last active August 29, 2015 14:07
Elixir Run-Length Encoding
defmodule RunLength do
def run(string) do
compress(String.slice(string, 1..-1), String.slice(string, 0, 1), 1, "")
end
defp compress("", char, count, result) do
result <> Integer.to_string(count) <> char
end
defp compress(string, char, count, result) do
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 54.88.210.143 [54.88.210.143] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/Users/adamrobbie/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /Users/adamrobbie/.ssh/id_rsa type 1
debug1: identity file /Users/adamrobbie/.ssh/id_rsa-cert type -1
uri = URI::HTTP.build(
:host => '127.0.0.1',
:port => 9393,
:path => request.path_info,
:query => request.query_string
)
content_type 'application/json', :charset => 'utf-8'
Net::HTTP.get(uri)
module SoftDeletable
extend ActiveSupport::Concern
def soft_delete!
find_each do |record|
record.soft_delete!
end
end
included do
# == Paperclip without ActiveRecord
#
# Simple and lightweight object that can use Paperclip
#
#
# Customized part can be extracted in another class which
# would inherit from SimplePaperclip.
#
# class MyClass < SimplePaperclip
# attr_accessor :image_file_name # :<atached_file_name>_file_name
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