Created
November 16, 2015 22:46
-
-
Save mijoharas/99cd06827ab9ef9fe04d to your computer and use it in GitHub Desktop.
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 PuzzledPintScriptElixir do | |
HTTPotion.start | |
defp get_file_strings do | |
File.read! "/usr/share/dict/cracklib-small" | |
end | |
def list_of_urls do | |
base_string = "http://www.puzzledpint.com/puzzles/august-2015/semaphore/" | |
list_of_words = get_file_strings | |
list_of_lines = String.split(list_of_words, "\n", trim: true) | |
filtered_words = Enum.filter(list_of_lines, fn x -> String.length(x) == 7 end) | |
Enum.map(filtered_words, fn x -> base_string <> x end) | |
end | |
def pmap_printer_func(collection, fun, condition_func) do | |
me = self | |
collection | |
|> Enum.map(fn (elem) -> | |
:timer.sleep(200) | |
spawn_link fn -> (send me, {self, [ fun.(elem), elem ] }) end | |
end) | |
|> Enum.map(fn (pid) -> | |
receive do {^pid, result} -> | |
if condition_func.(result[0]) do | |
IO.puts(result[1]) | |
end | |
result end | |
end) | |
end | |
def getter_func(url) do | |
IO.puts url | |
HTTPotion.get url | |
end | |
def condition_function(response) do | |
response.status_code == 404 | |
end | |
def main do | |
pmap_printer_func(list_of_urls, &getter_func/1, &condition_function/1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Timeouts in code: