Skip to content

Instantly share code, notes, and snippets.

View stevegraham's full-sized avatar
🛠️
Building @tellerhq

Stevie Graham stevegraham

🛠️
Building @tellerhq
View GitHub Profile
document.addEventListener("DOMContentLoaded", function() {
var tellerConnect = TellerConnect.setup({
applicationId: "your_app_id",
skipPicker: true,
onInit: function() {
document.querySelector("button.teller-connect").addEventListener("click", function() {
tellerConnect.open({institution: "chase"})
})
},
onSuccess: function(enrollment) {
@stevegraham
stevegraham / teller_payments.rb
Created May 8, 2018 14:20
Teller payment example with signatures
require "net/https"
require "time"
require "base64"
require "uri"
require "securerandom"
# Load your private key
pkey = OpenSSL::PKey::RSA.new File.read("private_key.pem")
# Create new HTTP request
@stevegraham
stevegraham / payment_example.rb
Created May 8, 2018 14:17
Teller payment example with signature
require "net/https"
require "time"
require "base64"
require "uri"
require "securerandom"
# Load your private key
pkey = OpenSSL::PKey::RSA.new File.read("private_key.pem")
# Create new HTTP request
defmodule Foo do
def bar(%{baz => _}), do: "I wish pattern matching map keys worked"
end
defmodule Teller.Web.SignupForm do
use Form,
email: :email,
password: :password,
password_confirmation: :password
validates :email, presence: true
validates :password, length: [min: 8], confirmation: true
end
@stevegraham
stevegraham / example.ex
Last active August 30, 2015 04:47
Memorex - a cache for expensive code paths
require Memorex
Memorex.start_link([])
# Cache this expensive function call, e.g. external service API
Memorex.get("unique_cache_key", ttl: 30) do
do_some_expensive_shit
end

http: [compress: true] is set on App.Endpoint

defmodule App.Router do
  use Phoenix.Router

  scope "/", App do
    resources "foo", FooController do
  end
end
@stevegraham
stevegraham / mockery.ex
Created July 20, 2015 03:26
Mockery example
defmodule RequestTest do
use ExUnit.Case, async: false
use Mockery
def dsl_test do
Mockery.intercept do
request = %Request{ method: :post, uri: "http://example.com:3000/users", body: "hello=world", headers: %{ "User-Agent" => "My App" } }
response = %Response{ status: 201 }
stub_request request, response
defmodule Knox.Ecto.Hstore do
@behaviour Ecto.Type
def type, do: :hstore
def blank?, do: false
def load(t), do: { :ok, t }
def dump(t), do: { :ok, t }
def cast(t), do: { :ok, t }
end
@stevegraham
stevegraham / fizzbuzz.ex
Created December 20, 2014 14:46
Functional FizzBuzz
defmodule FizzBuzz do
def upto(n) when n > 0, do: 1..n |> Enum.map(&fizzbuzz/1)
defp fizzbuzz(n) when rem(n, 15) == 0, do: "FizzBuzz"
defp fizzbuzz(n) when rem(n, 3) == 0, do: "Fizz"
defp fizzbuzz(n) when rem(n, 5) == 0, do: "Buzz"
defp fizzbuzz(n), do: n
end