Created
November 16, 2015 23:05
-
-
Save benwilson512/ba4cbe28f16016e438f6 to your computer and use it in GitHub Desktop.
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 PuzzledPintScriptElixir do | |
@base_string "http://www.puzzledpint.com/puzzles/august-2015/semaphore/" | |
defp get_file_strings do | |
File.read! "/usr/share/dict/cracklib-small" | |
end | |
def list_of_urls do | |
get_file_strings | |
|> String.split("\n", trim: true) | |
|> Enum.filter(fn line -> String.length(line) == 7 end) | |
|> Enum.map(fn line -> @base_string <> line end) | |
end | |
def pmap_printer_func(collection, fun) do | |
me = self | |
collection | |
|> Enum.map(fn (elem) -> | |
spawn_link fn -> (send me, {self, {fun.(elem), elem}}) end | |
end) | |
|> Enum.map(fn (pid) -> | |
receive do | |
{^pid, result} -> | |
result | |
end | |
end) | |
end | |
def main do | |
list_of_urls | |
|> Stream.map(&IO.inspect/1) | |
|> pmap_printer_func(&HTTPotion.get/1) | |
|> Enum.map(&log_errors/1) | |
end | |
@doc """ | |
Prints the urls if the response was 404 | |
""" | |
def log_errors({%{status_code: 404}, url} = result) do | |
IO.puts url | |
result | |
end | |
def log_errors(result), do: result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment