<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Marco</title>
    <description>The latest articles on DEV Community by Marco (@linediconsine).</description>
    <link>https://dev.to/linediconsine</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F767280%2F11d9bbea-e2a1-48b2-acb6-26a7091acab8.png</url>
      <title>DEV Community: Marco</title>
      <link>https://dev.to/linediconsine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/linediconsine"/>
    <language>en</language>
    <item>
      <title>Update 3: Kamal + Postgres Finally Running</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Mon, 16 Feb 2026 03:02:51 +0000</pubDate>
      <link>https://dev.to/linediconsine/update-3-kamal-postgres-finally-running-4k6e</link>
      <guid>https://dev.to/linediconsine/update-3-kamal-postgres-finally-running-4k6e</guid>
      <description>&lt;p&gt;I finally configured Kamal to work with Postgres. It took a few days of trial and error — until now I had only used SQLite, which is great for a tiny MVP, but not enough once things start growing... or this is what I am told myself for learn how to configure it :D&lt;/p&gt;

&lt;p&gt;Here’s the accessory config I’m using in deploy.yml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;accessories:
  postgres:
    image: postgres:15
    roles:
      - web
    env:
      clear:
        POSTGRES_USER: "postgres"
        POSTGRES_DB: retro_production
      secret:
        - POSTGRES_PASSWORD
        - POSTGRES_USER
    directories:
      - data:/var/lib/postgresql/data
    files:
      - config/init.sql:/docker-entrypoint-initdb.d/setup.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Useful commands:&lt;/p&gt;

&lt;p&gt;Boot Postgres&lt;br&gt;
&lt;code&gt;kamal accessory boot postgres&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Check if it’s running&lt;br&gt;
&lt;code&gt;kamal accessory details postgres&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Few post I used for learn this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://deploymentfromscratch.com/kamal/running-postgresql-on-kamal/" rel="noopener noreferrer"&gt;https://deploymentfromscratch.com/kamal/running-postgresql-on-kamal/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://rameerez.com/kamal-tutorial-how-to-deploy-a-postgresql-rails-app/" rel="noopener noreferrer"&gt;https://rameerez.com/kamal-tutorial-how-to-deploy-a-postgresql-rails-app/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>devjournal</category>
      <category>devops</category>
      <category>postgres</category>
    </item>
    <item>
      <title>A Small Lesson I Learned the Hard Way</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Mon, 02 Feb 2026 13:25:11 +0000</pubDate>
      <link>https://dev.to/linediconsine/a-small-lesson-i-learned-the-hard-way-g4l</link>
      <guid>https://dev.to/linediconsine/a-small-lesson-i-learned-the-hard-way-g4l</guid>
      <description>&lt;p&gt;A few years ago, I was juggling a big project at work, moving from Italy to the US, and rebuilding my life from scratch. In the middle of all that, something simple—but brutal—hit me: back pain.&lt;/p&gt;

&lt;p&gt;I kept working, of course, and I mentioned it to my team lead at the time, Ivan. Today I see him as a real mentor. He told me something I’ll never forget:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Spend as much on your chair as you spend on your computer. I learned it the hard way, just like you’re learning it now.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;He pointed me toward the well‑known brands—Steelcase, Herman Miller—and warned me not to trust cheap chairs to do the same job.&lt;/p&gt;

&lt;p&gt;I’ve always struggled with spending money on myself, so seeing chairs that cost thousands of dollars scared me. But after some research, I found companies that refurbish these high‑end models. They explained their process, the quality, and the savings. I took the leap.&lt;/p&gt;

&lt;p&gt;I paid less, got a great chair, and my back pain disappeared for years.&lt;br&gt;
Now that it’s creeping back, I’m reminded again how much our work depends on our bodies being able to support us.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The short version&lt;/strong&gt;&lt;br&gt;
If you’re early in your career, please take care of your body.&lt;br&gt;
You can study hard, code all day, push yourself—but you also need movement, rest, and a setup that doesn’t slowly break you.&lt;/p&gt;

&lt;p&gt;Your future self will thank you.&lt;/p&gt;

&lt;p&gt;I hope this small experience helps someone out there.&lt;/p&gt;

