<?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: dan</title>
    <description>The latest articles on DEV Community by dan (@dcs-ink).</description>
    <link>https://dev.to/dcs-ink</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%2F1271253%2F17530f3d-41f3-49e1-8182-163daf89e511.jpg</url>
      <title>DEV Community: dan</title>
      <link>https://dev.to/dcs-ink</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dcs-ink"/>
    <language>en</language>
    <item>
      <title>Creating In PatchWorld XR</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Sun, 30 Mar 2025 23:52:19 +0000</pubDate>
      <link>https://dev.to/dcs-ink/creating-in-patchworld-xr-1c91</link>
      <guid>https://dev.to/dcs-ink/creating-in-patchworld-xr-1c91</guid>
      <description>&lt;p&gt;I love music. If you're into VR, &lt;a href="https://patchxr.com/" rel="noopener noreferrer"&gt;PatchWorld XR&lt;/a&gt; is an amazing app that gives you complete creative freedom both musically and visually. &lt;/p&gt;

&lt;p&gt;Gemini 2.5 Pro sums it up pretty good.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PatchWorld XR provides an immersive virtual reality platform where users build interactive musical worlds using a visual, block-based system. This method directly introduces fundamental coding concepts, as users learn to connect blocks logically to create sequences, trigger actions, and manage parameters – much like visual programming. Simultaneously, by assembling blocks that generate sounds, control rhythms, and shape melodies, users intuitively explore and grasp core music fundamentals. This hands-on, playful approach makes learning the foundational principles of both coding and music creation engaging and accessible.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's a neat minecraft(ish) tool I've been working on.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://player.vimeo.com/video/1070877934" width="710" height="399"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I'm still working on the grid and how to enable it for only the blocks. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create a Simple API with Python and Flask</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Sun, 30 Mar 2025 23:16:16 +0000</pubDate>
      <link>https://dev.to/dcs-ink/create-a-simple-api-with-python-and-flask-2b80</link>
      <guid>https://dev.to/dcs-ink/create-a-simple-api-with-python-and-flask-2b80</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/dcs-ink/simple-api-python-flask" rel="noopener noreferrer"&gt;https://github.com/dcs-ink/simple-api-python-flask&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I recently &lt;a href="https://requests.hrtechprivacy.com/create?entity=INDEED" rel="noopener noreferrer"&gt;requested&lt;/a&gt; my data from Indeed because I was curious about the statistics with my recent job search.&lt;/p&gt;

&lt;p&gt;I've worked plenty with APIs, but never built one from scratch. I decided to create a simple one using Python and Flask. &lt;/p&gt;

&lt;p&gt;It's simple really, only consists of two files - the python script and the json file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;jobs.json&lt;/code&gt;&lt;br&gt;
&lt;code&gt;job_api.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here's a snippet example of the json file I received from Indeed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
    {
      "title" : "Job Title",
      "company" : "CoolCompany",
      "location" : "Cool City, COOL",
      "date" : "date timestamp"
    }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mine had something like 300 entries, but the point remains the same.&lt;/p&gt;

&lt;p&gt;Here's the python script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import json
from flask import Flask, jsonify

app = Flask(__name__)

jobs_data = []
try:
    with open('jobs.json', 'r') as f:
        jobs_data = json.load(f)
    print(f"Successfully loaded {len(jobs_data)} jobs from jobs.json")
except FileNotFoundError:
    print("Error: jobs.json not found!")
except json.JSONDecodeError:
    print("Error: jobs.json is not valid JSON!")

@app.route('/api/jobs', methods=['GET'])
def get_all_jobs():
    return jsonify(jobs_data)

@app.route('/api/jobs/titles', methods=['GET'])
def get_job_titles():
    titles = [job['title'] for job in jobs_data]
    return jsonify(titles)

@app.route('/api/jobs/companies', methods=['GET'])
def get_job_companies():
    if not jobs_data:
        return jsonify({"error": "No job data available"}), 500
    companies = list(set(job.get('company', 'N/A') for job in jobs_data))
    return jsonify(companies)

