-
AI-generated Vegan Recipe Site
I recently came across Fly.io’s article on LangChain. I decided to give it a spin and created my own Vegan Recipe site based on the template they gave. You can check it out here: https://greatvegan.recipes. Note that the design kinda sucks because I (unfortunately) am not a designer. Sorry!
Enjoy!
-
Apple is Effectively Paying You to Borrow Money from Them
With the introduction of the Apple Savings Account, Apple is now effectively paying you to borrow money from them. All you have to do is:
- Add money to your Apple Savings account. This money will be used to pay off your Apple Card balance at the end of the month.
- Remember to pay off your Apple Card in full every month so that you are not charged interest.
Back in my finance days, we would have called this
arbitrage
. Big win for us Apple customers! -
Video Game Data Linear Regression
Today I was experimenting with the new Elixir Scholar library. My goal was to translate the following Colab: https://colab.research.google.com/drive/1Jq1QLC9x7PoovRdJbLKi_Pj_pm9l-6No
You can find the Livebook where I translated that Colab to Elixir here: https://github.com/danieljaouen/video-game-data/blob/main/video_game_data.livemd
As you can see if you run the Livebook, linear regression probably wasn’t the best model here, but I was just using this as a Scholar learning exercise, so I am pretty happy with how this turned out. We probably would have had better results had we removed the outliers, but I will leave that as an exercise for the reader.
Enjoy!
-
OpenSUSE Tumbleweed
I recently installed OpenSUSE Tumbleweed on an old laptop I had lying around my apartment. I did so to test out my new install script ( https://github.com/danieljaouen/dotfiles/blob/main/install.sh ) which still had some rough edges (and still does). I figured I’d write a blog post about the setup process along with some comments.
First, I thought the installer was very intuitive. I didn’t keep the old Windows partition, so partitioning was a breeze with the installer. Just a few clicks to get everything partitioned. Overall, the process took about half an hour total. Not bad!
I also like that SUSE offers a rolling release in the form of Tumbleweed. I have some experience with Arch, so that is a nice touch. Nothing beats not having to upgrade your system every so often.
One thing I’ve read is that OpenSUSE doesn’t have some popular packages. While most of the packages in my installer script were available, I did notice that
duf
was not. I recently installed Arch on a server and noticed it did haveduf
. Not a big deal, but something to watch out for if you do want to install OpenSUSE.Overall, my experience so far with OpenSUSE has been pleasant. You can download the installer here: https://get.opensuse.org/tumbleweed/. Hopefully, this has been helpful to you. Have a great day!
-
emacsclient and fzf
I recently came across Andrew Quinn’s article on fzf: https://andrew-quinn.me/fzf/
I just thought I’d add that, you can open up a fzf-inded file in
emacsclient
by typing into your terminalec <C-t>
Of course, you will need to have
emacsclient
aliased toec
:alias ec='emacsclient'
.Useful!
-
Introducing LouLinks
Hey there! Tonight I was feverishly working on a basic Phoenix 1.7.0 app that lets me store various links. The goal was to build out a site that would replace having to keep a whole bunch of tabs open in my laptop and mobile browsers. Here it is: https://loulinks.net. Enjoy!
-
ChatGPT and Flask
I recently used ChatGPT to generate a Flask app that automatically generates the current price of Solana. You can check it out here: https://github.com/danieljaouen/chatgpt-solana-price
Enjoy!!
-
Happy Holidays!
Wishing you and your close ones a very Happy Holidays! May the worst times of your 2023 be as the best times of your 2022. 🙂
-
A Brief Introduction to Phoenix and LiveView (Part 2)
This is a continuation of Part 1, which you can find here:
https://danieljaouendevelopment.com/2022/12/18/a-brief-introduction-to-phoenix-and-liveview-part-1/Now, let’s navigate to the
index.html.heex
file, which is located inlib/todo_web/live/todo_item_live/index.html.heex
..header
The first thing we encounter is something that looks like an HTML tag, but is actually a LiveView function component. We can tell that it is a function component because it begins with a
.
. You can find the definition of the header component inlib/todo_web/components/core_components.ex
. We can see that it has a class attr, an inner_block, a subtitle, and associated actions slots.In
:actions
, we see that there is a.link
. This is defined in LiveView itself (see:deps/phoenix_live_view/lib/phoenix_component.ex
— search for “def link
“. Feel free to also read the documentation at the top of the file). You can find the documentation for thepatch
attr in the file listed above (search for"attr.(:patch"
). The long and short of it is that/todo_items/new
is first translated into a Verified Route (note the~p
sigil), which then will callhandle_params
with the:new
action..table
Next, we have a
.table
. You can also view this function component inlib/todo_web/components/core_components.ex
. Basically, the table function component has three attrs (id
,row_click
, androws
) and a slotcol
which takes an optional attrlabel
plus a slotaction
. Therows
attr passes each list item into the:let
slot of the associated slot, and therow_click
attr callsJS.navigate
, which will, in turn navigate the page to theshow.ex
LiveView. You can learn more about theJS
module here: https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.JS.html.modal
Next, we have the
modal
function component, which is displayed only when the@live_action
is in[:new, :edit]
. Basically, it renders a LiveComponent, which you can find inlib/todo_web/live/todo_item_live/form_component.ex
. You can read more about LiveView’s LiveComponent’s here: https://hexdocs.pm/phoenix_live_view/Phoenix.LiveComponent.htmlConclusion
And that’s it! Now we navigated through
index.html.heex
, so you should have a better understanding of function components and where you can find the docs for them.Again, if you gained value from this article, feel free to throw me a dollar or two on my Buy Me a Coffee page, which you can find here: https://www.buymeacoffee.com/danieljaouen
Thanks for reading!
-
A Brief Introduction to Phoenix and LiveView (Part 1)
Hello, once again! Today, I am going to introduce you to the basics of the web framework, Phoenix. Phoenix is a web framework that reached 1.0 in 2015 written in the Elixir programming language. It is generally seen as the “successor” to Ruby on Rails, although that can be hotly debated and is not the purpose of this post. It is well known for its use of the real-time package, LiveView, which can help minimize the amount of Javascript that you have to write. It is well-suited for programmers who want a combination of functionality and performance. If that sounds like you, let’s jump right in!
Installation
I will assume that you have Elixir 1.14 installed. We are going to be using Phoenix version 1.7 in this tutorial. To install it, run the following command in your terminal:
mix archive.install hex phx_new
You may need to uninstall your previous version first (if you had it installed already):
mix archive.uninstall phx_new
Creating the App
Great! Now, let’s begin our Phoenix project by using the
mix phx.new
command:mix phx.new todo
Great! Now let’s
cd
into the newtodo
directory and run the following commands:cd todo
mix ecto.createGreat! That created the initial PostgreSQL database for us. Now, let’s run the following command to make sure everything was set up correctly:
iex -S mix phx.server
Now browse to
localhost:4000
and you should see the Phoenix welcome page. If not, you will need to debug the reason you are getting your specific error.Creating the Todos
First, let’s take a look at the help dialog that ships with Phoenix by running the following command:
mix help phx.gen.live
Feel free to read this at your convenience. Now, let’s create the Todos using the following command:
mix phx.gen.live Items TodoItem todo_items text:string
Next, follow the instructions printed to your terminal about modifying your
router.ex
file.Next, run the generated database migrations:
mix ecto.migrate
Now restart the Phoenix server and re-navigate to
localhost:4000/todo_items
and you should see the listing page for your TodoItems. Great!Navigating the Generated Code
Now that we have the Todo app up-and-running, let’s navigate through the code to get a glimpse at how things work under the hood.
lib/todo_web/live/todo_item_live/index.ex
First, let’s take a look at index.ex, the generated Elixir code for the index LiveView. We notice five functions:
mount
handle_params
apply_action
handle_event
list_todo_itemsmount
is called when the client connects and is used to set up the initialsocket
. You will notice that there is norender
function, and that is because Phoenix uses a particular convention to display its templates: if there is an associatedindex.html.heex
adjacent toindex.ex
, that template will be used.handle_params
is called whenever we have a live navigation event. These events are what you would normally have separate HTTP requests for. You can learn more abouthandle_params
here:https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:handle_params/3
handle_event
is called whenever we have a JS “delete” event pushed to the page. Finally,list_todo_items
simply calls the associated context’s function.Next Up
Join me next time when we dive into
index.html.heex
. In the mean time, feel free to browse through the additional generated code.If you gained value from this post, feel free to throw me a dollar or two on my Buy Me a Coffee page, which you can find here:
https://www.buymeacoffee.com/danieljaouen
Your support goes to the cost of keeping the server up and is never unappreciated. Thanks!