</description>
      <category>developer</category>
      <category>programming</category>
      <category>devlive</category>
      <category>buildinpublic</category>
    </item>
    <item>
      <title>Build in public day 1 - Dealing With “Magic” in Frameworks</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Thu, 22 Jan 2026 13:36:28 +0000</pubDate>
      <link>https://dev.to/linediconsine/build-in-public-day-1-dealing-with-magic-in-frameworks-3jli</link>
      <guid>https://dev.to/linediconsine/build-in-public-day-1-dealing-with-magic-in-frameworks-3jli</guid>
      <description>&lt;p&gt;I’m working on a small project right now. Nothing revolutionary, but it works, it’s fun, and it has some interesting features.&lt;/p&gt;

&lt;p&gt;Most of my career has been on the frontend, but I’ve also worked with Django, FastAPI, and sometimes Rails.&lt;/p&gt;

&lt;p&gt;Rails has a very particular approach based on “magic.”&lt;/p&gt;

&lt;p&gt;And I don’t mean “magic” only in a good way. I mean the kind of magic where things work… but you don’t fully understand why they work, because the framework hides a lot of complexity. This happens with many tools. jQuery was the first “don’t worry, I’ll handle it for you” library I used early in my career.&lt;/p&gt;

&lt;p&gt;Hiding complexity is great, but it also requires skepticism, testing, and validation—things you don’t need as much when you build everything from scratch.&lt;/p&gt;

&lt;p&gt;A Practical Example: Deploying With Kamal&lt;br&gt;
For deployment, I used Kamal. Kamal handles a lot for you: server setup, deploy configuration, even SSL certificates. It’s a sweet deal—but you need to learn Kamal and trust Kamal.&lt;/p&gt;

&lt;p&gt;Here’s a simple example of the configuration it requires:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;service: retro

# Name of the container image.
image: registryUser/retro # &amp;lt;-- your docker username/project name

servers:
  web:
    - 0.0.0.0 # &amp;lt;-- your server IP

proxy:
  ssl: true
  host: retro.ponopo.site

registry:
  server: localhost:5555
  username: myusername # &amp;lt;-- your docker username

env:
  secret:
    - RAILS_MASTER_KEY

volumes:
  - "db_storage:/root/storage"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just a few lines, and Kamal will SSH into your server and set everything up. Magic!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When the Magic Breaks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then I discovered a big bug in my production configuration.&lt;br&gt;
So I had to slowly “unpack” the magic and understand what was really happening.&lt;/p&gt;

&lt;p&gt;That led me to learn how to run Rails in production mode locally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are the commands I used:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create the production database&lt;br&gt;&lt;br&gt;
&lt;code&gt;RAILS_ENV=production rails db:create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run migrations&lt;br&gt;&lt;br&gt;
&lt;code&gt;RAILS_ENV=production rails db:migrate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Precompile assets&lt;br&gt;&lt;br&gt;
&lt;code&gt;RAILS_ENV=production rails assets:precompile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Start the server in production mode&lt;br&gt;&lt;br&gt;
&lt;code&gt;RAILS_ENV=production rails s&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Thanks and see y'all soon &lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>rails</category>
      <category>buildinpublic</category>
      <category>programming</category>
      <category>kamal</category>
    </item>
    <item>
      <title>Building in Public - Day 0</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Thu, 22 Jan 2026 13:18:01 +0000</pubDate>
      <link>https://dev.to/linediconsine/building-in-public-day-0-48d4</link>
      <guid>https://dev.to/linediconsine/building-in-public-day-0-48d4</guid>
      <description>&lt;p&gt;My brain freezes every time I think about publishing the first MVP.&lt;br&gt;
It’s definitely not ready. And after 14 years working on the web, it’s not easy to ship something incomplete, not polished, or somehow perfect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What perfect even means?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Perfection means something different to everyone : perfect CSS, perfect JavaScript, perfect load times, perfect interactions, perfect engagement.&lt;/p&gt;

&lt;p&gt;This project is none of that. It’s just the result of a few late‑night hours stolen from sleep.&lt;/p&gt;

&lt;p&gt;I’m terrified, but I want feedback. That’s what pushed me to write this post.&lt;/p&gt;

&lt;p&gt;I want someone to tell me what they think—even if it’s harsh. I need that input, and I’ll deal with it, even if it stings.&lt;/p&gt;

&lt;p&gt;I’ve worked hard to compress the complexity so this could be a one‑person project: backend, frontend, and now this post. I learned this idea from a talk about Ruby on Rails, and it stuck with me.&lt;br&gt;
I used Copilot like having a friend junior developer while I am reviewing every line before committing it to the repo.&lt;/p&gt;

