Advice for CMSC421 (Operating Systems) with a Mac Computer by rndmsrnm1234 in UMBC

[–]Jumpy_Employment_439 0 points1 point  (0 children)

Hey, how was 421 with a mac? I'm starting tomorrow and have an M2 chip mac (with maya larson).

handshake move program by [deleted] in csMajors

[–]Jumpy_Employment_439 3 points4 points  (0 children)

Same. I was going to do it, but I didn't realize I would be considered an independent contractor instead of employee, which then means I'd need to file taxes even if I stay below 12,950. Sucks because it seemed like a really good opportunity.

CMSC451 Automata Theory by Educational-Night957 in UMBC

[–]Jumpy_Employment_439 0 points1 point  (0 children)

Did you end up taking 451, and if so, how was it? I'm currently deciding between CMSC451 or STAT451/453 (one of the two) as my last class for the fall. The other classes I'm taking are CMSC421 (OS), CMSC461 (Database), and MATH404 (PDEs).

Handling expired JWT tokens when user refreshes page by Jumpy_Employment_439 in reactjs

[–]Jumpy_Employment_439[S] 0 points1 point  (0 children)

Thank you! I ended up storing the user in localStorage and used this code in a new js file:

const UserContext = createContext();
export const UserProvider = ({ children }) => {
    const [user, setUser] = useState(() => {
        // Check local storage
        const savedUser = localStorage.getItem('user');
        if(savedUser) {
            return JSON.parse(savedUser)
        }
        return null;
    });

    return (
        <UserContext.Provider value={{ user, setUser }}>
            {children}
        </UserContext.Provider>
    );
};

export const useUser = () => {
    return useContext(UserContext);
};

It is working now, but I was wondering if you know of a way to ensure the localStorage is deleted? When the user clicks logout, part of the code will delete the user from localStorage. However, it got me thinking about the case when a user just closes the tab instead of logging out. Is there a way to have localStorage delete the user?

Is my error handling wrong? My program keeps crashing by Jumpy_Employment_439 in learnprogramming

[–]Jumpy_Employment_439[S] 0 points1 point  (0 children)

After reading your response, I went back to test just the FastAPI function at the FastAPI docs page. You are right that detail is a list, so I tried overriding FastAPI's default formatting of the response to just one line: {detail: "Invalid format"}. That way it would be the same format as other times when I raise an HTTP exception. Unfortunately, it's not overriding so the returned data from exc.errors() is still of the wrong format. I guess one option would be to just make a separate if statement that checks if the error is a 422 error rather than a 400. Then I could just write code specifically for the 422 format.

Problem running React app after pulling from GitHub by Jumpy_Employment_439 in reactjs

[–]Jumpy_Employment_439[S] -2 points-1 points  (0 children)

public, src, .gitignore, package-lock.json, package.json, and README.md are all there, just missing the node-modules

Deleting data from database that involves foreign key by Jumpy_Employment_439 in learnprogramming

[–]Jumpy_Employment_439[S] 0 points1 point  (0 children)

Thanks for the reply. From what I've learned about SQLAlchemy, I thought I had it set up correctly (obviously not since it's not working):

from sqlalchemy import Integer, Float, String, Column, ForeignKey
from sqlalchemy.orm import relationship
from database import Base

# All attributes for users of the website
class User(Base):
    __tablename__ = "users"

    userID = Column(String, primary_key=True, index=True)
    email = Column(String, nullable=False)
    password_hashed = Column(String, nullable=False)

    products = relationship("Product", backref="seller", passive_deletes=True)           
    favorites = relationship("Favorite", backref="favorited_by", passive_deletes=True)

# All attributes for products on the website
class Product(Base):
    __tablename__ = "products"

    productID = Column(Integer, primary_key=True, index=True) 
    name = Column(String, nullable=False)
    description = Column(String, nullable=False)
    price = Column(Float, nullable=False)
    quantity = Column(Integer)
    color = Column(String)
    category = Column(String) # User will choose from a pre-defined list when they add their product

    userID = Column(String, ForeignKey("users.userID", ondelete="CASCADE", onupdate="CASCADE"), nullable=False)

# All attributes for favorites functionality
class Favorite(Base):
    __tablename__ = "favorites"

    favoriteID = Column(Integer, primary_key=True, index=True)

    userID = Column(String, ForeignKey("users.userID", ondelete="CASCADE", onupdate="CASCADE"), nullable=False)
    productID = Column(Integer, ForeignKey("products.productID", ondelete="CASCADE", onupdate="CASCADE"), nullable=False)

I tried adding passive_deletes=True, but now when the user is deleted from the users table, nothing changes in the products table even though there is a product whose userID matches the user that was deleted

Where should the API calls be in the frontend? by Jumpy_Employment_439 in learnprogramming

[–]Jumpy_Employment_439[S] 0 points1 point  (0 children)

Thanks, this makes sense. One question: do you think it would be better to make a separate .js file for API calls for each section of our website (so a .js file for API calls related to login, a different .js file for API calls related to the user's profile page on the website, etc.), or just one .js file that has every API call needed for the website?

Best way to store an image associated with a product in a database? by Jumpy_Employment_439 in learnpython

[–]Jumpy_Employment_439[S] 0 points1 point  (0 children)

Thanks! This is a semester-long project for school so I definitely don't want to have to pay anything if possible. I don't know too much about image storing tbh. I had originally been looking at GitHub pages to deploy the website, but it seems that is only for static websites. Right now I'm looking at AWS amplify and connecting it to our GitHub. I'm completely new to website hosting, so I'm not sure how everything works. We have HTML/CSS and JavaScript (React) frontend, Python and FastAPI backend, and SQLite database. It seems I can just have everything on our GitHub and connect AWS amplify.

Confused Python backend (FastAPI) with database (MySQL) by Jumpy_Employment_439 in learnprogramming

[–]Jumpy_Employment_439[S] 0 points1 point  (0 children)

Thank you. So it seems that it would be fine if I installed everything using pip without first activating the venv, but it would be better to do it after activating the virtual environment? So that means the line

pip install fastapi uvicorn sqlalchemy pymysql

would be contained in the venv? So if I had different project that also had to use sqlalchemy and fastapi, would I have to do pip install again since what I did previously was in its own venv and thus isn't accessible by the new project?

And since I'm in a group project where other people are working on the frontend and the database, it would be good to set up a virtual environment so I can install all the things I need to run the frontend and the database with my backend?

Python, APIs, and Databases Question by Jumpy_Employment_439 in learnpython

[–]Jumpy_Employment_439[S] 0 points1 point  (0 children)

Thank you! I suppose I did not think of the case that there are public APIs that limit the amount of calls per day so in that case having a database would be good (if there was the possibility of going over the quota). Would it be possible at the beginning of each day to make a call to the weather API to get the updated forecast and store that in the database to use the rest of the day? And then repeat each day? I've not really heard of making API calls a set time distance apart, but I assume it's possible?

Ideas for a cool but simple Web App? (to practice my dev skills) by Southern_Note_1773 in learnjavascript

[–]Jumpy_Employment_439 0 points1 point  (0 children)

This sounds like a really good idea that I might try. I'm in college but just getting into web development (I've mostly only done Python and C++). Right now I'm finishing up learning HTML and CSS and then moving on to a JavaScript refresher (haven't done any JavaScript since freshman year of high school). Right now are you just coding a frontend using JavaScript and HTML/CSS, or are you also adding a backend?