This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defp deps do | |
| [ | |
| {:kaffe, "~> CURRENT_VERSION_NUMBER"} | |
| ] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule MyAppWeb.InboundController do | |
| use MyAppWeb, :controller | |
| def create(conn, params) do | |
| # POST the message to Kafka | |
| text(conn, "") | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| scope "/api", MyAppWeb do | |
| pipe_through :api | |
| post "/inbound", InboundController, :create | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config :kaffe, | |
| producer: [ | |
| endpoints: ["<YOUR_BOOSTRAP_SERVER>": 9092], | |
| topics: ["sms.inbound.v1"], | |
| ssl: true, | |
| sasl: %{ | |
| mechanism: :plain, | |
| login: "<YOUR_API_KEY>", | |
| password: "<YOUR_API_SECRET>" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| contacts = Enum.group_by(contacts, fn c -> c["email"] end) | |
| for lead <- leads do | |
| matching_contacts = contacts[lead["email"]] | |
| if matching_contacts do | |
| # Return a tuple with the lead and any contacts that match | |
| {lead, matching_contacts} | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for lead <- leads do | |
| matching_contacts = Enum.filter(contacts, fn c -> c["email"] == lead["email"] end) | |
| # Return a tuple with the lead and any contacts that match | |
| {lead, matching_contacts} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| random = fn -> Enum.random(97..122) end | |
| string = fn -> to_string([random.(), random.(), random.(), random.()]) end | |
| leads = | |
| for _ <- 1..10_000 do | |
| %{"first" => string.(), "last" => string.(), "email" => string.() <> "@example.com"} | |
| end | |
| contacts = | |
| for _ <- 1..10_000 do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule APR do | |
| @moduledoc """ | |
| This module has a single function, `calc_apr`, for calculating an APR on a simple installment loan. | |
| This code was a conversion of a Groovy implementation of the algorithim in this answer on Stack Overflow: https://stackoverflow.com/a/3190428/7223229 | |
| """ | |
| @doc """ | |
| Takes three arguments: the number of payments (in months), monthly payments, and the amount being financed not including interest. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule States do | |
| @moduledoc """ | |
| A util that allows you to search for the uppercase abbreviation | |
| of a state by name (case insensitive) or the capitalized name | |
| of a state by abbreviation (case insensitive). | |
| """ | |
| @states_to_abbr %{ | |
| "Alabama" => "AL", | |
| "Alaska" => "AK", |
NewerOlder