&lt;p&gt;They’re my commits because I believe &lt;strong&gt;I’m responsible for every line.&lt;/strong&gt; I can’t blame AI for a bug—if it’s there, it’s because I didn’t check carefully enough.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So here’s where I am now:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I built the first MVP of my project.&lt;br&gt;
Now I need the courage to deploy it and ask a few friends for feedback. This step turned out to be harder than I expected, but I’m hoping this post gives me the push I need to move forward.&lt;/p&gt;

</description>
      <category>buildinpublic</category>
      <category>rails</category>
      <category>programming</category>
    </item>
    <item>
      <title>Notes on Rails</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Fri, 10 Oct 2025 20:53:24 +0000</pubDate>
      <link>https://dev.to/linediconsine/notes-on-rails-2j09</link>
      <guid>https://dev.to/linediconsine/notes-on-rails-2j09</guid>
      <description>&lt;p&gt;I solved few errors and I want here to provide how&lt;/p&gt;

&lt;h2&gt;
  
  
  esbuild and sass missing
&lt;/h2&gt;

&lt;p&gt;Running &lt;code&gt;bin/rails test:system&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The error message contains&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh: esbuild: command not found
bin/rails aborted!
jsbundling-rails: Command build failed, ensure `npm run build` runs without errors
sh: esbuild: command not found
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As suggested &lt;code&gt;npm run build&lt;/code&gt; is a good start&lt;br&gt;
and it show this error message&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh: esbuild: command not found
bin/rails aborted!
jsbundling-rails: Command build failed, ensure `npm run build` runs without errors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the solution is install &lt;code&gt;esbuild&lt;/code&gt;, I also suggesto to install &lt;code&gt;sass&lt;/code&gt; if you are not sure&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save-exact --save-dev esbuild sass&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Running &lt;code&gt;npm run build:css&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I see this error:&lt;br&gt;
&lt;code&gt;sh: sass: command not found&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;the solution is install &lt;code&gt;sass&lt;/code&gt;, I also suggesto to install &lt;code&gt;esbuild&lt;/code&gt; if you are not sure&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save-exact --save-dev esbuild sass&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;now &lt;code&gt;npm run build:css&lt;/code&gt; and &lt;code&gt;npm run build&lt;/code&gt; works and I can finally run my tests&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Running:

Capybara starting Puma...
* Version 7.0.4, codename: Romantic Warrior
* Min threads: 0, max threads: 4
* Listening on http://127.0.0.1:63406
....

Finished in 2.813492s, 1.4217 runs/s, 3.9097 assertions/s.
4 runs, 11 assertions, 0 failures, 0 errors, 0 skips
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>rails</category>
    </item>
    <item>
      <title>Browsers</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Mon, 19 May 2025 15:39:25 +0000</pubDate>
      <link>https://dev.to/linediconsine/browsers-31og</link>
      <guid>https://dev.to/linediconsine/browsers-31og</guid>
      <description>&lt;p&gt;&lt;strong&gt;What's a web browser?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;... serioulsy what's a browser?&lt;/p&gt;

&lt;p&gt;I would define a browser as an ecosystem of multiple interpreters with the goal o presenting a web page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An interpreter?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, like Python, Lua ... Uh no... sorry not like that... since the those interpreters are not afraid to show that you made a error while a browsers hide your errors&lt;/p&gt;

&lt;p&gt;A good browser is a browser who can work with partial, missing, buggy infomations&lt;/p&gt;

&lt;p&gt;Here is a simple example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;HTML&amp;gt;
    &amp;lt;HEAD&amp;gt;
    &amp;lt;BODY&amp;gt;
&amp;lt;h1&amp;gt;hi All
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code not only works without errors but also get fixed in realtime in this, without any alert of error :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;
    &amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;
        &amp;lt;h1&amp;gt;hi all&amp;lt;/h1&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A browser is a ecosystem of interpreters who call is to show a web page whatever is buggy, full of problem ... the browser will show something if he can ... it will triggers an error as last last last thing before trying anything to fix it.&lt;/p&gt;

&lt;p&gt;Let me add here an other point... the browsers are multiple each one with different interpreters for the same language. Nowadays most of the browsers are based on Webkit but still not all browswer and they do still have custome codes.&lt;/p&gt;

&lt;p&gt;Each browser may have some differences from on to another&lt;/p&gt;

&lt;p&gt;That's ok... we can still make great apps if we know what we are facing.&lt;/p&gt;

