/r/AskProgramming

Photograph via snooOG

Ask questions about programming.

AskProgramming

All questions related to programming welcome. Wonder how things work? Have a bug you can't figure out? Just read about something on the news and need more insights? We got you covered! (probably)

Do

  1. Ask questions and start discussions
  2. Keep things civil and support each other
  3. Give your threads descriptive titles
  4. Include relevant information when asking for help
  5. Stay on topic in your posts and replies

Don't

  1. Post off-topic material
  2. Troll or flamebait, insult others, or act in bad faith
  3. Self-promote
  4. Ask others to do your work for you
  5. Ask for help in illegal or unethical activities
  6. Repost the same question within 24 hours
  7. Post AI-generated answers

You can find out more about our (preliminary) rules in this wiki article. If you have any suggestions please feel free to contact the mod team.

Have a nice time, and remember to always be excellent to each other :)

/r/AskProgramming

129,338 Subscribers

1

Small QT widget application errors please help

0 Comments
2024/05/12
03:29 UTC

0

With the rise of AI how do you still motivate yourself to learn how to code?

15 Comments
2024/05/12
00:56 UTC

1

Is this a good "error code system" proposal

Long story short: I often find myself with the problem that HTTP status codes aren't that flexible. So I made this new system and thought why not hear out other people's opinion about it.

Code layout: XYZ

X describes where the error happened

Y describes why the error happened

Z describes what caused the error

X and Y follow this pattern:

  • 0 - Client input error
  • 1 - Client runtime error
  • 2 - Client library error
  • 2 - Client network error
  • 3 - Gateway network error
  • 4 - Server runtime error
  • 5 - Server library error
  • 6 - Server network error
  • 7 - Third party error
  • 8 - Unknown source
  • 9 - <Open space>

Z follows this pattern:

  • 0 - Requires authentication
  • 1 - Insufficient permissions
  • 2 - Rate limit
  • 3 - Data incorrect or missing
  • 4 - Data malformed
  • 5 - Network
  • 6 - Internal error
  • 7 - Legal
  • 8 - Unknown
  • 9 - <Open space>

Open spaces are free to experiment with or I just missed a common error.

I am in no way an expert, and I anything is wrong with this, tell me in the comments.

5 Comments
2024/05/12
00:29 UTC

1

question about finding specific data

In the last few days I've been enthusiastic about creating programs, cheats or scripts. and now I'm somehow stuck in a browser game called kour.io because I think that a lot is possible there and I think that I can learn a lot there. Well, let's get to my actual problem. I managed to write a script which is a command automatically to verify the user (a blue tick) that works great, but I would like to create other functions but I just can't find anything else and that brings me to my question: how do I find the data I need for something like that in a browser game? I know that things like this are stored in the database and find base but I don't know how to find them.

Maybe someone here has a suggestion on how I can find the data I'm looking for. or any tips thank you... By the way, here is the script if it helps or someone wants to take a look. Its not good but for my first project its okay i guess

Script: https://greasyfork.org/de/scripts/494667-verify-kour-io-made-by-snomy

0 Comments
2024/05/11
23:49 UTC

1

Advice needed for building a basic B2B SaaS as a relatively novice dev.

Hey all, I built an incredibly horrendous MVP of my SaaS app last year and would like to re-build in a much more professional way. Id like to do as much of this as possible myself. I built the MVP in ReactJS and Node/Express, and all hosted on AWS (Amplify, Beanstalk, Lambda, Cognito, SES & DynamoDB)

The App: a self serve website that hiring teams can purchase single or bulk hiring assessments from. To begin this will be pretty basic, including a:

  1. Landing page w/ details and pricing cards
  2. Login/sign up
  3. Dashboard displaying assessment stats for users (completed or not) along with the ability to click a user to view their assessment results/report, as well as a few buttons for purchasing more assessments
  4. A multiple choice test page - each interview candidate gets a unique, one time link emailed to them that takes them to the assessment to complete in a webpage. Once completed they submit and a lambda auto-grades the assessment, notifies the manager and populates it in the dashboard.
  5. Blog page
  6. Billing page (Stripe integration)

My Question: since Im far from being a pro developer I'd like advice on how best to build this SaaS app. I want it to look modern/slick.

