gangstead
This is my second year doing AoC in Elixir and my first year doing it with Livebook.
When I was doing just plain Elixir I usually set up each day as an exs script and ran it with elixir 2021-day1.exs 2021-1input.txt That way I could save the example input from the problem setup, and the user-specific input and switch back and forth.
@josevalim did it in livebook last year and I was looking at his code where he used Kino inputs (example) and copy/pasted the AoC input and ran it. This works great, but your input is not persisted across sessions.
I’ve tried reading a file from the Livebook, putting it in the same directory as my .livemd file and reading the file as file1.txt and ./file1.txt, but that’s not right. The file is not found. I’m guessing the path is relative to the livebook process, which might be different depending on how you’re running livebook (escript, livebook.app, or hosting it on a webserver).
Are there any other tips for reading a file from within a livebook? Whether it’s on the livebook server or from the browser with Kino, a smart cell, something else?
Trending in Challenges
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











First 5 of 5 Posts
stevensonmt
maybe try using
"#{__DIR__}/file1.txt"as the file path?gangstead
That works!
I’m still interested if there’s any way to do a file upload into a livebook. Maybe that’s a smart cell or something I could develop?
bmitc
I am also using Livebook, and you can find my 2022 notebook here: advent-of-code/2022/elixir/advent_of_code_2022.livemd at main · bmitc/advent-of-code · GitHub
Warning: Solutions are there for days 1 and 2.
In particular, I am using a
Utilitiesmodule to provide the data input file reading:I download all of the input files and name them as
day_<number>_input.txt. For example,day_01_input.txt. I put them in adatafolder up a level from the notebook because the intention is to potentially support several languages but keep the input files in a single location for a given year.I also have tests setup to help in refactoring after I have solved a puzzle.
mruoss
I’m using kino_aoc. A very handy tool imo.
https://github.com/mruoss/advent_of_code/blob/main/2022/day04.livemd
netto
Hey.
I use this SmartCell that fetches the puzzle and the input to a Livebook.
https://github.com/nettinho/smaoc
Hope it can be helpful.