&lt;p&gt;This is a series of post that I decided to do about web and technology... I hope you enjoy it&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Exploring the Instructor Library: Structuring Unstructured Data (and Some Fun along the Way)</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Sat, 16 Nov 2024 14:40:45 +0000</pubDate>
      <link>https://dev.to/linediconsine/exploring-the-instructor-library-structuring-unstructured-data-and-some-fun-along-the-way-30el</link>
      <guid>https://dev.to/linediconsine/exploring-the-instructor-library-structuring-unstructured-data-and-some-fun-along-the-way-30el</guid>
      <description>&lt;p&gt;I’ve recently come across the &lt;a href="https://github.com/instructor-ai/instructor" rel="noopener noreferrer"&gt;instructor&lt;/a&gt;  library, and I have to say, I’m pretty impressed. The concept of structuring unstructured data is both powerful and, dare I say, a bit magical. The idea that you can take data that’s all over the place and somehow impose order on it—well, that’s just my kind of wizardry.&lt;/p&gt;

&lt;p&gt;But… how exactly does it work?&lt;/p&gt;

&lt;p&gt;To find out, I spent some time digging into the internals of this library, and I discovered that there are two key players behind the scenes that are responsible for much of its magic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Meet the Players: Pydantic and a nice prompt
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;instructor&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BaseModel&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you're familiar with Python's data validation and settings management, you’ve probably heard of Pydantic. And if you haven't... well, buckle up! It’s an amazing library that allows you to define data structures and then validate that incoming data matches those structures—in real time. Think of it as the bouncer at a fancy club, making sure that only the right data gets in.&lt;/p&gt;

&lt;p&gt;FastAPI, which is another great tool, makes excellent use of Pydantic to ensure that data passing through an API is in the right format. So, what's the next step? Now that we’ve defined our structure, how do we get an LLM (like OpenAI’s GPT) to follow it? Hmm…&lt;/p&gt;

&lt;h2&gt;
  
  
  Hypothesis 1: Pydantic's Serialization
&lt;/h2&gt;

&lt;p&gt;My first hypothesis was that Pydantic might allow some kind of serialization—converting the data structure into something an LLM can easily understand and work with. And, it turns out, I wasn’t wrong.&lt;/p&gt;

&lt;p&gt;Pydantic allows you to serialize your data into a dictionary with the following method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model_dump&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;  &lt;span class="c1"&gt;# Dumps the model into a dictionary
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method recursively converts your Pydantic models into dictionaries, which can then be fed into an LLM for processing. So far, so good. But then I stumbled across something even more interesting:&lt;/p&gt;

&lt;h2&gt;
  
  
  Hypothesis 2: Generating a JSON Schema
&lt;/h2&gt;

&lt;p&gt;It gets better. Pydantic doesn’t just convert data into dictionaries—it can also generate a JSON schema for your model. This is key, because now you have a blueprint of the structure you want the LLM to follow.&lt;/p&gt;

&lt;p&gt;Here’s where things really started to click:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Generate a JSON schema for a Pydantic model
&lt;/span&gt;&lt;span class="n"&gt;response_model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model_json_schema&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bingo! Now you’ve got a clear schema that defines exactly how the data should look. This is the blueprint we can send to the LLM, so it knows exactly how to structure its output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bringing It All Together
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dedent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Understand the content and provide
    the parsed objects in json that match the following json_schema:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;

    &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response_model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model_json_schema&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ensure_ascii&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;

    Make sure to return an instance of the JSON, not the schema itself
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the library is passing the schema to the LLM, asking it to return data that conforms to that structure. The message is clear: "Hey LLM, respect this schema when you generate your output." It’s like giving your LLM a detailed map and saying, “Follow these directions exactly.”&lt;/p&gt;

&lt;h2&gt;
  
  
  Thanks for bear with me
&lt;/h2&gt;

&lt;p&gt;So, after all this investigation, I’m now convinced: Pydantic’s serialization and JSON schema generation are what make it possible for the Instructor library to get an LLM to follow structured data formats.&lt;/p&gt;