So far I think my choices are:

  1. Buy a frontend template from Themeforest and DIY the backend on AWS as I did before - the challenge here is these templates contain so much code that I don't really know where/ how to start in making it "my own"

  2. Use AWS Amplify Studio + Figma intergation for a lower code approach, and DIY the backend as before. The challenge here is I will have much less flexibility in how 'slick' and dynamic the web app experience is.

  3. Use a tool like bubble.io or Flutterflow for low/no code - the challenge is I'm not quite sure how to stitch in the backend to these tools, and fear that I would be limiting my flexibility in expanding/evolving the app in the future.

  4. Hire someone - I don't really have the funds for this at the moment. If I can get 50% of the app built then maybe I could hire help to complete it, but I'd really like to keep this as a last resort.

Any advice here would be greatly appreciated!

P.S. - I have a STRONG desire to keep as much of this on AWS as possible as I'm most familiar with lambda, DynamoDB, API gateway, Cognito etc.

0 Comments
2024/05/11
23:00 UTC

2

What is your opinion on differences in Python format strings between languages?

There are various implementation of python-ish like formatting strings. They have couple of small differences which really grind my gears. In the following table I show differences in specyfing dynamic field precision between different implementations:

whatdocumentationdynamic field precision examplenotes
pythonhttps://docs.python.org/3/library/string.html#formatspec"{:.{}}".format("ABCDEF", 5)precision specified with {} after the argument
C++ {fmt}https://fmt.dev/latest/syntax.htmlfmt::format("{:.{}}", "ABCDEF", 1)specified after the argument
Rusthttps://doc.rust-lang.org/std/fmt/index.htmlprintln!("{:.*}", 5, "ABCDEF");specified before the argument and with .* not {}
C good old printfprintf("%.*s", 5, "ABCDEF")specified before the argument

For me it is very highly confusing why the dynamic precision and width of a field in Python is specified after the argument to print? This is very highly confusing to me. I find specyfing it before the argument much more understandable.

Rust fmt, which was created later than C++ {fmt}, not only specifies the dynamic precision before the argument, but also uses .* for it.

Questions:

  • Why did Python want dynamic precision to be specified after the width? Isn't it confusing? Is there a technical reason? Is it better to specify width after the argument?
  • Why did Rust deviated from how Python did it?
  • Why Rust fmt has no dynamic width?
  • What do you prefer? Specifying dynamic field width and precision before or after the argument?

Thanks.

1 Comment
2024/05/11
22:13 UTC

0

Guidelines for beginners?

Hey ppl, don’t know if this is the right sub-reddit to ask this in but oh well. I’m a first-year Software Engineering student and let me tell you I am struggling. Given that I had never looked at a code sheet before, I managed to pass everything, but I feel like I know next to nothing… So I guess my question is: What do you recommend for beginners in this field? What should I prioritise, important languages, important concepts etc.. Thx

1 Comment
2024/05/11
21:32 UTC

1

I was trying to solve AOC 2018 day5 part 1 , come up with my logic thats working for smaller strings but not for the larger ones.

while (stack.length >= 2 && (stack[stack.length - 1].toLowerCase() == stack[stack.length - 2] || stack[stack.length - 1] == stack[stack.length - 2].toLowerCase())) {
 stack.pop();
 stack.pop();}

The above snippet is working fine for smaller strings but not for bigger ones, gpt gave me the 2nd snippet that worked correctly in both cases, i dont get why 1st one didnt worked

while (stack.length >= 2 && (stack[stack.length - 1].toLowerCase() == stack[stack.length - 2].toLowerCase()) && stack[stack.length - 1] !== stack[stack.length - 2]) {
stack.pop();
stack.pop();

}

1 Comment
2024/05/11
21:11 UTC

1

How to calculate precision and recall in Rstudio, total beginner in coding

I have done this until part 10, i cannot for the life of calculate precision and recall curves and plot them please help 

1)      Randomize the data using the data analysis tool pack in Excel.

a.       To do this, use the random number generation tool and generate one uniform random variable with 768 observations (because you have 768 rows of data) with seed = 123.

b.       Now sort your data in ascending order against the random variable you just generated

2)      Load the data into R. You can use the read.csv command for this purpose

3)      Convert the variable Outcome into a factor variable

4)      Remove the random variable column from your data (because we only needed it to randomize the data and we do not need that column anymore)

