This file contains 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
# first, add :inets to :extra_applications or some other similar method | |
defp simple_http_request(request, http_method) do | |
Application.ensure_all_started(:inets) | |
Application.ensure_all_started(:ssl) | |
ok_block = {'HTTP/1.1', 200, 'OK'} | |
options = [{:ssl, [{:verify, :verify_none}]}] | |
with {:ok, {^ok_block, _headers, json_text}} <- | |
:httpc.request(http_method, request, options, []), |
This file contains 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 RichModel do | |
@moduledoc """ | |
A mini-package that injects basic db functionality in any model. | |
Good for rapid prototyping. | |
""" | |
defmacro __using__([]) do # alternatively, `defmacro __using__([repo: repo]) do ....` | |
quote do | |
alias __BASE_MODULE__.Repo # __BASE_MODULE__ is the app root name |
This file contains 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
text = "sms text" | |
opts = [follow_redirect: true, basic_auth: {@account_sid, @auth_token}] | |
base_url = "https://api.twilio.com/2010-04-01/Accounts/#{@account_sid}/Messages.json" | |
payload = "Body=#{text}&From=#{@number_from}&To=#{number_to}" | |
headers = ["Content-Type": "application/x-www-form-urlencoded"] | |
case :hackney.request(:post, base_url, headers, payload, opts) do | |
{:ok, 201, _hs, _ref} -> | |
json(conn, %{message: "Message sent successfully!"}) | |
{:error, reason} -> | |
send_resp(conn, 500, Jason.encode!(%{message: reason})) |
This file contains 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
#first, we need to obtain a converter to GMT, needed for the Date header | |
# GMT format: "Sun, 22 Nov 2015 08:16:38 GMT" | |
defp utc_to_gmt(utc_datetime) do | |
# format = "{WDshort}, {0D} {Mshort} {YYYY} {h24}:{m}:{s} GMT" | |
days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] | |
months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] | |
day_of_week = Date.day_of_week(utc_datetime) | |
month = Enum.at(months,utc_datetime.month-1) | |
year = utc_datetime.year | |
time = to_string(Time.truncate(DateTime.to_time(utc_datetime),:second)) |
This file contains 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
# app deps | |
sudo yum install git | |
# erlang deps | |
sudo yum groupinstall "Development Tools" | |
sudo yum install ncurses-devel openssl-devel | |
# erlang | |
wget http://www.erlang.org/download/otp_src_19.2.tar.gz | |
tar -zxvf otp_src_19.2.tar.gz |