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
def send_text_message(phone_number, message) do | |
ExTwilio.Api.create(ExTwilio.Message, | |
[to: phone_number, | |
from: Application.get_env(:ex_twilio, :send_number), | |
body: message]) | |
end |
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
def send_text_message( | |
%Plug.Conn{adapter: {Plug.Adapters.Test.Conn, _}}, _, _), do: nil | |
def send_text_message(_, phone_number, message) do | |
ExTwilio.Api.create(ExTwilio.Message, | |
[to: phone_number, | |
from: Application.get_env(:ex_twilio, :send_number), | |
body: message]) | |
end |
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 Project.Twilio do | |
def send_text_message(phone_number, message) do | |
ExTwilio.Api.create(ExTwilio.Message, | |
[to: phone_number, | |
from: Application.get_env(:ex_twilio, :send_number), | |
body: message]) | |
end | |
end |
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 Project.FakeTwilio do | |
def send_text_message(phone_number, message), do: nil | |
end |
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
# in config.exs | |
config :project, text_service: Project.Twilio | |
# in test.exs | |
config :project, text_service: Project.FakeTwilio |
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
def some_method do | |
# some code here | |
text_module.send_text_message(phone_number, message_body) | |
end | |
defp text_module, do: Application.get_env(:my_app, :text_service) |
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
{ | |
"type": "FeatureCollection", | |
"features": [ | |
{ | |
"type": "Feature", | |
"geometry":{ | |
"type":"Polygon", | |
"coordinates":[ | |
[[ -118.47000042983923, 34.027237322664057 ], | |
[ -118.46997469284874, 34.027150122627894 ], |
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
@block_file "data/sm_blocks.geojson" | |
@zone_file "data/sm_zones.geojson" | |
defp get_commercial_zones do | |
%{"features" => zones} = Poison.decode!(File.read!(@zone_file)) | |
zones | |
end | |
defp get_blocks do | |
%{"features" => blocks} = Poison.decode!(File.read!(@block_file)) |
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
commercial_zones = get_commercial_zones() | |
|> Enum.map(fn(%{"geometry" => %{"coordinates" => [coordinates]}}) -> | |
coordinates | |
end) | |
commercial_blocks = get_blocks() | |
|> Enum.map(fn(geoJson = %{"geometry" => %{"coordinates" => [coordinates]}}) -> | |
# we need the coordinates to check for intersections and the | |
# original geoJson because if this block is in a commercial | |
# zone we will want to output it to a new file |
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
from shapely.geometry import Polygon, Point | |
def blockInZone(block, zone): | |
boundaryPoints = [] | |
for pair in block: | |
# reverse the order because from the file | |
# coordinates data was read in lat, long | |
# and for Shapely we need to put the data | |
# as long, lat | |
boundaryPoints.append((pair[1], pair[0])) |
OlderNewer