5)      Split your data into training and testing. Use the top 500 rows as training and the bottom 268 rows as testing

6)      Create a decision tree model on your training data to predict the "Outcome" variable using the rpart function.

7)      In your console, print the decision tree model just made and explain how to read the output and what each value means. You don't have to explain every node. Just a few terminal nodes to show you understand how to interpret the output.

8)      There are some parameters that control how the decision tree model works. These can be accessed in the help file of rpart. Type "?rpart" to bring up the help file and scroll down to controls. You will see a hyperlink titled "rpart.control". Click on the hyperlink and read the help file.

9)      Create a decision tree model where every terminal node has at least 25 observations. Do you notice any difference between this model and the model created in part (6) above? Explain

10)   Plot the decision tree model from (9) above using rpart.plot

11)   Predict the probability of having diabetes for each observation in both training and test data. Create the ROC plot and precision recall curves and report the area under the curve for all curves.

I have done this until part 10, i cannot for the life of calculate precision and recall curves and plot them please help

heres my R code up till this point
setwd("E:/Downloads")

diabetes <- read.csv("assignment 3 diabetes.csv")

print(diabetes)

library(dplyr)

diabetes <- diabetes %>%

mutate(Outcome = as.factor(Outcome))

diabetes <- diabetes %>%

select(-"Random")

training_data <- diabetes[1:500, ]

testing_data <- diabetes[501:768, ]

install.packages("rpart")

library(rpart)

decision_tree_training <- rpart(Outcome ~ ., data = training_data)

?rpart

decision_tree_training_25_observations <- rpart(Outcome ~ ., data = training_data, minsplit = 25)

install.packages("rpart.plot")

library(rpart.plot)

rpart.plot(decision_tree_training_25_observations, extra = 2)

training_data$prob_diabetes <- predict(decision_tree_training_25_observations, newdata = training_data, type = "prob")[, 2]

testing_data$prob_diabetes <- predict(decision_tree_training_25_observations, newdata = testing_data, type = "prob")[, 2]

install.packages("pROC")

library(pROC)

roc_train <- roc(training_data$Outcome, training_data$prob_diabetes)

roc_test <- roc(testing_data$Outcome, testing_data$prob_diabetes)

plot(roc_train, main = "ROC Curve - Training and Testing Data", col = "purple")

plot(roc_test, add = TRUE, col = "red")

legend("bottomright", legend = c("Training Data", "Test Data"), col = c("purple", "red"), lty = 1)

install.packages("PRROC")

library(PRROC)

colnames(training_data)[colnames(training_data) == "prob_diabetes"] <- "training_prob_diabetes"

colnames(testing_data)[colnames(testing_data) == "prob_diabetes"] <- "testing_prob_diabetes"

train_prob <- training_data$training_prob_diabetes

test_prob <- testing_data$testing_prob_diabetes

install.packages("pracma")

library(pracma)

pr_train <- pr.curve(training_data$Outcome, train_prob)

pr_test <- pr.curve(testing_data$Outcome, test_prob)

library(pROC)

pr_train <- pr.curve(training_data$Outcome, training_data$training_prob_diabetes)

pr_test <- pr.curve(testing_data$Outcome, testing_data$testing_prob_diabetes)

0 Comments
2024/05/11
19:58 UTC

8

What is a Memory leak?

I was just told by a YouTube video that memory leaks don’t exist. I’ve always thought memory leaks were something that happened when you allocate memory but don’t deallocate it when you’re supposed to, and major memory leaks are when like you start a process then it accidentally runs ad infinitum, increasing amount of memory used until computer crashes. Is that wrong?

Edit:Thanks everyone for the answers. Is there a way to mark the post as solved?

36 Comments
2024/05/11
17:51 UTC

1

Want to create a portal / Website builder like Shopify

Hey,
I wanna create a portal / website builder like shopify of my own
So can anyone help me out what languages should I learn of coding
And some basic process of how can I
It will be very appreciatable for your opinions.

0 Comments
2024/05/11
15:42 UTC

1

Output Display MASM VS Studio 2022. Irvine library.

Trying to study the sample example programs in the book. I successfully displayed output but am unable to recreate it. Doing the AddTwo.asm. Am I doing something wrong in VS studio?