&lt;p&gt;Thanks for sticking with me through this fun (and slightly convoluted) investigation. Who knew that unstructured data could be tamed with a little help from Python libraries and a bit of creative prompting?&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>architecture</category>
      <category>promptengineering</category>
    </item>
    <item>
      <title>Quick and Dirty Guide to Running a Local LLM and Making API Requests</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Sat, 16 Nov 2024 14:21:59 +0000</pubDate>
      <link>https://dev.to/linediconsine/quick-and-dirty-guide-to-running-a-local-llm-and-making-api-requests-4f6h</link>
      <guid>https://dev.to/linediconsine/quick-and-dirty-guide-to-running-a-local-llm-and-making-api-requests-4f6h</guid>
      <description>&lt;p&gt;Alright, buckle up because we’re diving into a quick and dirty solution for running a local LLM (Language Model) and making API requests — much like what the fancy commercial solutions do. Why? Well, why not? In just about three minutes, you can have a perfectly decent system running locally for most of your tests. And if you ever feel the need to scale up to the cloud again, switching back is practically effortless.&lt;/p&gt;

&lt;p&gt;Here’s the documentation we’ll be following, mostly so you can claim you’ve read it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://platform.openai.com/docs/api-reference/making-requests" rel="noopener noreferrer"&gt;OpenAI API docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In particular, we’ll focus on making a request like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.openai.com/v1/chat/completions &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer &lt;/span&gt;&lt;span class="nv"&gt;$OPENAI_API_KEY&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{
     "model": "gpt-4o-mini",
     "messages": [{"role": "user", "content": "Say this is a test!"}],
     "temperature": 0.7
   }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far, so good, right? Nothing groundbreaking. But here’s where it gets fun…&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter LM Studio
&lt;/h2&gt;

&lt;p&gt;There's this gem of a tool called &lt;a href="https://lmstudio.ai/" rel="noopener noreferrer"&gt;LM Studio&lt;/a&gt;, which makes local LLMs much easier to handle. After installing and running your model, you’ll notice a tab with a console icon called Developer. I know, it doesn’t sound too exciting at first, but hold on, because it gets better. This tab comes with a handy CURL example that shows you exactly how to use your local model. And, wouldn't you know it, it looks pretty familiar!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:1234/v1/chat/completions &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{
    "model": "llama-3.1-8b-lexi-uncensored-v2",
    "messages": [
      { "role": "system", "content": "Always answer in rhymes. Today is Thursday" },
      { "role": "user", "content": "What day is it today?" }
    ],
    "temperature": 0.7,
    "max_tokens": -1,
    "stream": false
}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks pretty familiar, right? This is the local version of what we just saw. You get the same setup as the OpenAI API request, except it’s running on your local machine. Plus, it's got a little flair — like the "Always answer in rhymes" system prompt. Poetry, anyone?&lt;/p&gt;

&lt;h2&gt;
  
  
  What About Python? We Got You.
&lt;/h2&gt;

&lt;p&gt;If you prefer working with Python (and let’s be real, who doesn’t?), here’s how you’d send the same request using Python’s requests module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;http://localhost:1234/v1/chat/completions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Content-Type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;model&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;llama-3.1-8b-lexi-uncensored-v2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;messages&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;system&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You are a helpful assistant.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is the capital of France?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;temperature&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;max_tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stream&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;choices&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;message&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And voilà! You’re now ready to send requests to your local LLM just like you would with a commercial API. Go ahead, test it, break it, make it rhyme — the world (or at least your model) is your oyster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enjoy!
&lt;/h2&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>python</category>
      <category>localmodel</category>
    </item>
    <item>
      <title>How-to: Use dictionary in TypeScript</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Wed, 05 Jun 2024 20:42:11 +0000</pubDate>
      <link>https://dev.to/linediconsine/a-dictionary-in-typescript-31ek</link>
      <guid>https://dev.to/linediconsine/a-dictionary-in-typescript-31ek</guid>
      <description>&lt;p&gt;Here is the scenario, I want to create a function &lt;code&gt;getLegsNumber&lt;/code&gt; that use this structure as dictionary&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mappingAnimalLegs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;CAT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DOG&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DUCK&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If I write something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getLegsNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;animal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;mappingAnimalLegs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;animal&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Typescript is not happy and tell us:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ CAT: number; DOG: number; DUCK: number; }'.(7053)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So... how I can solve this without adding too much noise ?&lt;/p&gt;