@app.route('/api/jobs/location', methods=['GET'])
def get_job_locations():
    if not jobs_data:
        return jsonify({"error": "No job data available"}), 500
    locations = list(set(job.get('location') for job in jobs_data))
    return jsonify(locations)

if __name__ == '__main__':
    app.run(debug=True, port=8080)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Steps to make it work.&lt;br&gt;
After setup and activating a virtual environment...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;pip install flask&lt;/li&gt;
&lt;li&gt;pip install jsonify&lt;/li&gt;
&lt;li&gt;Create python file and paste above python code&lt;/li&gt;
&lt;li&gt;Create json file and paste above json code&lt;/li&gt;
&lt;li&gt;Run python script
&lt;code&gt;sudo python3 job_api.py&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use curl to test
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl http://127.0.0.1:8080/api/jobs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Response&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
    {
        "company": "CoolCompany",
        "date": "date timestamp",
        "location": "Cool City, COOL",
        "title": "Job Title"
    }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>api</category>
      <category>python</category>
      <category>flask</category>
      <category>json</category>
    </item>
    <item>
      <title>Control a servo connected to a Raspberry Pi using an Xbox controller</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Mon, 22 Jul 2024 03:52:28 +0000</pubDate>
      <link>https://dev.to/dcs-ink/control-a-servo-connected-to-a-raspberry-pi-using-an-xbox-controller-230a</link>
      <guid>https://dev.to/dcs-ink/control-a-servo-connected-to-a-raspberry-pi-using-an-xbox-controller-230a</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/dcs-ink/raspberry_servo_controller" rel="noopener noreferrer"&gt;https://github.com/dcs-ink/raspberry_servo_controller&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  raspberry_servo_controller
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrzmovvshd94ld9edxke.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrzmovvshd94ld9edxke.gif" alt="output4" width="500" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Control a servo connected to a Raspberry Pi using an Xbox controller. Easy setup for testing.
&lt;/h2&gt;