http://asmirvine.com/gettingStartedVS2022/index.htm#syntax

"When you assembled and linked the sample project, a file named Project.exe was created inside the project's \Debug folder. This file executes when you run the project. You can execute any exe file by double-clicking its name inside Windows Explorer, but it will often just flash on the screen and disappear."

Thanks.

0 Comments
2024/05/11
13:37 UTC

24

Do you think that programming makes you a problem solver in life?

It has been many years before since I started delving into programming extensively when I suddenly realized that my perception of daily things started to change as well. All of a sudden, I noticed that the way that I interpret usual circumstances was to accept them as problems that require a solution. And this starts from silly matters such as "Should I have a cup of coffee or a cup of tea", up to big ones such as "Find a job that matters to you".

To cope with that, I started to simplify things. I accepted the fact that not all problems are solvable, require an immediate solution, or even lie on the scope of my actions. So, I started focusing on what comes through my action range. However, what I believe is that by identifying daily situations as problems, you bias your way of thinking in a negative aspect. All I am saying is that I would prefer to instinctively identify opportunities rather than problems to solve.

Not to mention, even this post appears like a problem to me!

Do all of this make sense?

I truly wanted to know what others think about it.

27 Comments
2024/05/11
10:09 UTC

15

How do I know if I have enough Python knowledge to start a freelance business?

For some time now, I've been keen on eventually using my coding skills to start freelancing and get an income. But the bottleneck to my idea is the fact that I feel I'm still inadequate in my Python skills. So I'd really like to know if there is a specific way of knowing if you're ready to start freelancing and if so what all must I learn in Python to get there.

9 Comments
2024/05/11
06:20 UTC

1

First time developing mobile application and I need help in what tools that i should use?

Hello, I am a CS student and it is my first time developing a mobile application. I wanted to build a music player application similar to iTunes with React Native. I want the application to be an offline application but can Sync like iTunes if paired via bluetooth or wifi.

I have learned HTML, CSS, Java, C# and python before but I have no experience in JavaScript. I am currently watching some Javascript tutorials and from W3 school as well. As for the database, I only have experience with SQL server management studio and phpmyAdmin.

My question is that what react library am I going to need for the development and what database should I use? I would appreciate if you guys can share tips and videos on how to build them.

PS. It is for my school assignment and I need to build it within 2 and half month. Would appreciate if there are already free music projects that I can modify quickly due to the limited time frame**.**

1 Comment
2024/05/11
04:02 UTC

1

HTML/CSS/JS. Hello, I am looking for advice on how to get started with a web page that can build an image with colored dots on certain parts of the image.

A little bit more detail. So the premise of the app/tool is I have ~10 different layouts with numbered spaces lets call the layouts A-J, each layout has 10 spaces. So spot 5 on layout B would be B5. I have a button system where the user can select the layout and then pick any spot within that layout. Once they pick the desired spots they have the option to pick a colored circle to place on that spot. for example they pick. C1, C4, C5, C7. then for spots C1, and C4 they want a green circle, and C5, and C7 get a blue circle. After they make all there selections I want them to be able to save the final image. I was wondering if anyone knows if there might be another language more suited to building this tool or if its seems reasonable to do with HTML/JS/CSS. This is a side project to help me with a repetitive task at work I am not a programmer by trade but enjoy programming on the side here and there. Thanks for any help!

2 Comments
2024/05/11
03:23 UTC

0

How to create aol messenger in Python ?

5 Comments
2024/05/11
02:07 UTC

4

OK, so... I'm with a team and we are debating about which backend to use