&lt;p&gt;Here is my solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getLegsNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;animal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;animal&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;mappingAnimalLegs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;mappingAnimalLegs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;animal&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;keyof&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;mappingAnimalLegs&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I can also simplify a bit more with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getLegsNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;animal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;mappingAnimalLegs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;animal&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;keyof&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;mappingAnimalLegs&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you think?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAtgQwA5IJZgOYEEysQGwBkBTDCGAXhgG8AoGBmAcgGEsAVJmALhgBYANPUZMAIgHkA4l16DhDMQFUWAaRkwATLQC+tWgDMArmGBRU4GBmJQSZAHII4AI2IAnABQJcBXtFfoMAEpeMENnNxp5GFdrQ1cweGQ0TBw8BCJSCABtLzT8GARyAGtiAE8QfRgoUqRiCsSUANSCWwgAXRgAHxgABh0gA" rel="noopener noreferrer"&gt;Typescript playground as reference&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>[WIP] Test UI?</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Wed, 05 Jun 2024 20:31:14 +0000</pubDate>
      <link>https://dev.to/linediconsine/wip-test-ui-dl4</link>
      <guid>https://dev.to/linediconsine/wip-test-ui-dl4</guid>
      <description>&lt;p&gt;There are different solutions on test UI &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Jest unit testing&lt;/li&gt;
&lt;li&gt;Jest Snapshots&lt;/li&gt;
&lt;li&gt;Integration testing&lt;/li&gt;
&lt;li&gt;Image comparison testing&lt;/li&gt;
&lt;li&gt;Accessibility reports&lt;/li&gt;
&lt;li&gt;Manual testing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When to us what? In my experience a big project will end up using all of them.&lt;/p&gt;

&lt;p&gt;Let start with the first &lt;/p&gt;

&lt;h2&gt;
  
  
  Jest unit testing
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Unit testing is a type of software testing that focuses on individual units or components of a software system.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nice... but let also mention that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;we want to test behavior and not implementation&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The goal is I can change 100% the implementation and the test will still pass&lt;/p&gt;

&lt;p&gt;How? the style is called "Black box testing" and it focus on behavior not on testing each function input output&lt;/p&gt;

&lt;h2&gt;
  
  
  Jest Snapshots
&lt;/h2&gt;

&lt;p&gt;As the official docs tell &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The idea is, I take a copy of the rendered component ( only the generated HTML) in a scenario X and I will compare each time I run the test. If it's different... Well, we know something has changed&lt;/p&gt;

&lt;p&gt;... to be continued&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Test if a promise throw an Error</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Wed, 05 Jun 2024 20:19:36 +0000</pubDate>
      <link>https://dev.to/linediconsine/test-if-a-promise-throw-an-error-3116</link>
      <guid>https://dev.to/linediconsine/test-if-a-promise-throw-an-error-3116</guid>
      <description>&lt;p&gt;Hi, few weeks ago I had to solve this problem,&lt;/p&gt;

&lt;p&gt;If the API return 404 I want my code to Throw and error, in general fetch will not throw an error on API failure with exception of a time out so I had to force that behavior:&lt;/p&gt;

&lt;p&gt;Here is my base code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Error on details API &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok... here the solution I end up with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;rejects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toThrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error on details API 404&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can be improved but I thought sharing the solution may help somebody else&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>jest</category>
    </item>
    <item>
      <title>How to determine which Python version your Jupyter notebook is using</title>
      <dc:creator>Marco</dc:creator>
      <pubDate>Fri, 09 Jun 2023 16:42:24 +0000</pubDate>
      <link>https://dev.to/linediconsine/how-to-determine-which-python-version-your-jupyter-notebook-is-using-3hnl</link>
      <guid>https://dev.to/linediconsine/how-to-determine-which-python-version-your-jupyter-notebook-is-using-3hnl</guid>
      <description>&lt;p&gt;Have you ever spent an incredible amount of time trying to understand which version of Python your Jupyter Notebook is using, or how to install a library on it? The solution is actually quite simple.&lt;/p&gt;

&lt;p&gt;All you need to do is run the following code block in your Jupyter Notebook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import sys
print(sys.executable)
print(sys.version)
print(sys.version_info)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will return information about the version of Python being used, as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/usr/local/opt/python@3.9/bin/python3.9
3.9.16 (main, Dec  7 2022, 10:15:43) 
[Clang 14.0.0 (clang-1400.0.29.202)]
sys.version_info(major=3, minor=9, micro=16, releaselevel='final', serial=0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ah!! Now everything is clear! You can also find pip3.9 in the &lt;code&gt;/usr/local/opt/python@3.9/bin/&lt;/code&gt; directory, and there is also &lt;code&gt;pip3.9&lt;/code&gt; that you can use to install library like :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/usr/local/opt/python@3.9/bin/pip3.9 install dotenv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Stay tuned for future improvements and next episodes on how to use an environment in Jupyter Notebook&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