&lt;p&gt;Parts list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;raspberry pi 4&lt;/li&gt;
&lt;li&gt;xbox controller&lt;/li&gt;
&lt;li&gt;power bank&lt;/li&gt;
&lt;li&gt;breadboard&lt;/li&gt;
&lt;li&gt;100 µF capacitor&lt;/li&gt;
&lt;li&gt;servo&lt;/li&gt;
&lt;li&gt;jumper wires&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Diagram
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5calhmasicb5jiup2p15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5calhmasicb5jiup2p15.png" alt="wire_diagram" width="800" height="632"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Prep Raspberry Pi (I used Raspberry OS Lite but I imagine most OS's should work)&lt;/li&gt;
&lt;li&gt;Install dependancies
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo apt-get install -y evtest evdev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Pair controller
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   bluetoothctl
   scan on
   pair XX:XX:XX:XX:XX:XX
   trust XX:XX:XX:XX:XX:XX
   connect XX:XX:XX:XX:XX:XX
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make note of the ID; eventX&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Look at controller output
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo evtest /dev/input/eventX
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create python script
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   vim ServoController.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;copy paste (be sure to change 'eventX' to your controller id&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import evdev
   import RPi.GPIO as GPIO
   import time

   GPIO.setmode(GPIO.BOARD)
   GPIO.setup(11,GPIO.OUT)
   servo = GPIO.PWM(11,50)
   servo.start(0)

   controllerInput = evdev.InputDevice("/dev/input/event0")

    for event in controllerInput.read_loop():
      if event.type == evdev.ecodes.EV_ABS:
        if event.code == evdev.ecodes.ABS_X:
          angle = 2 + (event.value / 6553.5)
          servo.ChangeDutyCycle(angle)
          print(angle)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Run script
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   python3 ServoController.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks to &lt;a href="https://github.com/Berardinux" rel="noopener noreferrer"&gt;Berardinux&lt;/a&gt; for the code and guide! &lt;a href="https://github.com/Berardinux/XboxController_Servo_RaspberryPi" rel="noopener noreferrer"&gt;XboxController_Servo_RaspberryPi&lt;/a&gt; &lt;br&gt;
&lt;a href="https://youtu.be/3Z6Bf0uV7tc?si=rzX2nBYM4o1anVEc" rel="noopener noreferrer"&gt;https://youtu.be/3Z6Bf0uV7tc?si=rzX2nBYM4o1anVEc&lt;/a&gt;&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>controller</category>
      <category>servo</category>
      <category>robotics</category>
    </item>
    <item>
      <title>Installing with PNPM is 56% faster than NPM</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Mon, 03 Jun 2024 17:23:13 +0000</pubDate>
      <link>https://dev.to/dcs-ink/installing-with-pnpm-is-56-faster-than-npm-1phc</link>
      <guid>https://dev.to/dcs-ink/installing-with-pnpm-is-56-faster-than-npm-1phc</guid>
      <description>&lt;p&gt;I'm surprised I don't see recommendations to use PNPM over NPM more often. Over the past couple of months, I've been reading guides and tutorials daily, and I've only seen it recommended in one project, &lt;a href="https://github.com/gethomepage/homepage#:~:text=Then%20install%20dependencies%20and%20build%20the%20production%20bundle%20(I%27m%20using%20pnpm%20here%2C%20you%20can%20use%20npm%20or%20yarn%20if%20you%20like)%3A" rel="noopener noreferrer"&gt;homepage&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Since I started using PNPM while learning React, I've noticed a significant speed increase. PNPM conducts a daily benchmark comparing its performance to NPM. You can check it out here: &lt;a href="https://pnpm.io/benchmarks" rel="noopener noreferrer"&gt;PNPM Benchmarks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Have a great day!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React Styling: Navigating CSS Specificity and Precedence</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Sat, 18 May 2024 21:28:59 +0000</pubDate>
      <link>https://dev.to/dcs-ink/react-styling-navigating-css-specificity-and-precedence-50oe</link>
      <guid>https://dev.to/dcs-ink/react-styling-navigating-css-specificity-and-precedence-50oe</guid>
      <description>&lt;p&gt;In trying to figure out why an image wasn't centering where I thought it should be I built a little flowchart that shows the styling precedence for a typical React webapp. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frb3w3zh6uf3ks9v8j5wo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frb3w3zh6uf3ks9v8j5wo.png" alt="Flowchart" width="800" height="896"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Open Interpreter Quick Setup Guide</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Sat, 18 May 2024 21:17:47 +0000</pubDate>
      <link>https://dev.to/dcs-ink/open-interpreter-quick-setup-guide-1jgh</link>
      <guid>https://dev.to/dcs-ink/open-interpreter-quick-setup-guide-1jgh</guid>
      <description>&lt;p&gt;I've been using Open Interpreter quite a bit in building a React website. If you haven't heard of it, Open Interpreter lets LLMs run code on your computer to complete tasks. This has a major advantage over the average AI web interface in that it can see entire directories rather than being limited to a code snippet or single page. I admit it has been a while since I used Copilot, so I'm not sure if it has that capability yet. However, Open Interpreter also has the ability to run apps and take over your screen/keyboard, among some other really cool things.&lt;/p&gt;

&lt;p&gt;I'm using WSL and it works great. Here's a quick setup guide:&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a virtual environment
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Activate it
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source &lt;/span&gt;venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install Open Interpreter
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;open-interpreter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Start the interpreter
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;interpreter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some additional notes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You will need an OpenAI API key, so head over to their site if you don't have one yet.&lt;/li&gt;
&lt;li&gt;There are many flags and custom prompts that can be used; head over to the official documentation for further use: &lt;a href="https://docs.openinterpreter.com/getting-started/introduction" rel="noopener noreferrer"&gt;Open Interpreter Documentation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;In WSL, conversations are saved in &lt;code&gt;/home/user/.config/open-interpreter/conversations&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The list of supported models can be found here: &lt;a href="https://docs.openinterpreter.com/language-models/hosted-models" rel="noopener noreferrer"&gt;Supported Models&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I've been really impressed with GPT-4O, but I'd love to hear about others' experiences.&lt;/p&gt;

</description>
      <category>openinterpreter</category>
      <category>01</category>
      <category>ai</category>
    </item>
    <item>
      <title>Simplifying Imports in React with Base URL Configuration</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Sun, 12 May 2024 23:52:05 +0000</pubDate>
      <link>https://dev.to/dcs-ink/simplifying-imports-in-react-with-base-url-configuration-32cd</link>
      <guid>https://dev.to/dcs-ink/simplifying-imports-in-react-with-base-url-configuration-32cd</guid>
      <description>&lt;p&gt;Managing imports in a React project can get tricky, especially as your application scales and directories get deeper. Struggling with this myself, I asked chatGPT for some advise and discovered base URLs. &lt;/p&gt;

&lt;p&gt;Using a base URL allows you to use absolute paths instead of relative ones, making your code cleaner and easier to maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use a Base URL?
&lt;/h2&gt;

&lt;p&gt;Using complex relative paths like &lt;strong&gt;&lt;code&gt;../../../../components/MyComponent&lt;/code&gt;&lt;/strong&gt; is error-prone and hard to maintain. With a base URL, you can import components using straightforward paths:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import MyComponent from 'components/MyComponent';

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to Set Up a Base URL
&lt;/h2&gt;

&lt;p&gt;You can configure a base URL in your React project by editing the &lt;strong&gt;jsconfig.json&lt;/strong&gt;. (Sidenote: when using 'create-react-app' the file is not automatically created so you will need to create one at the base of your project.) &lt;/p&gt;

&lt;p&gt;Here's a simple config for &lt;strong&gt;jsconfig.json&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": ["src/**/*"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration tells your compiler that any imports should be resolved starting from the src directory, simplifying your import statements across the project.&lt;/p&gt;

&lt;p&gt;Hope this helps, have a great day!&lt;/p&gt;

</description>
      <category>react</category>
      <category>baseurl</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Next.js: App Router vs Pages Router</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Tue, 05 Mar 2024 11:32:44 +0000</pubDate>
      <link>https://dev.to/dcs-ink/nextjs-app-router-vs-pages-router-3p57</link>
      <guid>https://dev.to/dcs-ink/nextjs-app-router-vs-pages-router-3p57</guid>
      <description>&lt;p&gt;Let's talk about setting up a Next.js project, focusing on choosing between the App Router and the Pages Router. As I've been delving into React, I initially got to know the 'create-react-app' command, which made the setup process and understanding the basic file structure extremely easy. However, upon discovering that 'create-react-app' is no longer recommended, I was led to Next.js. &lt;/p&gt;

&lt;p&gt;Transitioning to Next.js has proven to be a steeper learning curve, highlighting the complexity of its setup compared to 'create-react-app'. Here's a lit of the questions you are asked when running 'create-next-app'.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app@latest mysite
✔ Would you like to use TypeScript? … No / Yes
✔ Would you like to use ESLint? … No / Yes
✔ Would you like to use Tailwind CSS? … No / Yes
✔ Would you like to use `src/` directory? … No / Yes
? Would you like to use App Router? (recommended) › No / Yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you're new to Next.js, deciding between using the Pages Router and the App Router can be confusing, and understanding how each affects your project's file structure isn't immediately clear.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pages Router
&lt;/h3&gt;

&lt;p&gt;Initially encountering Next.js, the Pages Router seems like a straightforward choice. It operates on a simple principle: the pages directory. You create a file within this directory, and just like that, you've created a new webpage (or route) for your site. This process is very beginner-friendly, relying on conventions that directly link the file structure to your website's URL paths. For example, if you want to add a /contact page to your site, you would simply create a contact.js file in the pages directory. However, as a beginner, it might not be immediately obvious how this choice between routers affects the organization and scalability of your project in the long run.&lt;/p&gt;

&lt;p&gt;Here is the pages router structure (no src directory)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pages/
├── _app.js
├── _document.js
└── index.js
Styles/
├── global.css
├── Home.module.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  App Router
&lt;/h3&gt;

&lt;p&gt;The App Router, introduced in later versions of Next.js, provides a more explicit approach to routing. Unlike the Pages Router, where routes are implicitly created based on file names in the pages directory, the App Router requires you to define your routes using a JavaScript API within an app directory. This method grants more control and flexibility, particularly for projects with complex routing needs or dynamic content. For beginners, the App Router introduces a level of complexity and requires a deeper understanding of Next.js concepts right from the start. It's a hands-on approach that might not be clear at first, especially when trying to grasp how it differs from the simplicity of the Pages Router and how it influences the structure and development of your application.&lt;/p&gt;

&lt;p&gt;Here is the app router structure (no src directory)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/
├── favicon.ico
├── global.css
├── layout.js
├── page.js
└── page.module.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key Differences for Beginners
&lt;/h3&gt;

&lt;p&gt;Simplicity vs. Control: Pages Router wins if you're after simplicity. It's great for static sites or apps with straightforward routing needs. App Router, however, gives you more control and is better suited for complex routing scenarios.&lt;/p&gt;

&lt;p&gt;Convention vs. Configuration: With Pages Router, you follow a convention (file names and structures). App Router is more about configuration, where you define routes through code.&lt;/p&gt;

&lt;p&gt;Dynamic Routing: Both routers support dynamic routes, but App Router provides a more explicit approach, which might be easier to manage and understand for complex cases.&lt;/p&gt;

&lt;p&gt;Learning Curve: Pages Router is generally easier for beginners to grasp. App Router introduces concepts that might be more familiar to those with experience in other JavaScript frameworks or more complex routing needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Which One Should You Choose?
&lt;/h3&gt;

&lt;p&gt;If you're just starting out, dipping your toes with the Pages Router might be the way to go. It's less to manage upfront, and you can get a site up and running quickly. As you grow more comfortable with Next.js or if your project's routing needs become more sophisticated, considering the App Router could be a game-changer, offering you the flexibility and power to manage more complex routing patterns.&lt;/p&gt;

&lt;p&gt;For more details be sure to check out the official documentation. &lt;a href="https://nextjs.org/docs/getting-started/project-structure" rel="noopener noreferrer"&gt;Next.js Project Structure&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Set Up the OpenAI API with Python and Flask</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Wed, 28 Feb 2024 18:50:01 +0000</pubDate>
      <link>https://dev.to/dcs-ink/how-to-set-up-the-openai-api-with-python-and-flask-2120</link>
      <guid>https://dev.to/dcs-ink/how-to-set-up-the-openai-api-with-python-and-flask-2120</guid>
      <description>&lt;p&gt;I found it intriguing to develop a user-friendly front end for OpenAI's API to enhance customization. This project marks the initial stages of that project. &lt;/p&gt;

&lt;p&gt;The primary focus was on establishing a strong foundation, given my intent to integrate this tool into my daily routine. By following this guide, you can create a simple web interface for interacting with OpenAI's chatGPT. As a learner myself, I understand some of the challenges in finding guides, so I tailored this content with beginners in mind but also short and to the point.&lt;/p&gt;

&lt;p&gt;Moving forward, my goal is to expand this project by adding features like a chat history and individual user accounts. This serves as the first installment of the project.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Set Up the OpenAI API with Python and Flask
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Create your project folder.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir homeGPT
cd homeGPT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create your virtual environment
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 -m venv homeGPT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Activate the virtual environment
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source homeGPT/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Install &lt;a href="https://pypi.org/project/Flask/" rel="noopener noreferrer"&gt;flask&lt;/a&gt;, &lt;a href="https://pypi.org/project/requests/" rel="noopener noreferrer"&gt;requests&lt;/a&gt;, &lt;a href="https://pypi.org/project/python-dotenv/" rel="noopener noreferrer"&gt;python-dotenv&lt;/a&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install flask requests python-dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create file &lt;em&gt;app.py&lt;/em&gt;. I use vim.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add this code to &lt;em&gt;app.py&lt;/em&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template, request
import os
from openai import OpenAI
from dotenv import load_dotenv

load_dotenv()  # Load environment variables from .env
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
client = OpenAI(api_key=OPENAI_API_KEY)

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        prompt = request.form['prompt']
        response = client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
                {"role": "user", "content": prompt}
            ]
        )
        return render_template('home.html', prompt=prompt, response=response.choices[0].message.content)
    else:
        return render_template('home.html')

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create a templates folder
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir templates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create a file &lt;em&gt;home.html&lt;/em&gt; within templates
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim home.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add this code to &lt;em&gt;home.html&lt;/em&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;HomeGPT&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="container mt-5"&amp;gt;
        &amp;lt;h1&amp;gt;HomeGPT&amp;lt;/h1&amp;gt;
        &amp;lt;form method="POST"&amp;gt;
            &amp;lt;div class="form-group"&amp;gt;
                &amp;lt;input type="text" name="prompt" class="form-control" placeholder="Enter your prompt"&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;button type="submit" class="btn btn-primary"&amp;gt;Submit&amp;lt;/button&amp;gt;
        &amp;lt;/form&amp;gt;

        {% if response %}
            &amp;lt;div class="mt-3"&amp;gt;
                &amp;lt;h2&amp;gt;The AI Says:&amp;lt;/h2&amp;gt;
                &amp;lt;pre class="bg-light p-3"&amp;gt;{{ response }}&amp;lt;/pre&amp;gt;
            &amp;lt;/div&amp;gt;
        {% endif %}
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Your file structure should look like this.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; project_folder/
 ├── app.py
 ├── templates/
 │   └── home.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Grab your OpenAI API key &lt;a href="https://openai.com/" rel="noopener noreferrer"&gt;Link&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Set it as an environment variable
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add this line at the end with your own api key.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export OPENAI_API_KEY="yourAPIkey"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  This will let you use your new key.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Now let's test, you should see your api key.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo $OPENAI_API_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Startup the app
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flask run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Assuming no errors, you should see this!
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvhidrdv7lqro8idqlwp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvhidrdv7lqro8idqlwp.png" alt="homegpt" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>flask</category>
      <category>openai</category>
      <category>ai</category>
    </item>
    <item>
      <title>What day is it?</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Wed, 28 Feb 2024 14:37:29 +0000</pubDate>
      <link>https://dev.to/dcs-ink/what-day-is-it-455e</link>
      <guid>https://dev.to/dcs-ink/what-day-is-it-455e</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fee7tpw5nem5kgb4fu9pc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fee7tpw5nem5kgb4fu9pc.png" alt="Gemini Advance Response" width="663" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fygiihwelgpoa72f4pzlk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fygiihwelgpoa72f4pzlk.png" alt="Gemini Response" width="610" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffrejb3uxjzm4golhub80.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffrejb3uxjzm4golhub80.png" alt="ChatGPT 3.5 response" width="665" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>chatGPT, create a diagram of a light switch</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Thu, 01 Feb 2024 15:40:35 +0000</pubDate>
      <link>https://dev.to/dcs-ink/chatgpt-create-a-diagram-of-a-light-switch-446d</link>
      <guid>https://dev.to/dcs-ink/chatgpt-create-a-diagram-of-a-light-switch-446d</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fedj4aamecxgj0d71rc1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fedj4aamecxgj0d71rc1t.png" alt="incorrect light switch diagram" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>chatgpt</category>
      <category>openai</category>
    </item>
  </channel>
</rss>