Basically we want to make a social network and we are expecting a lot of data. After what I've read and programmed elixir came to mind instantly, one of us has experience with ruby on rails and atm that's what we are working with (we don't have much tho), after seeing what next.js and clojure are capable of I still have my doubts. As you can see I'm debating on whether to use a not-so-used yet loved technology vs a well established technology.

Phoenix attracts me powerfully bc of its performance, functional style, concurrency/parallelism...etc Ruby on the other hand has been in the game for longer and unlike other frameworks it seems quite clean and understandable, however Idk how good it's going to scale.

We are also planning on using it on AWS with a react native frontend.

I'd like to know what do you guys think

73 Comments
2024/05/11
01:03 UTC

1

Need guidance over how I should go about building this.

Hey everyone. So I am a second year comp sci student and I need to build an extension and app. Browser extension for now that detects women on the screen and blurs them, kinda like a porn blocker where you just blur the parts that are indecent. But in this case the entirety of the woman is blurred using AI ML ofc. If it is easier to get started with an app that runs in the background while performing this function ( Which I do doubt) then lmk.

I know the theoretical ins and outs of basic AIML but don't really have much practical experience. Can someone give me a roadmap on what I'll need to learn and how I'd go about doing this? Thank you for all your suggestions.

2 Comments
2024/05/11
00:42 UTC

11

JS or TS?

I wanna make a discord bot with discordjs along with its own webpage (I already know html and css) I know parts of JavaScript but I’m not great at it I’ve heard typescript is better and some people say JavaScript is better what would you guys recommend?

36 Comments
2024/05/10
23:46 UTC

0

HTML, CSS, Js. Now what?

My goal is to be an wordpress expert including theme and plugin development.

I have completed courses on wordpress basics, woocommerce, elementor; built some no coding projects. Learnt HTML, CSS. And now I am learning JavaScript.

I mean it has been a long journey and my pc folders are full of files and exercises. So I think I am confident. But after that, what should I do? Learn more about skills like frameworks or about getting some work?

My case: I am too much broke and need to get into earning super fast, doesn’t matter how less I would get.

11 Comments
2024/05/10
21:34 UTC

1

Why should i implement cloneable when i am doing stacks and queues

for example

public class Queue implements Cloneable{

why do i implement it?

3 Comments
2024/05/10
18:03 UTC

5

What is the difference between Classes and Structures?

14 Comments
2024/05/10
16:16 UTC

0

Which language should I use if I’m coming from using a visual editor like in Godot? (Node based DAW project)

I’ve been making games since September but now I want to try my hand at software development. The problem I’m running into is that in using Godot, I’ve become used to having a visual editor for making UI changes instead of having to rely on code. The first language suggested to me for the project I want to make was JS, but I’m having a hard time with HTML and CSS (I know they’re supposed to be simple but they’re messing with my head). I’ve also been suggested Python because GDScript (the language I use in Godot) is supposedly a mix of TypeScript and Python. I haven’t been able to find a visual editor for Python but maybe I’m not using the right keywords? Finally I’ve also been suggested Ruby, specifically on Rails because the nature of the project is a web app. Any help would be greatly appreciated. I’m open to learning any language that can be used to make a web app that has a visual editor for UI. If there is not such a thing or you would suggest against using one, which language do you think would be best for a music based project? Thank you for your time!

11 Comments
2024/05/10
13:37 UTC

1

Is it possible to write a program to automate this process?

Ok, so I’m currently studying Japanese using Anki, (a spaced repetition note card software) and I have a specific format for my note cards that I’ve found to work very well for me.

When I find a word I want to turn into a card, I set the front of the card as the word, and on the back, it will have the definition (from my digital dictionary) and 2 example sentences from an online site called Jisho (Jisho.org) as well as the break down of the characters that make up the word which I would copy and paste from another card deck I use in Anki. Would this creation process be something I could automate somehow? Maybe writing code telling the machine to retrieve the information from these specific places and put it all together in the form of the card? Or at least pull the information from their sources and put it in a memo software from which I can just copy and paste? I’m very new to programming and my language of choice has been C# up to now 😊

9 Comments
2024/05/10
10:41 UTC

2

Differences between code in Inspect Element and View Source

I am looking at a website, particularly a <p> in inspect element. This <p> isn't available in View Source. The particular <p> also isn't present in the GitHub repo that the website owner made public.

So maybe the GitHub repo is different from the live version of the website? Maybe the GitHub repo code is older, and the live version has newer code?

Or maybe that particular paragraph is loaded from somewhere else, so that it is not directly present in View Source or GitHub, but due to the loading, it is present in the Inspect Element?

Is what I describe a common situation in web dev? I am an absolute beginner, so sorry for the stupid question. The specific use case I am trying to solve is, I was hoping by having the GitHub repo locally on my machine, I would be able to run the project locally and then play around with the UI/UX. I have been able to run the project locally, but having an issue with the Supabase PostgreSQL db. The project locally does not look like the live version. So I am not sure if the difference is due to my workaround for Supabase, or something else. Thanks.

1 Comment
2024/05/10
10:40 UTC

2

What is the easiest digital tool to program circular shaped planner with toggle-able grouping functions?

Hi

First time posting here, I hope I'm in the right subreddit for this question. This is more of a looking for suggestions post rather than a single specific solution. If there is a better subreddit for this post, please tell me which it is. :)


I work IT in an office for a rather large organization (400+ workers if not more) and a department head came by with a neat idea for his organizational presentations. In essence he often holds major meetings involving multiple departments that work on a lot of separate projects that sometimes overlap with each other's departments.

He had trouble communicating all the info with regular table info-graphics, and also expressed annoyance to the fact that it had to be a static graph. He had the idea of portraying the info in the shape of a year-wheel (for the fiscal year). Traditionally in most presentation tools those end up having a lot of spokes prodding out from them with the additional info per section. But he didn't like that design because of death by Power Point with too much information.

What he actually wants is a year wheel where you can portray the names of the ongoing projects of each month, which would then be color coded and sort-able by department.

This example image shows the Power Point smart art he has been using as a baseline. Although with more added info other than just the name of the months.

Now this sounds easy at first given that it's just about the visual design of the data presented. What makes his idea different is that he wants the different departments to be toggle-able dynamically within the same graphic.

So with a push of a button he could show only Department A and B's projects, then maybe he adds C and D. He also wants some indicator (maybe color coded) of which multiple departments are involved in what.

To do this with regular graphics and smart art would mean to make every single variant of the wheel and simply move to that slide. Obviously the data would have to be entered in advance, but the toggle function would give some dynamic presentation options for what to show.

I'm far from an expert on power point or Excel, but my mind immediately jumped to programming something in Excel or maybe using Excel for the data entry then exporting and displaying it in Power Point. But then we get to the issue of how to toggle the displayed graphic details.

So my question is: Are there presentation tools out there that have this sort of higher functionality or would one have to program something themself from scratch?

I've looked around at tools online, but without downloading all of them I can't tell whether or not they support this idea.

The department head is well aware that what he's asking for might not be worth the time or effort of either him or us in the IT department. But I thought I'd gather some info and at least get back to him with what I can. Either to give him a path forward to crush is Power Point perfectionism dreams.


TL;DR - Boss wants to reinvent the wheel but not entirely a stupid idea.

0 Comments
2024/05/10
08:22 UTC

4

Security of api Keys

Hello Hello everyone,

I'm using SonarQube at work to check for vulnerabilities in the app, and it seems that it doesn't like the use of a random function from C#.
After further research, this random function from C# is used to generate api keys ( which to my ear it sounds awfull, but I'm just a junior, so I don't want to judge my senior colleagues judgements ). From what I know this is strongly not recommended, since random function have predicted behaviour, and they can be used for attacks.
The question is, is this really not secure, should I change the way we generate API keys, and if so, what would you recommend?
Is there a library with such safe random generator, or should I use just Guid from C#?

Thank you, you are my favourite comunity.

10 Comments
2024/05/10
07:00 UTC

1

Help what should I do next learning Android development

I'm on my Android development journey, and I have completed Kotlin Fundamentals from Philipp Lackner (Noobie to Pro playlist).  I'm confused about what I do next. Some options that I have are:

Android Fundamentals by Philipp Lackner:https://youtube.com/playlist?list=PLQkwcJG4YTCTq1raTb5iMuxnEB06J1VHX

Jetpack course playlist by Phillipp Lackner:https://youtube.com/playlist?list=PLQkwcJG4YTCSpJ2NLhDTHhi6XBNfk9WiC

If I'm doing something wrong, you can tell me a more efficient and better way on what to learn and from where to learn (a preferred free course or playlist). Feel free to give me suggestions. I'm just a beginner and would appreciate it if a more experienced person could share his or her learning path for Android development.

PS: I have 1.5 months to reach a skill level where I can make small projects (apps) like to-do apps and basic clones.

0 Comments
2024/05/10
06:40 UTC

0

Compression library for C++ in 2024?

I am looking for a replacement for a VERY old static library of zlib (it's from 2002...), but when I Google around, I only find people recommending actually using zlib. Is zlib still the go to library for compression in 2024?

5 Comments
2024/05/10
06:37 UTC

Back To Top