Skip to content

Instantly share code, notes, and snippets.

@taylonr
Last active June 20, 2016 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taylonr/4e7b20cb10b9eaaf236fe4f42b2dfa39 to your computer and use it in GitHub Desktop.
Save taylonr/4e7b20cb10b9eaaf236fe4f42b2dfa39 to your computer and use it in GitHub Desktop.
Get random line from a file
def get_line(path) do
path
|> File.read!
|> String.split(~r{\n})
|> Enum.map(&String.strip/1)
|> Enum.filter(fn x -> String.length(x) <= 140 end)
|> Enum.random
end
File.read!(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment